This example sends packets continuously. The contents of P0 are sent in the first payload byte (byte 0).
The example shows the minimum required setup for transmitting packets to a primary receiver (PRX) device.
The following default radio parameters are being used:
The project Enhanced ShockBurst Primary Receiver (PRX) example can be used as a counterpart for receiving the data.
Functions | |
| void | main (void) |
| NRF_ISR () | |
| void main | ( | void | ) |
Definition at line 59 of file main.c.
{
uint8_t payload[3];
#ifdef MCU_NRF24LE1
while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M)
{
// Wait until 16 MHz crystal oscillator is running
}
#endif
#ifdef MCU_NRF24LU1P
// Enable radio SPI
RFCTL = 0x10U;
#endif
// Enable the radio clock
RFCKEN = 1U;
// Enable RF interrupt
RF = 1U;
// Enable global interrupt
EA = 1U;
// Power up radio
hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
for(;;)
{
// Put P0 contents in payload[0]
payload[0] = ~P0;
// Write payload to radio TX FIFO
hal_nrf_write_tx_payload(payload, 3U);
// Toggle radio CE signal to start transmission
CE_PULSE();
radio_busy = true;
// Wait for radio operation to finish
while (radio_busy)
{
}
}
}
| NRF_ISR | ( | ) |
Definition at line 107 of file main.c.
{
uint8_t irq_flags;
// Read and clear IRQ flags from radio
irq_flags = hal_nrf_get_clear_irq_flags();
switch(irq_flags)
{
// Transmission success
case (1 << (uint8_t)HAL_NRF_TX_DS):
radio_busy = false;
// Data has been sent
break;
// Transmission failed (maximum re-transmits)
case (1 << (uint8_t)HAL_NRF_MAX_RT):
// When a MAX_RT interrupt occurs the TX payload will not be removed from the TX FIFO.
// If the packet is to be discarded this must be done manually by flushing the TX FIFO.
// Alternatively, CE_PULSE() can be called re-starting transmission of the payload.
// (Will only be possible after the radio irq flags are cleared)
hal_nrf_flush_tx();
radio_busy = false;
break;
default:
break;
}
}
1.7.2