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.

Raising the pin when 25bytes of data is transmetted through UART

Hi,

In my project I need to raise a pin when  25bytes of data is transmitted through UART,as the HAL_UART_DMA_RX_MAX is 128

I need to raise pin for 25bytes,50bytes,75bytes,100,125bytes.

Calling function:   (void)NPI_WriteTransport(buffr,25);

#if (HAL_UART_DMA == 1)
HAL_ISR_FUNCTION( halUart0TxIsr, UTX0_VECTOR )
#else
HAL_ISR_FUNCTION( halUart1TxIsr, UTX1_VECTOR )
#endif
{
  HAL_ENTER_ISR();

  if (dmaCfg.txHead == dmaCfg.txTail)
  {
    IEN2 &= ~UTXxIE;
    dmaCfg.txMT = 1;
  }
  else
  {
    UTXxIF = 0;
    UxDBUF = dmaCfg.txBuf[dmaCfg.txHead++];
      
    if(dmaCfg.txHead==0x19 || dmaCfg.txHead==0x32 || dmaCfg.txHead==0x4B || dmaCfg.txHead==0x64|| dmaCfg.txHead==0x7D )
    {
     P2DIR = 0xFF; // All port 1 pins (P2.0-P2.4) as output
     P2=0x03;
    }
      
    if ((HAL_UART_DMA_TX_MAX != 256) && (dmaCfg.txHead >= HAL_UART_DMA_TX_MAX))
    {
      dmaCfg.txHead = 0;
      
    }
  }

  HAL_EXIT_ISR();
}
#endif


in the ISR,I tried to raise the pin as showed in above code , by using

if(dmaCfg.txHead==0x19 || dmaCfg.txHead==0x32 || dmaCfg.txHead==0x4B || dmaCfg.txHead==0x64|| dmaCfg.txHead==0x7D )

but this dint work for me.

any kind of help is appreciable.

 

Regards

Lokesh

  • Hello Lokesh,

    Why not just transfer 25 bytes at a time by setting the DMA transfer count to 25?   If you enable the appropriate DMA interrupt by setting the appropriate bit, then you can send the next 25 bytes in the DMA interrupt by clearing the flag.

    See swrc257 UART DMA. Sample code to see how they use the DMA interrupt. 

    http://www.ti.com/lit/sw/swrc257/swrc257.zip

    Thanks,

  • Hi Lokesh,

    Do you set a breakpoint in "if(dmaCfg.txHead==0x19 || dmaCfg.txHead==0x32 || dmaCfg.txHead==0x4B || dmaCfg.txHead==0x64|| dmaCfg.txHead==0x7D )" statement to check if your code really enter it when transmit 25 bytes?

  • Hi Yikai Chen,

    Yes,I set a breakpoint and the code enters into the statment when dmaCfg.txHead==0x19,0x32,0x4B,0x64.

    but the problem is the pin is not raised(high) exact at 25bytes,it varies for 24bytes,31bytes and so.

    In the receiving microcontroller the bytes received is not exactly 25bytes and even in  Oscilloscope the raising edge is not uniform.

    Regards,

    Lokesh

  • Hi Lokesh,

    Try to replace the following codes in your "if(dmaCfg.txHead==0x19 || dmaCfg.txHead==0x32 || dmaCfg.txHead==0x4B || dmaCfg.txHead==0x64|| dmaCfg.txHead==0x7D )" statment.

    P2DIR = 0xFF; // All port 1 pins (P2.0-P2.4) as output
    P2SEL &=(~(BV(0)|(BV(1)|(BV(2)|(BV(3)|(BV(4));
    P2DIR |=((BV(0)|(BV(1)|(BV(2)|(BV(3)|(BV(4));
    P2_0=1;
    P2_1=1;
    P2_2=1;
    P2_3=1;
    P2_4=1;