View previous topic :: View next topic |
Author |
Message |
hillcraft
Joined: 22 Sep 2003 Posts: 101 Location: Cape Town (South africa)
|
Enabling and disabling #USE RS232 ... |
Posted: Fri May 26, 2006 6:18 am |
|
|
I need to sense a non-uart pin. The data may be 19200 8N1 or it may be a completely different pulse train.
I can use #use RS232 to test the pin initially to see if the data is RS232 data, but...
How do I disable the #use RS232 if the data is found to be invalid? |
|
|
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Fri May 26, 2006 7:24 am |
|
|
You can always disable/enable/reconfigure any feature of the PIC by writing the appropriate register bits directly. I often do this rather than depend on the idiosyncracies of the compiler. I find that I, and I assume others, sometimes forget that it is OK to not use the predefined functions. |
|
|
Ttelmah Guest
|
|
Posted: Fri May 26, 2006 7:27 am |
|
|
In order for RS232 I/O to take place (assuming this is a hardware UART), the TRIS register must be set to allow the UART to have control of the pin. The setting for this varies with different PICs. You can use a UART pin for something else, by simply changing this setting (this is very useful, where you want to use for example a hardware receive pin, but use the other UART pin for something else). Alternatively, you can turn the UART peripheral itself off, by just clearing the SPEN bit in the control register.
Best Wishes |
|
|
hillcraft
Joined: 22 Sep 2003 Posts: 101 Location: Cape Town (South africa)
|
|
Posted: Fri May 26, 2006 7:43 am |
|
|
Let me clarify the problem:
I have the following:
18F2550, running USB and RS232 via the standard UART.
I now have data coming in via pin B1. B1 is configured to interrupt on L_H. This information is used and then passed to the PC via USB.
There is a situation though, where the data coming in via B1 is perfect 19200 8N1. I would like to be able to switch to using the built in CCS rs232 code if this occurs.
The problem is really this:
if I have place #use RS232 (baud=19200, rcv=PIN_B1) in my code, how do I stop CCS from applying this routine, when I no longer want it to be used:
Pseudo Code:
Disable interrupt on B1
Set rs232 rec on B1
Read data for a while
Is this properly formatted data?
No
Disable rs232 rec on B1
Enable interrupt on B1
Use B1 interrupt received data as is.
I really need to be able to do the following
void Set_Rs232_B1_ON() {
#use RS232 (baud=19200, rcv=PIN_B1) ;
}
void Set_Rs232_B1_OFF() {
??
} |
|
|
Ttelmah Guest
|
|
Posted: Fri May 26, 2006 10:05 am |
|
|
If you are on 'B1', then you are using a 'soft' serial implementation. No hardware. As such, the serial code, is only used _when you call it_. You can perfectly well do any I/O you want on the pin, and the code will do nothing. If you want to perform serial input, set the pin as an input, and call the getc routine. You can do your own input functions on the pin at any time you want, and the RS232 code will not care at all.
Best Wishes |
|
|
hillcraft
Joined: 22 Sep 2003 Posts: 101 Location: Cape Town (South africa)
|
|
Posted: Fri May 26, 2006 1:38 pm |
|
|
Ah, of course.
I will try it in the morning.
Thanx. |
|
|
|