PDC Counter getting set to zero as soon as TXTEN bit is set.

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

DiBosco2
Posts: 11
Joined: Mon Sep 08, 2014 7:38 pm

PDC Counter getting set to zero as soon as TXTEN bit is set.

Wed Sep 23, 2015 6:55 am

Folks,

I have had SAM3S code running for ages to send two messages out of the serial port just fine using the PDC. However, if I use the identical code on SAM4S, it doesn't work properly.

This is the code I use to send out two messages from the UART/USART.

Code: Select all

// Start a double USART or UART DMA transmit transfer
void StartDualUSARTDMA(Pdc *usartPDC,unsigned char *DataStartAddress1,unsigned int BytesToTransfer1,unsigned char *DataStartAddress2,unsigned int BytesToTransfer2)
{

    usartPDC->PERIPH_TPR = DataStartAddress1;
    usartPDC->PERIPH_TCR = BytesToTransfer1;
    usartPDC->PERIPH_TNPR = DataStartAddress2;
    usartPDC->PERIPH_TNCR = BytesToTransfer2;
    usartPDC->PERIPH_PTCR = PERIPH_PTCR_TXTEN;

} 
I then call the above function from this kind of code:

Code: Select all

while (((UART1->UART_SR & UART_SR_ENDTX) == 0) || ((UART0->UART_SR & UART_SR_ENDTX) == 0));

    if (ParallelUARTs == TRUE)
        {
        StartDualUSARTDMA(PDC_UART1,HeaderPtr,2,DataPtr,ImageSize);
        StartDualUSARTDMA(PDC_UART0,HeaderPtr,2,DataPtr,ImageSize);
        }

Now, the problem I have is that as soon as the line:

Code: Select all

 usartPDC->PERIPH_PTCR = PERIPH_PTCR_TXTEN;
Is called, the value in usartPDC->PERIPH_TCR and usartPDC->PERIPH_TNCR is immediately set to zero and the flags to say the transfer is complete are immediately set.

It's really weird though, because although the debugger shows those counter values going to zero and transfer complete flags being set, the requisite values are sent out of the U(S)ART exactly right. The problem is that the only way I can get this to work is by simply putting a delay in the code before I send out the next lot of data, which is a bonkers way of proceeding!

If I don't put a delay in and just send according to this line:

Code: Select all

while (((UART1->UART_SR & UART_SR_ENDTX) == 0) || ((UART0->UART_SR & UART_SR_ENDTX) == 0));
The UART just starts banging out the next lot of code, before the previous lot is all sent out.

I would stress that this works perfectly on the M3, but on the M4 I have problems.

Can anyone suggest what night be going on please?

Thanks! :)

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest