View previous topic :: View next topic |
Author |
Message |
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Thu Apr 19, 2018 6:33 am Post subject: Using software serial and Timer0 interrupt together on ATtin |
|
|
I'm attempting to use software serial ports and Timer0 in 1 second interrupt mode together in an ATtiny45, but it does not work. They both work separately, but not when combined in the same firmware.
I vaguely recall seeing somewhere that the two cannot be used at the same time, but I cannot find that article/post anywhere.
Can someone please advise whether this is correct?
(BASCOM-AVR version : 2.0.7.7 , Latest : 2.0.8.1 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Thu Apr 19, 2018 6:57 am Post subject: |
|
|
Hi,
Software serial port is just that. Serial communication needs fairly accurate timing to work and if your ISR (interupt handling code) takes too long it could delay the Serial code enough to corrupt communications.
How long does you ISR run (Show us some code, hint, hint).
I once wrote a software/interrupt driven serial input (Using a Timer and a Pin Change interrupt). I see if I can find the code when I get home this evening.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
sentinel
Joined: 02 Feb 2009 Posts: 141 Location: Tasmania
|
Posted: Thu Apr 19, 2018 12:05 pm Post subject: |
|
|
Thanks for the reply, Ian.
For some reason I can\'t fathom, the code is now working.
Sorry for the false alarm. |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Thu Apr 19, 2018 12:53 pm Post subject: |
|
|
Hi,
It could be a timing problem. You might be just inside the limit with your ISP.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Apr 19, 2018 2:38 pm Post subject: |
|
|
i.dobson wrote: | It could be a timing problem. You might be just inside the limit with your ISP. |
And care has to be taken that soft-serial handling completely within ISR may keep INTF0 set.
INTF0 is initially cleared by execution of the INT0-vector, but set again by pin-toggling of incoming serial data.
This leads to another execution of named ISR immediately after leaving it, while then no data is available and it gets stuck.
Solution is to clear INTF0 just before leaving the ISR by writing an 1 to it. |
|
Back to top |
|
|
|