Disabling UART Tx when entering SLEEP mode

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
streammaster
Posts: 78
Joined: Mon Jul 31, 2017 11:14 am
Has thanked: 7 times
Been thanked: 13 times
Contact:

Disabling UART Tx when entering SLEEP mode

Post by streammaster »

Hi everyone,

Can somebody please advise me what is the best way of disabling the UART Transmitter pin and converting it to input during SLEEP() mode?

I'm controlling the power of the peripherals, and I shut down all power on the board before entering the SLEEP(), but in SLEEP mode the UART remains active (Tx pin is high on +3.3V basically powering my GPS receiver).
I'm using UART (RS232) serial comm component. I noticed just now that the UART CAL has ability to be 'deinitilised' and release resources, but before i change my entire project (and by now it is basically finished and very large) i'm hoping that there is some way where i can disable transmit by simple C code statement. I tried to use 'Input' entry Flowcode macro by reading the input from the port just before entering the SLEEP, but this is doing nothing here.
The processor is PIC18F47J53 but this subject is i believe quite generic.

Thanks,

Igor

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Disabling UART Tx when entering SLEEP mode

Post by Benj »

Hi Igor,

It depends on which UART channel you're using but the following code should work to disable the transmit. Replace 1 with the number of your UART.

Code: Select all

TXSTA1bits.TXEN = 0;
To re-enable after coming back from sleep you can either reverse the C code or call initialise again.

Code: Select all

TXSTA1bits.TXEN = 1;
You can also power down the UART entirely with this code.

Code: Select all

TXSTA1 = 0;
RCSTA1 = 0;

Post Reply