|
|
View previous topic :: View next topic |
Author |
Message |
robin171
Joined: 12 Sep 2008 Posts: 4
|
Switching UART on and off |
Posted: Thu Sep 18, 2008 8:30 am |
|
|
Hello,
I have a problem with the #use UART statement
I have a ST7538 powerline transceiver connected to a PIC16F877A. RX and TX of the transceiver are connected to the hardware UART of the 16f887a. The CLR/T pin is connected to the B0 / INT pin of the microcontroller.
The ST7538 uses the CLR/T as a clock output for synchronous communication with a microcontroller. If you want to write the control register of the powerline transceiver, you must use synchronous communication.
I wrote a interrupt function for EXT_INT that writes 24 bits to the powerline tranceiver via pin C6. I tested this function with the scope, it works fine until I declare the following statement:
Code: | #use rs232(baud=600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PLM,restart_wdt) |
The C6 pin is continuously high...
Is there any way (a CCS function maybe? I'm a just starting with the CCS compiler) to disable the hardware UART until the control register of the powerline transceiver is written?
Thanks,
Robin
[/code] |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: Switching UART on and off |
Posted: Thu Sep 18, 2008 11:58 am |
|
|
The block diagram in figure 12-1 of the datasheet shows SPEN controlling the hardware UART's use of the TX pin (RC6). You can assume when your main program starts that the CCS runtime code has already initialized everything, including the RCSTA register that has the SPEN bit. So you need to override that by temporarily clearing RCSTA.SPEN until you have done your custom thing with RC6, and then set SPEN back to 1 when you want to enable the hardware serial port.
You can get direct access to the RCSTA register by declaring:
Code: |
#byte RCSTA=0x18
#define SPEN 7
|
Then later in your code you can do this:
Code: |
bit_clear(RCSTA,SPEN); //..disable UART
. . . //..initialize PLM...
bit_set(RCSTA,SPEN); //..re-enable UART
|
_________________ Robert Scott
Real-Time Specialties
Embedded Systems Consulting |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Sep 18, 2008 12:15 pm |
|
|
As an alternative to directly accessing the SPEN bit you can use the setup_uart function which does the same thing but is easier to read. CCS Manual wrote: | Very similar to SET_UART_SPEED. If 1 is passed as a parameter, the UART
is turned on, and if 0 is passed, UART is turned off. If a BAUD rate is passed to
it, the UART is also turned on, if not already on. |
Code: | .................... setup_uart(0); // Disable the UART
09E8: BCF RCSTA.SPEN
09EA: BCF RCSTA.CREN
.................... setup_uart(1); // Enable the UART again
09EC: BSF RCSTA.SPEN
09EE: BSF RCSTA.CREN |
|
|
|
|
|
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
|