How to reduce UART buffer size according to the received data ?

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

How to reduce UART buffer size according to the received data ?

1,934 Views
Amit_Kumar1
Senior Contributor II

Hi

I am Using K60, I am trying to communicate with a GPS using some AT commands. The input coming from the GPS is of 79 bits including CRC, LF,CR bits. So I declared the buffer size to char receive_buff[79]. So while receiving 79 bits its giving the complete value, but in case when GPS signal is not present the data being received from the GPS varies from 40 bits to 65 bits and is random.

So in this case the values is not displayed until the buffer is full by the next data.

My concern is I want to display the coming data no matter if the data is on full signal strength or low signal. so How do i operate with half filled buffer?

also, If I want to flush the data of the buffer , how do I do it?

Is there any way to insert '\0' to the remaining bits of the buffer which is larger than data received?  As per the datasheet, the bufffer should be filled according to  the size of UART buffer declared initially otherwise 2 data will be added and the result will be displayed skipping the accordingly. Please look into the matter

Thanks

Amit Kumar 

4 Replies

1,088 Views
Amit_Kumar1
Senior Contributor II

Hi Jorge

I meant that until the RX buffer is filled completely we cant extract data from that. and that gets filled when the next data comes from the GPS.  and Yes Jorge i mistakenly wrote bits it is supposed to be bytes. Ok I will try your solution . Thanks

Regards

Amit Kumar

0 Kudos

1,088 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Amit:

We are sorry for the time with your question unattended.

I think your GPS device will send the LF+CR even when the signal is low, right?

In this case I think the only solution would be polling the receive buffer to be aware of receiving that pair of bytes, or monitor the UARTx_S1[IDLE] flag, and then flush the input buffer. The Kinetis UART module allows you to flush the RX and TX buffers via the UARTx_CFIFO register, with TXFLUSH and RXFLUSH. Look at the next image:

Flush.png

Hope this is useful!


Regards,
Jorge Gonzalez

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

1,088 Views
Amit_Kumar1
Senior Contributor II

Hi Jorge

when the signal is low the value being received is

$GPRMC,,V,1303.7753,N,7735.09728,E,,,,,,M*6E<CR><LF>

when the signal is high the value is

$GPRMC,73859,A,1303.77271,N,7735.1103,E,0.1,200.4,170314,1.6,W,N*18<CR><LF>

So you can clearly see the values being received varies in size and in 1st case 2 data were being merged and displayed. I will try your solution and update you on the situation. I have one doubt also if I flush the rx data, then in 1st case since the data size le not 79 bits as declared so the rx buffer will again be inaccessible until it is completely filled upto 79 bits. So what should I do to extract the data from that buffer in this situation.?


Regards

Amit Kumar

0 Kudos

1,088 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hi Amit:

... in 1st case 2 data were being merged and displayed ...

Sorry, I do not understand this part, what do you mean by 2 data merged?

I have one doubt also if I flush the rx data, then in 1st case since the data size le not 79 bits as declared so the rx buffer will again be inaccessible until it is completely filled upto 79 bits. So what should I do to extract the data from that buffer in this situation.?

I think you mean *bytes* here, correct? In this case you should extract the data before flushing the rx buffer. You could do this for example in the *idle line* interrupt.


Regards!
Jorge Gonzalez

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

0 Kudos