hi,guys For testing the comunication between BLE+timeslot device and radio device, I change the code as below:
void start_timer(void)
{
NRF_TIMER0->TASKS_STOP = 1;
NRF_TIMER0->MODE = TIMER_MODE_MODE_Timer; // Set the timer in TIMER Mode
NRF_TIMER0->TASKS_CLEAR = 1; // clear the task first to be usable for later
NRF_TIMER0->PRESCALER = 4; // Prescaler = 6 creates 250kHz tick frequency, i.e. tick frequency of 4us
NRF_TIMER0->BITMODE = TIMER_BITMODE_BITMODE_32Bit;//0x01UL; //Set counter to 16 bit resolution
NRF_TIMER0->CC[0] = 6000;
// Set and enable interrupt on Timer0
NRF_TIMER0->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
NVIC_EnableIRQ(TIMER0_IRQn);
NRF_TIMER0->TASKS_START = 1; // Start timer
}
static nrf_radio_request_t m_timeslot_request;
static uint32_t m_slot_length = 10000;
static uint8_t packet[] = {1};
static uint32_t slotimes;
nrf_radio_signal_callback_return_param_t * m_radio_callback(uint8_t signal_type)
{
switch(signal_type)
{
case NRF_RADIO_CALLBACK_SIGNAL_TYPE_START:
signal_callback_return_param.params.request.p_next = NULL;
signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_NONE;
radio_configure();
NRF_RADIO->POWER = 1;
start_timer();
//NVIC_SetPendingIRQ(SWI3_IRQn);
NRF_RADIO->INTENSET = RADIO_INTENSET_ADDRESS_Msk | RADIO_INTENSET_DISABLED_Msk | RADIO_INTENSET_READY_Msk;
/* Enable RADIO interrupts */
NVIC_ClearPendingIRQ(RADIO_IRQn);
NVIC_EnableIRQ(RADIO_IRQn);
NRF_RADIO->PACKETPTR = (uint32_t)&packet;
NRF_RADIO->EVENTS_READY = 0U;
NRF_RADIO->TASKS_TXEN = 1;
while (NRF_RADIO->EVENTS_READY == 0U)
{
}
NRF_RADIO->TASKS_START = 1U;
NRF_RADIO->EVENTS_END = 0U;
while (NRF_RADIO->EVENTS_END == 0U)
{
}
NRF_RADIO->EVENTS_DISABLED = 0U;
// Disable radio
NRF_RADIO->TASKS_DISABLE = 1U;
while (NRF_RADIO->EVENTS_DISABLED == 0U)
{
}
NRF_RADIO->POWER = 0;
break;
case NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0:
m_configure_normal_timeslot();
if(slotimes>20)
{
signal_callback_return_param.params.request.p_next = NULL;
signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_END;
}
else
{
signal_callback_return_param.params.request.p_next = &m_timeslot_request;
signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END; //End the current timeslot and request a new one
}
slotimes++;
NRF_TIMER0->TASKS_STOP = 1;
NRF_TIMER0->TASKS_CLEAR = 1;
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
break;
case NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO:
signal_callback_return_param.params.request.p_next = NULL;
signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_NONE;
break;
}
return (&signal_callback_return_param);
}
BLE+timeslot Device and radio receiver have the same radio config.:
void radio_configure()
{
// Radio config
NRF_RADIO->TXPOWER = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos);
NRF_RADIO->FREQUENCY = 7UL; // Frequency bin 7, 2407MHz
NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
// Radio address config
NRF_RADIO->PREFIX0 = 0xC4C3C2E7UL; // Prefix byte of addresses 3 to 0
NRF_RADIO->PREFIX1 = 0xC5C6C7C8UL; // Prefix byte of addresses 7 to 4
NRF_RADIO->BASE0 = 0xE7E7E7E7UL; // Base address for prefix 0
NRF_RADIO->BASE1 = 0x00C2C2C2UL; // Base address for prefix 1-7
NRF_RADIO->TXADDRESS = 0x00UL; // Set device address 0 to use when transmitting
NRF_RADIO->RXADDRESSES = 0x01UL; // Enable device address 0 to use which receiving
// Packet configuration
NRF_RADIO->PCNF0 = (PACKET0_S1_SIZE << RADIO_PCNF0_S1LEN_Pos) |
(PACKET0_S0_SIZE << RADIO_PCNF0_S0LEN_Pos) |
(PACKET0_PAYLOAD_SIZE << RADIO_PCNF0_LFLEN_Pos); //lint !e845 "The right argument to operator '|' is certain to be 0"
// Packet configuration
NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) |
(RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) |
(PACKET1_BASE_ADDRESS_LENGTH << RADIO_PCNF1_BALEN_Pos) |
(PACKET1_STATIC_LENGTH << RADIO_PCNF1_STATLEN_Pos) |
(PACKET1_PAYLOAD_SIZE << RADIO_PCNF1_MAXLEN_Pos); //lint !e845 "The right argument to operator '|' is certain to be 0"
// CRC Config
NRF_RADIO->CRCCNF = (RADIO_CRCCNF_LEN_Two << RADIO_CRCCNF_LEN_Pos); // Number of checksum bits
if ((NRF_RADIO->CRCCNF & RADIO_CRCCNF_LEN_Msk) == (RADIO_CRCCNF_LEN_Two << RADIO_CRCCNF_LEN_Pos))
{
NRF_RADIO->CRCINIT = 0xFFFFUL; // Initial value
NRF_RADIO->CRCPOLY = 0x11021UL; // CRC poly: x^16+x^12^x^5+1
}
else if ((NRF_RADIO->CRCCNF & RADIO_CRCCNF_LEN_Msk) == (RADIO_CRCCNF_LEN_One << RADIO_CRCCNF_LEN_Pos))
{
NRF_RADIO->CRCINIT = 0xFFUL; // Initial value
NRF_RADIO->CRCPOLY = 0x107UL; // CRC poly: x^8+x^2^x^1+1
}
nrf_delay_ms(3);
}
But the radio receiver can not receive data when debugging:
int main(void)
{
init();
while (true)
{
//NRF_RADIO->POWER = 1;
// Set payload pointer
NRF_RADIO->PACKETPTR = (uint32_t)packet;
NRF_RADIO->EVENTS_READY = 0U;
// Enable radio and wait for ready
NRF_RADIO->TASKS_RXEN = 1U;
while (NRF_RADIO->EVENTS_READY == 0U)
{
}
NRF_RADIO->EVENTS_END = 0U;
// Start listening and wait for address received event
NRF_RADIO->TASKS_START = 1U;
// Wait for end of packet
while (NRF_RADIO->EVENTS_END == 0U)
{
}
// Write received data to LED0 and LED1 on CRC match
if (NRF_RADIO->CRCSTATUS == 1U)
{
switch (packet[0])
{
case '0':
nrf_gpio_pin_set(LED_0);
nrf_gpio_pin_clear(LED_1);
break;
case '1':
nrf_gpio_pin_set(LED_1);
nrf_gpio_pin_clear(LED_0);
break;
}
}
NRF_RADIO->EVENTS_DISABLED = 0U;
// Disable radio
NRF_RADIO->TASKS_DISABLE = 1U;
while(NRF_RADIO->EVENTS_DISABLED == 0U)
{
}
}
}
and I'm sure timeslot is working ,cause the uart output just as below: