EDIT: I just changed the reciever to toggle red LED instead of yellow, and now it doesn’t crash. What’s going on?
I’ve included what I was going to post below:
[quote]David, thanks for the tips. I think I’ve followed most of them.
First, I’ve made two apps, to isolate the issue. One only sends, and one only recieves. The sender works fine - I’ve tested it with the radio sniffer. However, the receiver crashes after a few messages have been recieved - maybe 5, or 3, or 13, or somewhere in between. It’s not the same every time I run it. Here’s how I know it crashes:
(1) The yellow LED is solid, and the green one does a double-blink every second.
(2) The “wixelconfig” program says that the app is stopped.
First, the sender code:
[code]/** Dependencies **************************************************************/
#include <radio_mac.h>
#include <board.h> // for LEDs
#include <cc2511_map.h>
#include <dma.h>
#include <radio_registers.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>
#include <string.h>
/** Global Variables *********************************/
#define RADIO_COUNT 2
#define MAX_TIMEOUT 50
#define MAX_PACKET_LEN 5
int32 CODE param_radio_channel = 128; // 0 - 255. Seperate by 2 channels to avoid crosstalk
uint8 XDATA rx_packet[MAX_PACKET_LEN + 4]; // room to store CRC
uint8 XDATA tx_packet[MAX_PACKET_LEN];
volatile uint8 PDATA radio_tx_available = 0;
volatile uint8 DATA respond_state = 0;
#define MESSAGE_RCV 1
#define BAD_CRC 2
#define RADIO_ID_ERROR 3
#define RADIO_TIMEOUT 4
/** Functions *****************************************************************/
void radioInitAddendum() {
CHANNR = param_radio_channel;
PKTLEN = MAX_PACKET_LEN;
}
void radioMacEventHandler( uint8 event) {
if(radio_tx_available){
radioMacTx( tx_packet );
LED_RED(1);
radio_tx_available = 0;
} else {
LED_RED(0);
}
}
void main( void ) {
uint8 PDATA i = 1; // counter
char DATA letter = ‘z’;
systemInit();
usbInit();
radioMacInit();
radioInitAddendum();
while(1){
boardService();
usbComService();
if( --i == 0 ) {
i = 100;
if( !radio_tx_available ){
if( usbComTxAvailable() > 1){
usbComTxSendByte( letter );
}
tx_packet[1] = letter;
tx_packet[0] = 1; // lenght of packet, excluding this byte
radio_tx_available = 1;
radioMacStrobe();
}
}
if( usbComRxAvailable() ) {
letter = usbComRxReceiveByte();
i = 1; //send the new character right away
} else {
delayMs(5);
}
}
}[/code]
And now the reciever code, which is crashing:
[code]/** Dependencies **************************************************************/
#include <radio_mac.h>
#include <board.h>
#include <cc2511_map.h>
#include <dma.h>
#include <radio_registers.h>
#include <usb.h>
#include <usb_com.h>
/** Global Variables *********************************/
#define MAX_TIMEOUT 50
#define MAX_PACKET_LEN 5
int32 CODE param_radio_channel = 128; // 0 - 255. Seperate by 2 channels to avoid crosstalk
uint8 XDATA rx_packet[MAX_PACKET_LEN + 4]; // room to store CRC
volatile uint8 DATA message_available = 0;
/** Functions *****************************************************************/
/* This function is declared in radio_mac.h, but needs to be defined here */
void radioMacEventHandler( uint8 event) {
if( event == RADIO_MAC_EVENT_RX){ //Packet recieved
message_available = 1;
LED_YELLOW_TOGGLE();
}
radioMacRx( rx_packet, MAX_TIMEOUT );
}
void main( void ) {
CHANNR = param_radio_channel;
PKTLEN = MAX_PACKET_LEN;
systemInit();
usbInit();
radioMacInit();
radioMacStrobe();
while(1){
boardService();
usbComService();
if( message_available && usbComTxAvailable() ){
usbComTxSendByte(rx_packet[1]);
message_available = 0;
}
}
}[/code]
Here’s my testing procedure:
I plug in the wixel with the reciever code, and wait two seconds. Then I plug in the wixel with the sender code. Then I count the toggles of the yellow LED on the reciever, to see how many messages it recieves before it crashes.
[/quote]