How to not lose UART data while waiting inside of EXT0 interrupt?

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

I'm not much of a embedded programmer and I think I'm gonna need your help for this one since I couldn't figure it out by myself. 

In my code EINT0 (external interrupt 0) is activated and I'm waiting for a Falling edge signal on EINT0 pin while I have activated UART Receive interrupt and some device is sending data through it.

Since I have to make a pulse every time that Falling edge signal comes (make a pin Low then make it high after 1mS in ISR) and thus I have to wait somehow in EINT0 ISR (like a simple delay) how can I make sure that I won't lose any UART data? 

 

I think I should not wait using delay in EINT0 ISR or Do I have to implement some kind of RTOS or something ? or would that just be too complicated for such a small problem? 

This topic has a solution.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

while waiting inside of EXT0 interrupt?

The thread title says it all! No ISR should be "waiting" - ever!

 

If you get an INT0 interrupt for one edge then expect to trigger on the other then set the rising/falling bits to the other state and return from the interrupt. You'll get another one when you hit the other "edge" of the signal.

 

if you are doing this I'm sort of guessing this might be about measuring the elapsed time between edges (measuring period/frequency in some way?) If so there could be "better" ways such as using the input capture facility that most timers offer.

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

Thank you

No it's not about measuring anything. What made you think that? It's as simple as it sounds. I have to make a 1mS width pulse when EINT0 occurred. So I have to have a some sort of wait in my ISR, right? What technique should I use instead of that wait so I can handle UART receive interrupt while having that 1mS pulse as well?

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

Thank you

No it's not about measuring anything. What made you think that? It's as simple as it sounds. I have to make a 1mS width pulse when EINT0 occurred. So I have to have a some sort of wait in my ISR, right? What technique should I use instead of that wait so I can handle UART receive interrupt while having that 1mS pulse as well?

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

So I have to have a some sort of wait in my ISR, right?

Wrong.  Many different ways to do it, depending on your configuration and accuracy/precision needs.  Most of us would use an AVR timer, and ideally with the output pin on a "compare" (OCnx) pin and let the timer do its work.

 

Must be a high-speed USART link, as 1ms is about one character time at 9600bps.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My approach would be something like this:

 

In EINT0 ISR:

start timer which will give you interrupt after 1ms

set pin low

return

 

In timer ISR:

set pin high

(stop timer)

return

 

Ensure that time spent in either of these ISRs is smaller than time needed to receive one byte by USART, and you will not loose any data from it.

 

 

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

You want ISRs as SHORT as you can get them for just this reason. On your EINT0, start your output pulse and set a timer or something to make another interrupt when it's time to end the pulse. Or even better, just use a timer to make the pulse and have EINT0 just start the timer.

274,207,281-1 The largest known Mersenne Prime

Measure twice, cry, go back to the hardware store

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

Thanks guys

bojanrc's idea seems good. I'll try that and if something else comes up I'll let you know. 

Wish I knew more about these techniques. Is there such a book or something where one can learn about these tricks and approaches?

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

mostafanfs wrote:

Wish I knew more about these techniques. Is there such a book or something where one can learn about these tricks and approaches?

 

It's called a BSCS degree!

 

 

 

jc

Last Edited: Fri. Nov 14, 2014 - 02:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

It's called a BSCS degree!

 

Yeah I have couple of those for sure !

I meant when it comes to programming for embedded systems @;