View previous topic :: View next topic |
Author |
Message |
soonc
Joined: 03 Dec 2013 Posts: 215
|
Question about UART not working after sleep() |
Posted: Sun Sep 30, 2018 6:44 pm |
|
|
18F67K22
Compiler: V5.081
Hardware UART is working just fine before doing sleep();
My Question: Are there any known issues with UART not working after sleep() ?
CPU is running but UART is not working after sleep().
Code: |
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=BLE,ERRORS)
// Code is working fine communication with external device is consistent.
// At one point in the code I need to call sleep();
sleep();
delay_cycles(1); // I also tried 2 cycles (nop's)
// wake up from sleep by RTC alarm Interrupt.
// at this point the UART no longer works.
|
I understand the sample is very limited, the full code is under NDA so I can't post it here.
I have tried disabling the uart before calling sleep() with a call to
setup_uart(0,BLE);
and then after wakeup from sleep() doing setup_uart(115200,BLE); to enable the uart again. It did not fix the problem.
I have tried sleep(SLEEP_IDLE); and that did not fix the problem.
Any suggestions regarding how to enable the uart after sleep() is welcome. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 30, 2018 7:23 pm |
|
|
What happens if you do a delay of 100 ms after waking up from sleep,
before using the UART ? |
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
Cried UNCLE too soon... ! |
Posted: Sun Sep 30, 2018 8:02 pm |
|
|
Buffer overrun caused the issue...!
UART works fine after sleep, and when not sowing weeds in the garbage patch! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Oct 01, 2018 4:50 am |
|
|
You need to make sure first thing PIC does just before AND after it wakes up from sleep, is to purge (clean out) or read the receive buffer.
I can see how any device attached to the serial input could send data and fill the buffer. I've never used sleep() and serial together so I've never read the datasheet to see how Microchip handles that situation.
Jay |
|
|
|