For some reason, it seems that I am not able to send any raw data with the BLE radio. I am able to configure the radio and start it successfully. However, the radio never transmits anything and therefore the software get stuck while it is waiting for an end event.
I found similar issue about four years ago, but it seems that the transmit function is similar. As a consequence, it is also possible that the issue is related to the configuration of the radio. I am using nRF5 (16.0.0) + SES + nRF52 DK.
#include <stdint.h>
#include <string.h>
#include "nrf_delay.h"
#include "nrf.h"
#include "nrf_gpio.h"
#define LED_1 17
#define LED_2 18
#define LED_3 19
#define LED_4 20
#define LED_ON 0
#define LED_OFF 1
void ett_led_init (void)
{
nrf_gpio_range_cfg_output(LED_1,LED_4);
nrf_gpio_pin_write(LED_1, LED_OFF);
nrf_gpio_pin_write(LED_2, LED_OFF);
nrf_gpio_pin_write(LED_3, LED_OFF);
nrf_gpio_pin_write(LED_4, LED_OFF);
}
void ett_led (uint8_t led_id,uint8_t state)
{
nrf_gpio_pin_write(led_id,state);
}
// Start HFCLK, it is needed by the radio!
void ett_system_init (void)
{
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { }
}
// Minimal settings, apply default values when possible!
void ett_radio_init (uint32_t * packet_ptr)
{
NRF_RADIO->PACKETPTR = packet_ptr; // Payload only
NRF_RADIO->MODE = 0x00000003; // BLE 1 Mbps
NRF_RADIO->PCNF1 = 0x0C; // The maximum length of the payload is 12 bytes
NRF_RADIO->BASE0 = 0x8E89BED6; // BLE advertising
NRF_RADIO->BASE1 = 0x8E89BED6; // BLE advertising
NRF_RADIO->TASKS_START = 1; // Start the radio
}
void ett_radio_transmit ()
{
NRF_RADIO->EVENTS_READY = 0; // Clear the event
NRF_RADIO->TASKS_TXEN = 1; // Enable the TX
while (NRF_RADIO->EVENTS_READY == 0) { } // Wait until the ready
NRF_RADIO->EVENTS_READY = 1; // Clear the event
ett_led(LED_2,LED_ON); // Turn ON led 2
NRF_RADIO->EVENTS_END = 0; // Clear the event
NRF_RADIO->TASKS_START = 1; // Start the TX
while (NRF_RADIO->EVENTS_END == 0) { } // Wait until the end
NRF_RADIO->EVENTS_END = 0; // Clear the event
ett_led(LED_3,LED_ON); // Turn ON led 3
NRF_RADIO->EVENTS_DISABLED = 0; // Clear the event
NRF_RADIO->TASKS_DISABLE = 1; // Disable the TX
while (NRF_RADIO->EVENTS_DISABLED == 0) { } // Wait until the disabled
NRF_RADIO->EVENTS_DISABLED = 0; // Clear the event
ett_led(LED_4,LED_ON); // Turn ON led 4
}
int main (void)
{
// Some advertising data with environmental sensing
uint32_t packet [3] = {0x02010003,
0x031A1803,
0xFF09C400};
ett_led_init(); // init the leds of nRF52 DK
ett_system_init(); // Start the HF clock
ett_radio_init(packet); // Init and start the radio
ett_led(LED_1,LED_ON); // Turn ON led 1
while (1) {
nrf_delay_ms(1000);
ett_radio_transmit(); // Transmit BLE packet
ett_led(LED_2,LED_ON); // Turn ON led 2
nrf_delay_ms(1000);
ett_led(LED_2,LED_OFF);
ett_led(LED_3,LED_OFF);
ett_led(LED_4,LED_OFF);
}
return 0;
}
I have created as minimal program as possible to recreate the issue. After the program has been started, leds 1 and 2 are turned on, which indicate that the configuration has been finished and the radio has been started successfully. However, the program gets stuck at line 71, because it keeps waiting for an end event, which never occurs.
If anyone has a working example how to send raw data with the BLE, please let me know.
Regards Sami