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.

LP-MSPM0G3507: Serial implementation issue of storing data in circular manner.

Part Number: LP-MSPM0G3507
Other Parts Discussed in Thread: MSPM0G3507

Hi ,

I am working with mspm0g3507 controller and trying to implement serial input output over UART interface with available sample code. but I am not able to store new data from zero index of RX buffer. it always stores data in circular manner means if I set RX buffer size to 20 and send only 10 bytes from serial consol then I received 10 bytes but after that if I sent again 15bytes then it will store into RX buffer from index 10 onward (not from index Zero) and then fill buffer in circular manner.  Is there any other implementation where I can store new data from zero index every time.

  • I think I know what you're looking for, and I'm going to try to talk you out of it.

    A circular buffer where the next-free index (usually called "tail") of the queue is reset to 0 (based on some criterion) is an invitation to race conditions, since the producer (interrupt or DMA) is competing for a variable with the consumer (foreground code). A locking mechanism could probably be effective if the producer is an interrupt, but if the producer is DMA you don't have much control; in any case, it's extra cost.

    I would further argue that the benefit of resetting the tail index is very small.

    I suggest you stay with what you have, and just have the debugger display the head/tail indices along with the buffer.

  • Bruce:

    It sounds like he wants to get away from the ring buffer.

    OP:

    Just do it, set aside a buffer and increment it every time you get a character.

    Periodically in your main routine you can check to see if you have a series of characters and reset it.

  • Certainly it's up to the Original Poster to decide.

    But the same contention will happen with a linear buffer, unless the communication is strictly half-duplex -- i.e. the receiver always knows whether the line is "idle".

**Attention** This is a public forum