View previous topic :: View next topic |
Author |
Message |
Diego1974
Joined: 13 Jan 2012 Posts: 2
|
Enable & Disable RS232 at runtime |
Posted: Fri Jan 13, 2012 8:06 pm |
|
|
Hi, this is my first post, I have a project using 16f1824, i want to enable the RS232 when PIN_A5 is high, and disable when its low, but i don't know how to disable the rs232.
Any ideas??? _________________ Diego |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sat Jan 14, 2012 3:03 am |
|
|
One has to ask what you mean by 'disable'?.
At the end of the day, if you don't send anything, the RS232 sits doing nothing. So, just stop sending....
However if you means you want to use the pins for something else, then use the baud=0 option.
If you have your #use RS232 set baud=0, everything is setup ready to go, but the UART is turned off. Then just use 'setup_uart(baud_rate_you_want);', to start using the UART, and when you have finished, use 'setup_UART(FALSE);' to turn it off again.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Diego1974
Joined: 13 Jan 2012 Posts: 2
|
|
Posted: Sat Jan 14, 2012 7:53 am |
|
|
Thank you Ttelmah, thats exactly what i'm trying to do, use in some part of the program the RS232 pins, and in another part to do something else, so thank you for your support. I will make some test and i will post the results.
Regards, _________________ Diego |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sat Jan 14, 2012 8:30 am |
|
|
One problem you may have concerns the device on the other end of the RS232 pins. When you use them for 'the other action', you'll also send data to the other device. Depending on that devices program you could lock up it's UART or send bad data to it.
Just something to watch out for. |
|
![](templates/subSilver/images/spacer.gif) |
mfeinstein
Joined: 05 Jul 2012 Posts: 35
|
|
Posted: Thu Mar 21, 2013 9:32 pm |
|
|
I am using a PIC18F2550 and this only works for me if I call a 'setup_uart(1);' after a 'setup_uart(0);'.
If I try like Ttelmah said, just placing a 'setup_uart(baud_rate_you_want);' it never turns one again and the PIC freezes forever. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Fri Mar 22, 2013 5:46 am |
|
|
without seeing your code it's impossible to say why it 'freezes' but perhaps you have an interrupt enabled without a handler?
or a sunset loop?
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Mar 22, 2013 6:08 am |
|
|
caveat creator :
re-purposing the TX pin in runtime, w/o a hardware GATE for your TX destination is a surefire way to get into trouble.
RX , not so much |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Fri Mar 22, 2013 6:16 am |
|
|
It'll behave like this if you try to set a baud rate on a _software_ UART. Are you sure you are using the hardware UART?...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|