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

UART RX in low power mode

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



Joined: 17 Dec 2005
Posts: 58

View user's profile Send private message

UART RX in low power mode
PostPosted: Thu Nov 13, 2008 10:55 am     Reply with quote

I am having a rather odd issue. I have a 38.4Khz crystal connected to Timer1. I switch from the main 48Mhz osc to the timer1 crystal to save power. A character coming in on the UART will wake up the PIC.

After programming the PIC or powering it up for the first time, the character is always detected incorrectly. Upon resetting the PIC, the character is detected correctly everytime there after.

Compiler Version: 4.080
PIC18F67J50

Relavent Code Below
--


Code:

#int_TIMER1
void timer1_isr()
{
   clear_interrupt(INT_TIMER1);
}


void main()
{
//timer1 (38.4Khz) setup
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);
set_timer1(0);
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
      
setup_oscillator(OSC_TIMER1 | OSC_IDLE_MODE);
      
#use delay(clock=timer1_clock)
#use rs232(baud=9600,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8,STREAM=serialport)
delay_ms(10);
set_uart_speed(9600,serialport);
      
wakeup_character = fgetc(serialport);
}





All other interrupts and timers are disabled during low power mode, I have also tried the #use rs232 statement with DISABLE_INTS and no difference.

Any ideas?
Ttelmah
Guest







PostPosted: Thu Nov 13, 2008 11:36 am     Reply with quote

The first received character on wake up, normally _will_ be received incorrectly. This is inherent in using the wake up function. It behaves as a way to wake, rather than an easy way to actually receive data. The easiest way, is to send a 'sacrificial' character to wake the chip, then wait for the main oscillator to start, and the chip to rouse, then start sending the real data.
You can have a character received correctly, if you use a new clock, and #use RS232 statement, with the value setup for the correct divisor for the low frequency clock, and select this to receive the first character. To do this, you also need to delay switching to the main clock, till the UART is idle (look at the RCIDL bit). You can also 'cheat' this, by using the set_uart speed function, and selecting as your required baud rate, a value of your real baud rate, *48000000/38400. Again though, you will need to check the RCIDL bit before selecting the real clock, and switching the baud rate to normal operation.
The problem is that the UART is clocked off the slower clock, and therefore will sample at the wrong time...

Best Wishes
ktallevi



Joined: 17 Dec 2005
Posts: 58

View user's profile Send private message

UART RX in low power mode
PostPosted: Thu Nov 13, 2008 12:01 pm     Reply with quote

Ttelmah, as you can see in my code, I am not putting the PIC to sleep, just switching to the Timer1 clock.

I am using a hardware UART, and the timer1 clock is 4 times the 9600 bitrate. So I should be able to read the character successfully without any error in the 38.4Khz mode.

From what I can tell, my code follows exactly what you recommended for reading the character without error.

Also as I had mentioned, it only fails when I initially program the PIC or power it on, once I issue a reset it reads the character correctly.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Nov 13, 2008 12:55 pm     Reply with quote

Please read the processor manual thorougly. No standard UART is operating with factor 4 oversampling, most use factor 16. You can't receive 9600 baud with a 38k4 crystal.

It can be seen from your code, how the UART baud generator is actually programmed, cause the respective statements (e. g. #use delay or manual override of baud rate) are missing.
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