This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to update the RADIO payload in nRF51822?

Hi, All!

I'm using nRF51822 to support custom protocol, and define array "packet[40]" for PACKETPTR. when "packet" is constant value, the radio tx is very stable; but when I update the "packet" with some variable, the radio looks like not very good. Could you help me, please?

This is my code for radio tx:

	uint8_t i, packet[40];
static uint16_t test = 1000;

/* update payload */
test++;
if (test >= 2000) test = 1000;	
for (i = 0; i < 40; i++) {
	if (i % 2 == 0) {
		packet[i] = (uint8_t)(test >> 8);
	} else {
		packet[i] = (uint8_t)(test >> 0);
	}
}

/* DISABLE radio */
NRF_RADIO->SHORTS = 0;
NRF_RADIO->EVENTS_DISABLED = 0;
NRF_RADIO->TASKS_DISABLE = 1;
while (NRF_RADIO->EVENTS_DISABLED == 0);
NRF_RADIO->EVENTS_DISABLED = 0;

/* set packet pointer */
NRF_RADIO->PACKETPTR = (uint32_t)packet;

/* wait for READY event */
NRF_RADIO->EVENTS_READY = 0U;
NRF_RADIO->TASKS_TXEN = 1;
while (NRF_RADIO->EVENTS_READY == 0U);

/* START radio and wait for END event */
NRF_RADIO->TASKS_START = 1U;
NRF_RADIO->EVENTS_END = 0U;
while(NRF_RADIO->EVENTS_END == 0U);

/* disable radio */
NRF_RADIO->EVENTS_DISABLED = 0U;
NRF_RADIO->TASKS_DISABLE = 1U;
while(NRF_RADIO->EVENTS_DISABLED == 0U);

Best Regards!

Related