Hi Shiren,
In fact, the SCI is very simple module without any FIFO or DLC.
It simply calls an interrupt when a byte is received.
The composing of complete received LIN message is fully managed by software – in your case by simple state machine with IDLE..CHECKSUM states.
The slave must know how many bytes refers to the received rx[lin_num].protected_id.
So, the rx[lin_num].protected_id value will tell you type of LIN message (whether Master send or request data, how many bytes Slave should receive/send).
Note: The most confusing point of this software is the state machine shift. The break character is received in the case IDLE, synchronization is tested in case _BREAK, protected_ID is received in case SYNCH…
The state is incremented directly after any of the cases execution, therefore it will fit from external point of view (when we receive protected_ID and LINGetChar() is executed, the rx[lin_num].state will be PROTECTED_IDENTIFIER).
The TC flag will probably not help you. It is just flag which signalize when byte transmit finish.
The TC flag is like the TDRE flag with small difference. The TDRE is set again when output buffer is ready for new data. TC is set again when complete byte is sent. In reality, there is just half SCI bit shift (TDRE first, TC later).
I hope it helps you.
Have a great day,
Radek
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------