PDA

View Full Version : HSEROUT & Sleep Question



rocket_troy
- 4th March 2014, 22:37
I have some code that sends commands via hardware serial port from one 18F14K50 to another. Due to UHF EMI (it's a UHF transmitter application) I need to put the master PIC into nap or sleep mode immediately after sending the command as you can actually hear the master's audio signature over the UHF's transmitted audio stream if it's in normal power mode (go figure).
Anyway... The problem I have is when I place a sleep or nap command immediately after the HSEROUT, it doesn't appear to send the serial command or at least, not all of the serial command ie. it's likely missing the terminating character of the command thereby the slave processor isn't registering the command.
If I replace the sleep or nap commands with pause or place a small pause between the HSEROUT & Nap/Sleep commands, it appears to work ok.
So any ideas as to what is going on here?

Thanks,

Troy

Darrel Taylor
- 5th March 2014, 00:52
You need to wait until the USART has finished sending all the bits before going to sleep.

The TRMT bit (TXSTA.1) reads 0 (TSR full) while the USART is still shifting out data.
Wait for it to go to 1 (TSR empty) before going back to sleep.



TRMT VAR TXSTA.1

HSEROUT ["Hello World!"]
WHILE NOT TRMT : WEND
@ SLEEP

rocket_troy
- 5th March 2014, 01:19
Thanks Darren!

Cheers,

Troy

rocket_troy
- 5th March 2014, 01:20
Thanks Darrel! (not Darren) [whacking forehead]

Troy