CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F25J11 second serial dies after sleep

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

View user's profile Send private message Visit poster's website

PIC18F25J11 second serial dies after sleep
PostPosted: Fri Oct 18, 2013 11:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 18, 2013 12:33 pm     Reply with quote

Post a short compilable test program that shows the problem.
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

View user's profile Send private message Visit poster's website

PostPosted: Fri Oct 18, 2013 1:00 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Oct 18, 2013 1:14 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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