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.

How to know the last byte is received from UART Receive Buffer

Other Parts Discussed in Thread: TM4C123GH6PM

Hello Community Members

I am currently working on UART communication with RS-485 physical interface. There are 8 different boards as slave in line. We are using Tiva TM4C123GH6PM MCU.

When I communicate independently with boards, there is no problem at all. But when these boards are on same line , I can't handle buffer. I mean for example, Master request is in certain length, and if SLAVE_ID and FUNCTION_CODE is true for me, I response to master. But when other slaves responses to master, these responses come to my RX_Buffer too and  I can't know when I should make rx_index to 0.

Since I can't know when I should make my rx_index to 0, everything goes wrong when one of other slaves response to Master.

As summary when there is only one slave

RX_Buffer[rx_index++] = PLC_Request;

Since PLC_Request is in defined length, I can know that when RX_index is 8 or whatever, Make it 0.

if there is more than slave in line

RX_Buffer[rx_index++] = PLC_Request + Slave_Reponse;

In this case Since I can't know length of slave_response, I can not make RX_index to 0 in correct index.

What should I do in this case ?


Thanks in advance

Serkan

  • Hi,

    Serkan said:
    Since I can't know length of slave_response, I can not

    Then you may introduce a byte at the beginning of the packet to hold the number of data bytes which will follows(so you can count them), or, if your data is an ASCII message, choose a terminator character to know when it is received.

    Serkan said:
    if there is more than slave in line

    If so, how do you avoid collision if at least two slaves come to speak? some order is needed also here - maybe a slave should not talk if not previously requested by the master.

  • Hello Petrei

    Do you think a I2C type access should be called, where the master addresses a slave?

    Regards
    Amit
  • You might want to consider implementing an existing protocol rather than inventing your own.

    Robert