Break char on 324 USART

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are there a well defined way to detect a break on mega324? (The USART are normal so I guess it's for most AVR's)

 

I receive a break to put me in sync but I don't know when (The transmitter send a break when it boot). and then I need to flush everything , so I for sure get the first char. 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just an idea but connect RXD over to another pin (even a timer ICP one?) that you can use to measure the length of low periods?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My problem it's an existing board :(

So first plan was to check for frame error (with a char value of zero). Then I guess that I can say that I know that there are a break, but then when does it end!

I have a timer ISR running so I guess I need to poll the RX pin then , and when high flush the USART. (I have not checked it but I guess that I can read RX as a normal port pin)

So the next will be how do I flush the USART.(will read UDRx do the job?)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok this seems to be the flush:

Disabling the Receiver will flush the receive buffer invalidating the FEn, DORn, and UPEn Flags.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is this for a DMX (or RDM) receiving device by any chance?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How long is your break character?

 

If the numbers work, could you start with your USART running at a lower baudrate so that the break looks like a valid 0x00 and when that is received switch the baudrate to working speed?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One of the pitfalls of using either of those techniques (frame error w/ all-zero data bits, or lower baud rate) for break detection is sync.  Depending on your application, if the receiver could ever find itself out-of sync with the transmitter, then a break might go undetected.  Often a break is meant to establish sync so these techniques may not be suitable for you.

 

Specifically, what happens if a break comes along after a frame RX is already underway?  What if that break actually starts as the current frame is receiving it's last data bit?  The stop bit will be a zero so that will generate a frame error, but if the lower bits weren't all zero then it won't pass your "all-zero-data-bits-plus-frame-error" test.  The break will continue, but the USART will ignore it altogether because RXD will remain low.  Start bit detection occurs when RXD transitions from high to low.

 

Mind you if you know that your USART will never get 'out-of-sync' then those techniques can be made to work.

 

Otherwise you need an independent means of detecting a break.  Some AVR like the ATtiny167 have LIN peripherals that have a limited ability to detect a break even if it starts mid-frame.  On AVR with a normal USART I use pin-change, INTn, or ICPn, in conjunction with a timer interrupt to detect a break.

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]