View previous topic :: View next topic |
Author |
Message |
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
PIC18F25J11 second serial dies after sleep |
Posted: Fri Oct 18, 2013 11:59 am |
|
|
I'm using the 4.129 version of the compiler with the above chip. I have used the peripheral select instructions to turn a set of pins into the second UART. This works fine and the UART will send sane looking data - until the unit goes to sleep. After it wakes up the second uart is totally messed up and outputs garbage. I've tried to use setup_uart with the proper baud and stream name but it does not work. Is this a known issue? Do I need to pony up the dough for the newest version of the compiler? Any easy work arounds? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 18, 2013 12:33 pm |
|
|
Post a short compilable test program that shows the problem. |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Fri Oct 18, 2013 1:00 pm |
|
|
This isn't perhaps the smallest program ever but it faithfully reproduces the environment that the actual project is running. It strikes me that it perhaps is because I go to sleep before the serial is finished but it seems to refuse to reinitialize the serial properly when it wakes back up.
Code: |
#include <18F25J11.h>
#fuses INTRC
#fuses NOWDT //turn off WDT in hardware - allows for software control
#fuses WDT256 //placeholder to put longer duration command for testing.
#fuses NODEBUG //don't enable chip level debugging
#device ADC=10 // use 10 bit ADC reading
#device PASS_STRINGS = IN_RAM
#use delay(clock=8000000) //8Mhz for internal RC
#use fast_io(ALL) //don't automatically set pin states.
#PIN_SELECT RX2=PIN_C2
#PIN_SELECT TX2=PIN_C1
#use rs232 (uart1, baud=9600,errors,stream=bio)
#use rs232 (uart2, baud=9600,errors,stream=pc)
void set_port_direction() {
set_tris_a(0b00000100);
output_low(PIN_A0);
output_low(PIN_A1);
output_low(PIN_A3);
output_low(PIN_A5);
output_low(PIN_A6);
output_low(PIN_A7);
set_tris_b(0b00110001);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B6);
output_low(PIN_B7);
set_tris_c(0b10010100);
output_low(PIN_C0);
output_low(PIN_C1);
output_high(PIN_C3); //acts as ground path for tilt sensor
output_low(PIN_C5);
output_low(PIN_C6);
}
void main(void) {
#use fast_io(ALL)
setup_wdt(WDT_OFF);
setup_oscillator(OSC_INTRC | OSC_8MHZ);
delay_ms(50);
set_port_direction();
fprintf(pc, "Starting Up!\n");
while (1) {
setup_uart(9600, pc);
setup_uart(9600, bio);
fprintf(pc, "In Loop\n");
setup_wdt(WDT_ON);
restart_wdt();
sleep();
delay_cycles(1);
setup_wdt(WDT_OFF);
}
}
| [/code] |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Fri Oct 18, 2013 1:14 pm |
|
|
Aaaand, yeah, I should have known. At least being forced to produce an example program made me test my theory. It is true that the reason it messes up is that it was sending characters when it went into sleep and the hardware doesn't properly reset if that happens. I added #byte TXSTA2 = 0xFA8 and then a while ((TXSTA2 & 2) != 2); before sleeping and everything works fine. |
|
|
|