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 CCS Technical Support

Simple question about software UART interrupt

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



Joined: 31 Jan 2014
Posts: 20

View user's profile Send private message

Simple question about software UART interrupt
PostPosted: Fri May 02, 2014 1:57 am     Reply with quote

I am trying to us a software UART on PIC24FJ64GA004 and wants to receive data when available but i am unable to find any interrupt for software serial port.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri May 02, 2014 2:33 am     Reply with quote

There isn't one.

A software UART, has to be sitting 'waiting' for a character to arrive. Polling the input. No interrupt.

For a _low baud rate_ character, or with a fast chip, you can (sort of) simulate an interrupt on data receipt, by using _any_ input pin, that supports a falling edge interrupt. Then when the line falls, this interrupts, and you then call the software routine inside this interrupt handler.

Depending on the speed of the chip, and the serial rate involved, you may need to use the 'sample_early' option in setting up the software UART. This tells the code to not delay at the start, by half a bit time, to align with the middle of the data bits. Instead the time involved in getting into the interrupt handler provides the delay needed.

Remember the limitations.
The software UART is half duplex (transmit _or_ receive at any time). If you are using an edge interrupt like this, and are trying to send a character when this is received, the transmitted character _will_ be destroyed.
The software getc, sits polling the line for the entire character time. As such nothing else must happen while this is happening. Chip is fully occupied for the entire byte time..
The software UART, is best _only_ used by a device that 'responds' to a request from your chip, rather than something that sends data 'unexpectedly'.

Far better to rethink, and find a chip that has more hardware UART's, or add en external (I2C typically) UART.
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Fri May 02, 2014 12:52 pm     Reply with quote

There are some chips in that family that have 4 UARTS. I don't know which ones are pin compatible, but microchip's website has a pretty decent search tool which can narrow the search down.

Ttelmah (or anyone else), curiosity question on your comment:
If I remember correctly you tend to work more with the PIC18 and lower chips. Do you know if the ISR service times are comparable to a PIC24? I don't have as much experience with non PIC24 chips. Some of the things that come to mind (without digging through specific data sheets) are the PIC24 use a div2 system clock versus the div4 that other architectures use and the PIC24 doesn't use global interrupt to dispatch interrupts. That doesn't mean the times aren't comparable, but was wondering if you ever looked at it since you have a lot more experience with these kinds of things and it relates to how it might be implemented if the OP decides to play with that route (though I would also agree that going to a chip with more hardware UARTS is the better solution).
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri May 02, 2014 2:38 pm     Reply with quote

Better, because first of all you have direct vectoring, and secondly the chips are as you say a lot quicker.
Probably 1/4 the typical time of a PIC18.

As a comment, I posted a timer based software receive routine (in the code library), and this could be used much better on a PIC24, and can be adapted to give full duplex.
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