Programmable XBee S2B freezes after sleeping the radio

I’m writing an application for a programmable S2B which in one configuration needs to sleep the radio during initialization (before entry into the main for loop). I’m seeing the application freeze inside the sys_xbee_tick() function. I traced it to the processing of a modem status == joined (2) message which calls the internal handler. The handler never returns. The handler basically sends a bunch of AT command queries to the EM250. Since the watchdog doesn’t reset the CPU, I’m assuming it is stuck inside the loop in the xbee_ser_write function waiting for the bytes to go to the EM250’s UART, but the radio is sleeping. As far as I can tell, this is the only loop that resets the watchdog timer, from xbee_serial_hcs08.c, line 183 and onward:


case SERIAL_PORT_SCI2:			// EM250
	while (length--)
	{
		// SCI2S1_TDRE -- 0 = sending, 1 = ready for byte
		// PTDD_PTDD6 -- 0 = clear to send, 1 = not clear
		while (! SCI2S1_TDRE || PTDD_PTDD6)
		{
			__RESET_WATCHDOG();
		}
		SCI2D = *((const byte FAR *)buffer)++;
	}
	break;

How do I prevent the joined message from triggering this freeze?

Try adding an end If statement having the processor query /CTS. If /CTS is not active, then do not query the radio.

My code is not querying the radio. That code is part of the XBee framework that handles modem status messages. I have the modem status handler disabled in my config.xml. This is some library code that is updating the network address and other values in the xbee device struct.

I tried as you suggested in the main for loop around sys_xbee_tick() and it worked. Thank you very much! I added if (xbee_ser_get_cts(&(xdev.serport))) in front of sys_xbee_tick().