View previous topic :: View next topic |
Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
RS232 interrupt equivalent for PIC16F84A? |
Posted: Thu Oct 19, 2006 1:52 am |
|
|
Hi
I would like to detect, and read characters comming over an RS232 line.
I have to use the PIC16F84A chip which does not have a hardware UART.
So the standard #int_rda is not available to me.
Can someone please tell me how to implement an equivalent check when characters are being sent over the RCV line?
Thank you
a. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Thu Oct 19, 2006 2:04 am |
|
|
Here are a couple of options.
1. Using the CCS software driver, you can connect the RS232 RX to the int pin. Then when an interrupt occurs you do a getch() inside the interrupt handler. This driver is half duplex, while it is sending it cannot be receiving. If a transmit is in progress when an interrupt occurs the transmitted data will be rubbish. Therefore if you ned to transmit and receive you have to determine what you want to do in this situation. If may be as simple as disabling interrupts while you transmit. Don't forget to always clear the external interrupt flag before enabling the interrupt.
2. You can use a timer to generate a bit clock. Then use an timer interrupt handler. Ideally you want a minimum of three interrupts per real bit time. This will enable you to achieve 4800 baud full duplex (simultaneous send and receive) on a PIC16F84 - possibly even 9600 baud. However if you do want full duplex send and receive you have to craft the interrupt handler to ensure each path thru the handler takes the same number of clock cycles to avoid introducing jitter to the tx stream. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Oct 19, 2006 2:16 am |
|
|
Hi Asmallri
Thank you for your suggestions.
Unfortunately I cannot use option (1) since I am already using the interrupt pin for something else.
I do not quite understand what you describe in option (2). I have a timer that interrupts every 4.096ms. Should I put in something like:
Code: |
if(kbhit()){
function2ReadRS232();
}
|
within the timer interrupt?
I do not write over the RS232 from the PIC16F84A. I am just "listening" and once a certain sequence comes over the line, the 84A has to do some stuff.
All the best
a. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Thu Oct 19, 2006 4:24 am |
|
|
One a 16F series PIC, you only have one interrupt priority, this means the timer method will probably not be reliable enough to implementthis technique as jitter is introduced as a result of external interrupts being process asynchronously.
On an 18F series PIC you could get around this mechanism by having the timer use the high priority interrupt.
WRT the mechanism, you run a timer to interrupt every 1/3 bit time. The ojective is to attempt to find the start bit edge. Lets say you have had a timer rollover without detecting a start bit but microseconds later a start bit occurs. At the next timer interrupt you will detect this condition and already be one third into the bit time. One the next edge of the timer you would sample (and confirm) the start bit is present. Then every third timer tick you sample the next bit.
If you are interested I sell the source code for such a driver on my site but this is the basic mechanism. The same timer interrupt is used for tx bit timing. As mentioned, you need to take care to ensure all paths through the handler take the same amount of CPU cycles to avoid introducing jitter into the tx waveform. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|