I can't get my pic to fall asleep. I have quite a bit of code, so I will only insert the main. I read that all interrupt flags must be cleared before entering sleep. Could this be the problem? Or is it going to sleep and then instantly waking up?
I have tried inserting a breakpoint but mplab keeps complaining that one or more breakpoints could not be resolved

Thanks for your help.
Trevor
Code: Select all
//main routine
void main(void)
{
unsigned char data; //register to hold letter sent and received
unsigned char control[3];
unsigned int retry; //counter for for loop
int i;
int time = 0;
Initialize();
DelayMS(200);
lcd_init(); // initialize lcd unit
//main program loop
while(1)
{
CheckErrorsUSART();
//check UART status register to see if data has been received. if so, process
while(1)
{
DelayMS(500);
for(i = 0; i < 7; i++)
{
if(i == 6)
control[0]=!control[0];
if(PORTBbits.RB4==0)
DelayMS(500);
else
break;
}
nrf24l01_write_tx_payload(control, 3, true); //transmit received char over RF
//wait until the packet has been sent or the maximum number of retries has been reached
while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_tx_ds_active()));
//check to see if the maximum number of retries has been hit. If not, wait for the RX device
//to send char back. If so, assume the packet is lost and send "*" back to UART
if(!nrf24l01_irq_max_rt_active())
{
nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
nrf24l01_set_as_rx(true); //change the device to an RX to get the character back from the other 24L01
//wait a while to see if we get the data back (change the loop maximum and the lower if
// argument (should be loop maximum - 1) to lengthen or shorten this time frame
for(retry = 0; retry < 30000; retry++)
{
//check to see if the data has been received. if so, get the data and exit the loop.
// if the loop is at its last count, assume the packet has been lost and set the data
// to go to the UART to "?". If neither of these is true, keep looping.
if((nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()))
{
nrf24l01_read_rx_payload(temp, 3); //get the payload into data
break;
}
//if loop is on its last iteration, assume packet has been lost.
if(retry == 29999)
{
temp[0] = '?';
temp[1] = '?';
temp[2] = 0;
}
}
nrf24l01_irq_clear_all(); //clear interrupts again
//wait a while to see if we get the data back (change the loop maximum and the lower if
// argument (should be loop maximum - 1) to lengthen or shorten this time frame
for(retry = 0; retry < 30000; retry++)
{
//check to see if the data has been received. if so, get the data and exit the loop.
// if the loop is at its last count, assume the packet has been lost and set the data
// to go to the UART to "?". If neither of these is true, keep looping.
if((nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()))
{
nrf24l01_read_rx_payload(status, 3); //get the payload into data
break;
}
//if loop is on its last iteration, assume packet has been lost.
if(retry == 29999)
{
status[0] = '?';
}
}
nrf24l01_irq_clear_all(); //clear interrupts again
sauna_status();
display_tempstr();
display_temp();
DelayUS(130); //wait for receiver to come from standby to RX
nrf24l01_set_as_tx(); //resume normal operation as a TX
}
else
{
nrf24l01_flush_tx(); //get the unsent character out of the TX FIFO
nrf24l01_irq_clear_all(); //clear all interrupts
printf("*"); //print "*" to the screen to show that the receiver did not receive the packet
}
ToggleLED(); //toggle the on-board LED as visual indication that the loop has complete
nop();
INTCONbits.INT0IF = 0; // Clear INT0 Interrupt Flag
Sleep();
}
}