![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
tmuir80
Joined: 05 May 2015 Posts: 1 Location: United States
|
Software and Hardware UARTs on the same pins? |
Posted: Tue May 05, 2015 11:57 am |
|
|
I need to be able to use the software UART and the hardware UART on the same pins, but at different times. The product I'm developing has a lot of legacy test hardware that expects inverted RS232, as it doesn't need any level changing hardware, because it's TX only. But now I also need a special mode that I can receive data, and a software UART doesn't have any buffering. Believe me, if I could make everything hardware UART, I would.
I don't need to switch back and forth. If the system is powered up with MODE_PIN held low, the hardware UART is used for configuring the system. Afterwards, the system is reset with MODE_PIN high, the system goes into normal operation, and uses the software UART.
I can make the two modes work independently, but not together. Here are my two #use rs232 statements:
Code: |
#use rs232( force_sw, invert, baud=9600,xmit=PIN_C6, parity=N, bits=8, restart_wdt, stream=DEBUG)
#use rs232( baud=9600,xmit=PIN_C6,rcv=PIN_C7, parity=N, bits=8, restart_wdt, stream=SETUP)
|
|
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue May 05, 2015 1:23 pm |
|
|
whether you mean TRU RS-232 ( +/-8v IO) or TTL levels from the PIC
what you want to do can be done quite simply with ONE otherwise un committed pin on your PICC design plus 2/6 of a 74HC04 and the gates of a 74HC4066 as Glue logic -- and then use only the HARDWARE UART.
if you could be CERTAIN of the idle state of your inverted channel it could even be done with different logic chips and no 4066 gates at all.
almost any other approach is going to be dodgy at best using code alone--
and you are sooooooo unclear about how the opposite polarity devices are "sharing" in HARDWARE terms...
\but to understand WHY our code does not work i would need to see MUCH more than what you show..... |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Tue May 05, 2015 1:53 pm |
|
|
A second option, use a PIC with two HW UARTS. Though asmboy is right it 'could' be bodged with a couple other chips what's YOUR R&D time worth? You could easily spend 2 -3 DAYS getting it to 'work' but using a PIC like the 18F46K22, you could be solidly and reliably 'up and running' in a couple hours.
Yes a 'bigger' PIC does cost a few cents more BUT comes with MORE codespace, 'extra' pins, and other things....
Even if the PIC costs $1 /unit more even buying 100 pcs that 's still less than the $100/hr R&D cost.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue May 05, 2015 2:19 pm |
|
|
This can be done as you show. The key though is to add NOINIT to the hardware RS232 setup, and specify the baud as zero. So:
Code: |
#use rs232( force_sw, invert, baud=9600,xmit=PIN_C6, parity=N, bits=8, restart_wdt, stream=DEBUG)
#use rs232( baud=0,UART1,NOINIT, parity=N, bits=8, restart_wdt, stream=SETUP)
|
Then when you want to use the hardware UART, use the line:
setup_UART(9600);
and then talk to the SETUP stream.
Without this line, you can talk to the DEBUG stream.
Done this way, #use RS232 on the hardware is 'ready to go', but doesn't initialise the hardware, till the setup_UART line.
Without NOINIT, with a specified baud rate, the hardware is initialised and overrides the normal I/O function on the stream. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|