|
|
View previous topic :: View next topic |
Author |
Message |
RKnapp
Joined: 23 Feb 2004 Posts: 51
|
2 UARTS but only one #int_RDA; suggestions please |
Posted: Tue Mar 02, 2004 12:13 am |
|
|
Friends,
I think this is a dumb question but I'll plow ahead with it. PIC18F8720 has two USARTs; I only find one #int_RDA in CCS v3.185. How to implement two fully-interrupt-driven ports? (Interrupt in both rx / tx: I will be needing full speed.)
Anyway, consider Rx. What does #int_RDA actually mean? Is it necessary that a second interrupt be set up?
Perhaps CCS or even the chip has OR'd the interrupts? If so, I'd write a shared-interrupt ISR that tries to determine which UART fired (pseudocode below) by polling, and exits when no more bytes are coming in. Something like:
#bit U1RX = (address of ) PIR1.RCIF // something like this, right?
#bit U2Rx = (address of ) PIR3.RCIF
#int_RDA
isr_RxBytes
{
do
{
if ( U1RX )
// read "TXREG1" (which I think is RCREG) and buffer that byte:
buf1[some index ] = fgetc(stream1);
if ( U2RX )
// well then get and buffer this byte also:
buf2[stream 2's index ] = fgetc(stream2);
} while ( any bytes are there )
};
Would this more or less work?
But is it simpler / better to use kbhit() in place of that #BIT definition?
Any other suggestions? Code you could share? Note, the corresponding question applies to int_tbe: one interrupt, two UARTs. Are they shared, or does the interrupt only map to the first UART?
Thanks for your patience,
Robert
ps. One more question: what is a "software UART"? Does it take ANY two pins as Rx/Tx and create a shift register etc. or does this term refer only to the s/w support of a onboard, real hardware UART? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 02, 2004 12:51 am |
|
|
If you have a question about what interrupts are supported by
the compiler, look in the .h file for your PIC. These files
are found in this folder: c:\Program Files\PICC\Devices
Do a search for the word "INT_RDA" within your .h file. |
|
|
Ttelmah Guest
|
|
Posted: Tue Mar 02, 2004 3:50 am |
|
|
There are two seperate interrupts.
If you either look at the device editor, or the .h include file for the chip, you will find 'INT_RDA', and 'INT_RDA2' supported.
The 'software UART', is just what it says. It uses bit shifting in a register, combined with software delays to allow the input or output of a serial caharacter on any pins. The 'caveat', is that the timings are done as simple counters, so any interrupt activity, will affect the timing accuracies involved.
Best Wishes |
|
|
RKnapp
Joined: 23 Feb 2004 Posts: 51
|
|
Posted: Tue Mar 02, 2004 10:29 am |
|
|
PCM and Telmah,
Thank you both! Good -- separate interrupts.
But I"m still interested in the idea of a "software UART." How does it arise? Is it added to code when #use rs232 is included? Does this somehow mean that I could create 10 virtual UARTs on one u-controller?
Does it mean that a FIFO deeper than one byte could be created? (I'm used to working with real UARTs, in which 64 bytes is the std FIFO depth for Rx and Tx these days.)
What is the effect of a "software UART" when I'm attempting to connect to a "real" UART onboard the 8720 chip (C6/C7, G0/G1)?
Finally, is there any documentation?
Robert |
|
|
Ttelmah Guest
|
|
Posted: Tue Mar 02, 2004 10:56 am |
|
|
RKnapp wrote: | PCM and Telmah,
Thank you both! Good -- separate interrupts.
But I"m still interested in the idea of a "software UART." How does it arise? Is it added to code when #use rs232 is included? Does this somehow mean that I could create 10 virtual UARTs on one u-controller?
Does it mean that a FIFO deeper than one byte could be created? (I'm used to working with real UARTs, in which 64 bytes is the std FIFO depth for Rx and Tx these days.)
What is the effect of a "software UART" when I'm attempting to connect to a "real" UART onboard the 8720 chip (C6/C7, G0/G1)?
Finally, is there any documentation?
Robert |
Read the section in the manual, entitled:
"How can I use two or more RS-232 ports on one PIC".
This was written before the latter PIC's that have two UARTs, and explains how the #use RS232 works (it is a bit like a macro define - once set, this becomes the port in use, till another similar statement - the code is generated when the port is used). Again after this was written, you now have the 'stream' ability, to allow multiple #use RS232 statements to be switched between at will.
The example files (and a lot of posts on this board), show how to build 'soft' buffers to give any depth that you want (within the available RAM). Look at 'EX_SISR.C' for this.
This also mentions 'en-passant', using INT_RB on chips that don't have a hardware UART.
There is no hardware difference at all. Both 'UARTs', will still require a level translator chip (but the software one can sometimes be wired directly for receive, just using a resistor, and the 'INVERT' option, which reverses the transmitted/received polarity).
Best Wishes |
|
|
|
|
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
|