"Hello, I'm using NCS v2.4.2 with an nRF52840DK and attempting to configure a custom radio channel with frequencies like 2403MHz and 2405MHz.
I followed the provided instructions;
https://github.com/Simula-UiB/mesh-node/blob/main/net_core/src/radio.c
the link would be on BLE-Mesh, but I tried BLE with my configuration, which is given below.
radio configurations:/**
* @brief Start radio transmission
*/
int radio_send(uint8_t *data, size_t length)
{
int ret = 0;
/* Fill radio transmission buffer */
memcpy(rf_tx_buf + RF_BUFFER_PAYLOAD_OFFSET, data, length);
/* Set length */
rf_tx_buf[RF_BUFFER_LENGTH_OFFSET] = length + 1;
LOG_HEXDUMP_DBG(rf_tx_buf, length + 1, "Data TX");
/* Get radio state */
nrf_radio_state_t state = nrf_radio_state_get(NRF_RADIO);
switch (state)
{
case NRF_RADIO_STATE_RX:
/* Stop RX, trigger TXEN task from RXIDLE state */
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_STOP);
trigger_tx();
break;
case NRF_RADIO_STATE_RXIDLE:
case NRF_RADIO_STATE_DISABLED:
/* Radio already in compatible state, trigger TXEN task */
trigger_tx();
break;
case NRF_RADIO_STATE_TXIDLE:
nrf_radio_packetptr_set(NRF_RADIO, rf_tx_buf);
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_START);
break;
default:
/* Radio in incompatible state. Drop packet, for now */
LOG_ERR("TX Failed, incompatible state. State: %d", state);
ret = -EIO;
}
LOG_DBG("Finished TX");
return ret;
}
void trigger_tx()
{
nrf_radio_packetptr_set(NRF_RADIO, rf_tx_buf);
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_TXEN);
}
/**
* @brief Initialize BLE radio
*/
void init_radio()
{
LOG_INF("Initializing radio");
/* Set modulation and bitrate */
nrf_radio_mode_set(NRF_RADIO, NRF_RADIO_MODE_BLE_1MBIT); // NRF_RADIO_MODE_BLE_2MBIT
/* Enable fast ramp up, transmit center when idle */
nrf_radio_modecnf0_set(NRF_RADIO, true, RADIO_MODECNF0_DTX_Center);
/* Set channel */
nrf_radio_frequency_set(NRF_RADIO, 2426); // 2442 Mhz
/* Set radio transmission power */
nrf_radio_txpower_set(NRF_RADIO, TX_POWER);
/* Set packet config */
nrf_radio_packet_conf_t pkt_conf = {
.lflen = 8UL, // Length field length in bits
.s0len = 0UL,
.s1len = 0UL,
.s1incl = false,
.plen = NRF_RADIO_PREAMBLE_LENGTH_16BIT,
.crcinc = false, // CRC included in length field
.statlen = 0UL,
.balen = 4UL,
.big_endian = true,
.maxlen = MAX_MESSAGE_SIZE, // Max payload length
.whiteen = false // Packet whitening
};
nrf_radio_packet_configure(NRF_RADIO, &pkt_conf);
/* Address */
nrf_radio_base0_set(NRF_RADIO, 0xAAAAAAAAAA);
nrf_radio_prefix0_set(NRF_RADIO, 0x42U);
nrf_radio_txaddress_set(NRF_RADIO, 0x00U); // Transmit using logical address 0 (base0 and prefix0)
// nrf_radio_rxaddresses_set(NRF_RADIO, 0x01U); // Enable RX of logical address 0
/* CRC Config */
nrf_radio_crc_configure(NRF_RADIO,
2, // 2 byte CRC
NRF_RADIO_CRC_ADDR_INCLUDE,
0x1021); // Polynomial: x16 + x12 + x5 + 1
/* Shortcuts */
nrf_radio_shorts_enable(NRF_RADIO, NRF_RADIO_SHORT_READY_START_MASK); // Ready -> Start shortcut
}
main/**
* @brief Initialize power and clock peripherals
*/
static void init_power_clock(void)
{
nrfx_clock_init(NULL);
nrfx_power_init(NULL);
nrfx_clock_start(NRF_CLOCK_DOMAIN_HFCLK);
nrfx_clock_start(NRF_CLOCK_DOMAIN_LFCLK);
while (!(nrfx_clock_hfclk_is_running() &&
nrfx_clock_lfclk_is_running()))
{
/* Just waiting */
}
}
void main(void)
{
init_power_clock();
/* Radio init */
init_radio();
LOG_INF("Radio initialized");
uint8_t msg = 0xAA;
while (1)
{
radio_send(&msg, 1);
k_msleep(2000); // Allow logs time to flush
}
}
Despite the code running without issues, I'm not receiving any messages on nRF Sniffer when monitoring with Wireshark.
I also tried using the default channel index 38 (2426MHz), but I encountered the same issue of not receiving any messages.
Could you please review the configuration to identify any potential mistakes?"