UART TXDATA last byte missing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART TXDATA last byte missing

854 Views
athmesh_n
Contributor IV

Data from UART is missing last byte using the following code snippet.  

 rs485_tx_mode();                                                    //Setting as Transmission
 for(mb=0;mb<u8ModbusADUSize;mb++)               //u8ModbusADUSize = 8
 {
  while(~LPC_USART0->STAT & (1<<3)); 
  LPC_USART0->TXDATA = u8ModbusADU[mb];
 }
 while(~LPC_USART0->STAT & (1<<3)); 
 rs485_rx_mode();                                                 //Setting as Reception

u8ModbusADUsize is 8, and the u8ModbusADU[7] is missing during continuous run. But while debugging step-by-step we are getting the full output including u8ModbusADU[7]. 

Processor : LPC1517

IDE            : MCUXpresso 

Clock          :   Internal Clock

Thanks and Regards,

Athmesh Nandakumar

Labels (1)
0 Kudos
3 Replies

693 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi ATHMESH NANDAKUMAR,

     Please modify your code like this:

 rs485_tx_mode();                                                    //Setting as Transmission

 for(mb=0;mb<u8ModbusADUSize;mb++)               //u8ModbusADUSize = 8
 {
  while(~(LPC_USART0->STAT & (1<<2))); 
  LPC_USART0->TXDATA = u8ModbusADU[mb];
 }

 while(~(LPC_USART0->STAT & (1<<3))); 
 rs485_rx_mode();                                                 //Setting as Reception

If you still have problems, just add a small delay above  rs485_rx_mode();

Please try it again.

Any updated information, just let me know.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

693 Views
darius_b
Contributor I

Hi Athmesh,

Possible you lost last byte when switch into rx mode.

Try insert delay 1ms.before rs485_rx_mode function.

BR. 

Darius Babrauskas

693 Views
athmesh_n
Contributor IV

Thanks

0 Kudos