I'm having a strange problem with a program for the CC1111 USB dongle: My program randomly reboots, sometimes after a few tens of minutes, sometimes after many hours. I'm relatively new to embedded systems, so I might be making a rookie mistake.
I'm working on a breadboard prototype -- the dongle is wired up to a digital temperature sensor and a digital accelerometer via an SPI bus. I'm using IAR EW8051 8.10.3.
I had been communicating with my program using serialport-over-USB, and thought perhaps the PC was responsible. So I've removed that from the equation -- I have the dongle connected to a USB cable plugged into a powerstrip surge protector with a USB port. All feedback now happens through the LED.
At the beginning of main() I check the SLEEP register to see the reason for the last reset, and set an LED blink pattern accordingly:
int main( void )
{
uint8 reset_cause = (SLEEP & SLEEP_RST) >> 3;
if (reset_cause == 0)
led_pattern = POWER_RESET_PTRN;
else if (reset_cause == 1)
led_pattern = EXT_RESET_PTRN;
else if (reset_cause == 2)
led_pattern = WATCHDOG_RESET_PTRN;
else
led_pattern = ERROR_PTRN;
I take input from the dongle button. On the first press, I change the LED pattern to a "default pattern" that is different from the others. Then I wait. Eventually, it restarts and the LED pattern tells me that the last reset cause was an external reset. I can also produce this by sticking a paper clip or wire in the ribbon cable connected to the debug connector (pin 7).
If the button is pressed a second time, the program begins a ten second countdown and then calls halMcuReset(), which uses the watchdog timer to reset the uC. Ten seconds later, I see the WATCHDOG_RESET_PTRN I expect.
One weird thing is that if I disconnect the dongle from the USB cable (so no power), wait, and reconnect it, the LED pattern shows the EXT_RESET_PTRN, and not the POWER_RESET_PTRN. This is making it impossible to determine whether power is the problem. When the dongle was still connected to the PC, I do believe I saw the POWER_RESET_PTRN at least once.
Any idea what could be causing this? Can I trust SLEEP.RST?
Thanks!
-David