cancel
Showing results for 
Search instead for 
Did you mean: 

Buffer never filled due to incorrect message/noise, how to reset if buffer not filled in time?

CLH
Associate II

Given the following possibilities:

  • Buffer not filled due to message not being in correct format
  • Buffer not filled due to random characters sent on the TX line

How do I go about resetting/aborting the transfer if the message isn't fully filling the buffer.

I'd use half transfer but what if the noise is less than half of the buffer?

I will not get the interrupt if the buffer isn't half full or full.

My solution would be to start a timer on first byte received, and if buffer not filled within x time then abort and reset receive. If this would be your solution how do I get an interrupt on first byte of message received?

Any help on this issue is greatly appreciated.

4 REPLIES 4
Ozone
Lead

You don't say what Tx/Rx. Shall we assume UART/RS232 ?

Then, first fix your hardware issue. With a two digit percantage of character corruption, you have a hardware/line problem.

Second, DMA would be not appropriate then. You need to clear the respective UART status error bit to resume reception.

An interrupt-based approach would be better suited in this case.

CLH
Associate II

It isn't a hardware issue as much as it is guaranteeing the USART can recover without question if random

things happen on the line.

Are you of the opinion that it can't happen if the hardware is setup correctly, and will work 100% of the time? I have all the USART error handling in too.

(I don't know the answer to that question, just my colleague sees it as a potential issue)

> Are you of the opinion that it can't happen if the hardware is setup correctly, and will work 100% of the time?

No.

It seems your problem lies outside of the MCU. Perhaps crappy or inappropriate wiring, or EMI-infested environments.

A one-per-thousand chance of character corruption is already an annoyance.

> I have all the USART error handling in too.

That contradicts your headline "buffer never filled ...".

First, the STM32 USART peripheral requires a manual clearing of some error status bits to resume reception.

And second, you need to keep track of transmission corruptions in the package context. Assuming one character belongs to a packet or sentence, the whole packet is corrupted and thus lost.

Piranha
Chief II

USART is not a message based, but a stream based protocol. Treat it as a stream of bytes with no beginning/end. Make a parser as a state machine that searches for a message header and uses checksum and/or timer to validate/cancel the message.