CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Can software UART use interrupts?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 403

View user's profile Send private message

Can software UART use interrupts?
PostPosted: Mon Feb 04, 2019 9:10 am     Reply with quote

I have a firmware that currently has a lot of routines and I need to add an extra software UART at 4800bps but I cant wait indefinitely because I have a lot of another tasks to perform so I was thinking in to have an interrupted software UART.

Is this possible with the CCS library or I must to create my own?
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Feb 04, 2019 9:19 am     Reply with quote

It's 'sort of possible'.

Basically all you do, is setup a software UART which received on a pin
that supports a 'level' interrupt.
Then set this to interrupt on a falling edge.
In the interrupt routine, call the software UART getc.

Then what happens is on the falling edge on the input pin, the handler
gets called, and the getc is then called.

If using a faster baud rate, you may have to set the software UART to
use the option 'SAMPLE_EARLY'. This means it starts reading data as soon
as it is called, rather than waiting for half a bit time after this. Reason is
that it will typically take perhaps 30 instruction times to actually get into
the interrupt handler, and if this was (perhaps) nearly half a bit time,
the software UART would be reading too late in the bit. However unless
your clock rate is very slow, this is not likely to be an issue at 4800bps.

However big caveat is that the code will remain in this handler for 1/480th
second (10 bits at 4800bps), which may cause issues with other interrupts.

Also separately on transmit, other interrupts can/will cause timing errors
with this, and (worse), if you get a receive interrupt while transmitting,
you will have problems....

I did publish in a thread a while ago, a 'timer' based software UART to
give more 'friendly' behaviour. A search should find this.

Update: The timer based software UART is here:
<http://www.ccsinfo.com/forum/viewtopic.php?t=39958&highlight=software+rs232+disturbed+interrupts>
E_Blue



Joined: 13 Apr 2011
Posts: 403

View user's profile Send private message

PostPosted: Mon Feb 04, 2019 11:26 am     Reply with quote

Thanks for your answer.

The protocol is mastered half duplex so I think I will not have issue with devices talking at same time.
I think I will use an interrupt timer to save the data.
_________________
Electric Blue
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group