This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UART transmission using DMA?

Other Parts Discussed in Thread: MSP430F5151

Hi all,

I'm attending to write a program which communication with PC via UART connection on MSP430F5151

I ran some examples such as echo, Its work well.

In order to make data transmission more easily, I'm trying to use DMA.

So, I wrote some code.

After initialzing  for DMA with following info;

+ Channel 0

+ Trigger  source : UCA0TXIF

When send data request occurs, I will resize DMA size, then send directly first byte with UCA0TXBUF

After that enable DMA with DMAEN bit.

I also enable DMA interrupt for checking last bit is transferred.

My source code is here :

main.c 

char verStr[] = { "Hello World\r\n" };

volatile UINT dmaLength = 12;

volatile UINT hasData= 0;

..

Init_UART();

..

{

while(1)

{

    if (hasData == 1)

    {

      hasData = 0;

    changeDMASizeAndSend();

   }

 }

}

void changeDMASizeAndSend()
{

    DMA0SZ = --dmaLength;

   if (dmaLength <= 1) dmaLength = 12;
    UCA0TXBUF = verStr[0];
    DMA0CTL |= DMAEN;
}

// UCA0RX interrupt

#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR (void)

{

 switch(__even_in_range(UCA0IV,4))
      {
      case 0:break;                             // Vector 0 - no interrupt
      case 2:                                   // Vector 2 - RXIFG
          hasData  = 1;
        break;
      case 4:
          break;                             // Vector 4 - TXIFG
      default: break;
      }

}

// DMA interrupt

#pragma vector=DMA_VECTOR
__interrupt void DMA_ISR (void)
{
     DMA0CTL &= ~DMAEN;
}

But It's not work. My thinking is wrong? Pls help me.

  • Phung Tu said:
    But It's not work.

    "Nothing works" actually is very bad description of the problem.

    Please tell how you tested, what results you got, what you tried and how it changed results.

  • Phung Tu said:

    In order to make data transmission more easily, I'm trying to use DMA.

    You made a bad move, and putting DMA in story is far from more easily. Using DMA instead UART ISR on TX side can improve something (if you know how to write good code). Using DMA instead UART ISR on RX side can't improve anything. Check this topic http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/271228.aspx

    Anyway, you can ask yourself just 2 simple questions, and everything will be (maybe) more clear...

    1) Why there is no more UART RX source examples provided by TI?

    2) Why there is no more DMA source examples provided by TI?

  • Ilmars said:

    But It's not work.

    "Nothing works" actually is very bad description of the problem.

    Please tell how you tested, what results you got, what you tried and how it changed results.

    [/quote]

    Sorry for poor English.In fact, It's still runs, It's seem It's impossible to change DMA size after first.

    It assume that DMA size is assigned to 12 first via dmaLength value.

    Ok, MCU sends out 12 bytes for each RX interrupt.

    After that, It must send 11, 10, ... bytes for for each next RX interrupt.

    But in fact, It still send out 12 bytes.

  • zrno soli said:

    In order to make data transmission more easily, I'm trying to use DMA.

    You made a bad move, and putting DMA in story is far from more easily. Using DMA instead UART ISR on TX side can improve something (if you know how to write good code). Using DMA instead UART ISR on RX side can't improve anything. Check this topic http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/271228.aspx

    Anyway, you can ask yourself just 2 simple questions, and everything will be (maybe) more clear...

    1) Why there is no more UART RX source examples provided by TI?

    2) Why there is no more DMA source examples provided by TI?

    [/quote]

    Thanks for reply.

    I'm not intending to use DMA for receiving UART data.

    It mạkes use of DMA for sending UART data.

    And  I trying to write good code as possible.

    If possible, pls show me how to write a good code in my case.

  • Phung Tu said:
    If possible, pls show me how to write a good code in my case.

    Nobody can show or tell how to write good code. You shall learn it yourself - read books, practice. Or just attend (embedded) C programming course/class.

  • Thanks all for reply.

    I don't know why, but I work with 1 modifed :

    // DMA interrupt

    #pragma vector=DMA_VECTOR
    __interrupt void DMA_ISR (void)
    {

        DMA0CTL &= ~DMAIFG;
        DMA0CTL &= ~DMAEN;
    }

**Attention** This is a public forum