|
|
View previous topic :: View next topic |
Author |
Message |
ikilicaslan
Joined: 25 Aug 2010 Posts: 1
|
How to read two RS232 ports using PIC18F8680? |
Posted: Wed Aug 25, 2010 2:54 am |
|
|
Hello,
I am using a PIC18F8680 and want to read two RS232 ports on one PIC.
The inbuilt functions getc(), putc() and kbhit() is quite useful when using a single RS232 port where kbhit() is used to indicate whether the message on the channel is ready to be read.
Additionally I know that PIC18F8680 support multiple RS232 routing using streams as follows:
Code: |
#use rs232(baud=9600, xmit = PIN_C6 , rcv = PIN_C7 , stream = CH1)
#use rs232(baud=9600, xmit = PIN_C6 , rcv = PIN_C7 , stream = CH2) |
Then these individually routed RS232 channels can be read or written using the inbuilt functions fgetc() and fputc(). But there is no such fkbhit() function (or a function with another name) to act as a flag for incoming data for two different RS232 channels.
Therefore here are my questions:
1) Assuming that I use polling to understand whether the message is ready to be read at the RS232 input. How could I understand which channel does the incoming message belong to? In other words are there any flags or functions to show me which channel is the message coming from?
2) Can another technique be used to handle this problem? I guess using the interrupt service routines would come up with a similar problem since the isr would be triggered upon a message arrival and it wont be able to distinguish the channels.
I would appreciate any help or any suggestions. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Wed Aug 25, 2010 3:58 am |
|
|
kbhit, already does this.
kbhit(STREAM)
Just include the stream name, in the kbhit call....
However, you seem to be talking about having two seperate streams on one UART. If so, there is nothing you can do. If there is only one hardware UART, you will only get interrupts on the stream connected to it's pins. Change to a PIC with two hardware UARTs, and you will have INT_RDA, and INT_RDA2, for the two seperate UARTs.
If you want to route the single UART to different code sections, according to some internal flag, then stop using 'streams', and do it yourself. Just routine the input/output to the required buffer according to your own flag.
It is fraqctionally possible to implement _very_ limited second channel comms, using a line that has a hardware 'level' interrupt, and a software UART on this pin, but performance has very severe limitations, that makes it unsuitable for anything but warranted half-duplex comms. Anything more complex won't work. You can write your own hgandler based upon timer interrupts (I have posted a basic RS232 receive in the past using this), but involves more work.
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
|