void init(void) { /* Start 16 MHz crystal oscillator */ NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; /* Wait for the external oscillator to start up */ while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { } // Set radio configuration parameters radio_configure(); simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC); // Set payload pointer //NRF_RADIO->PACKETPTR = (uint32_t)scan_rsp; //packet; // We will only announce on channel 37 for now int channel = 37; NRF_RADIO->DATAWHITEIV = channel & 0x3F; NRF_RADIO->FREQUENCY = ch2freq(channel); }
int16_t radio_recv(uint8_t channel, uint32_t aa, uint32_t crc, radio_recv_cb func, void *user_data) { uint16_t frequency; /* Configure callback */ recv_cb = func; cb_data = user_data; status = RADIO_RX; /* Set receive address */ NRF_RADIO->PREFIX0 = aa >> 24; NRF_RADIO->BASE0 = (aa & 0xFFFFFF) << 8; NRF_RADIO->RXADDRESSES = 0x00000001; /* Set frequency */ frequency = ch2freq(channel); if (frequency < 0) return -1; NRF_RADIO->FREQUENCY = (uint32_t) frequency; /* Set CRC and data whitening init values */ NRF_RADIO->CRCINIT = crc; NRF_RADIO->DATAWHITEIV = channel & 0x3F; /* Start RX ramp-up */ NRF_RADIO->TASKS_RXEN = 1UL; return 0; }
int16_t radio_prepare(uint8_t ch, uint32_t aa, uint32_t crcinit) { int8_t freq; if (!(status & STATUS_INITIALIZED)) return -ENOREADY; if (status & STATUS_BUSY) return -EBUSY; freq = ch2freq(ch); if (freq < 0) return -EINVAL; NRF_RADIO->DATAWHITEIV = ch & 0x3F; NRF_RADIO->FREQUENCY = freq; NRF_RADIO->BASE0 = (aa << 8) & 0xFFFFFF00; NRF_RADIO->PREFIX0 = (aa >> 24) & RADIO_PREFIX0_AP0_Msk; NRF_RADIO->CRCINIT = crcinit; return 0; }