Not being lazy here, but maybe you could save me just a little time with your expertise? I’m the guy who started that “Radio Reliability” thread.
I just want to TRY the approach of setting up an interrupt to handle receiving radio messages, if for no other reason than to see if I can make it more immune to other CPU activity, or interrupts related to the USB. Maybe it won’t help, but I’d like to try. Could you just tell me if I’m on the right track here? Also, I know its hard in C, but do you have any feel for how much code can actually be in an ISR, other than just to keep it short? This is not complete code, and some of it is modified from radio_test_rx. Obviously it not working or I wouldn’t be asking, but maybe you can help me get to first base?
// 1. Initialization of DMA, with IRQ mask set
#define RADIO_PACKET_SIZE 16
static volatile XDATA uint8 packet[1 + RADIO_PACKET_SIZE + 2 ];
void init ()
{
radioRegistersInit();
CHANNR = 128; // or whatever
PKTLEN = RADIO_PACKET_SIZE;
MCSM0 = 0x14; // Auto-calibrate when going from idle to RX or TX.
MCSM1 = 0x00; // Disable CCA. After RX, go to IDLE.
dmaConfig.radio.SRCADDRH = XDATA_SFR_ADDRESS(RFD) >> 8;
dmaConfig.radio.SRCADDRL = XDATA_SFR_ADDRESS(RFD);
dmaConfig.radio.DESTADDRH = (unsigned int)packet >> 8;
dmaConfig.radio.DESTADDRL = (unsigned int)packet;
dmaConfig.radio.LENL = 1 + RADIO_PACKET_SIZE + 2;
dmaConfig.radio.VLEN_LENH = 0b10000000; // Transfer length is FirstByte+3
// DC7 Bits 7:6 are SRCINC, 5:4 are DESTINC, 3 is IRQMASK, 2 is M8, 1:0 are PRIORITY.
// I'm trying a higher priority, and enabling the interrupt
dmaConfig.radio.DC7 = 0x19; // SRCINC = 0, DESTINC = 1, IRQMASK = 1 M8 = 0, PRIORITY = 1
DMAIF =1; // enable DMA transfer complete SFR
DMAIRQ &= ~(1<<DMA_CHANNEL_RADIO); // Clear any pending radio DMA interrupt
MAARM |= (1<<DMA_CHANNEL_RADIO); // Arm DMA channel
RFST = 2; // Switch radio to RX mode.
}
/* Have an interrupt ready to do something useful, and clear the interrupt
(By the way, if you use "DMA_VECTOR" for the 1st macro element, it gets expanded
to DMA_VECTOR_VECTOR, which obviously won't work)
*/
ISR(DMA, 0) // macro to set up interrupt, from cc2511_map.h
{
// do something useful with data in packet.
if (radioCrcPassed())
{
LED_RED_TOGGLE(); // toggel red each time I get a good packet
. . .
}
DMAIRQ &= ~(1<<DMA_CHANNEL_RADIO); // Clear radio DMA interrupt
}