This example monitors for data and writes the first byte (byte 0) of the received payloads to P0.
The example shows the minimum required setup for receiving packets from a primary transmitter (PTX) device.
The following default radio parameters are being used:
The project Enhanced ShockBurst Primary Transmitter (PTX) example can be used as a counterpart for transmitting the data.
Functions | |
| void | main () |
| NRF_ISR () | |
Variables | |
| uint8_t | payload [3] |
| void main | ( | void | ) |
Definition at line 56 of file main.c.
{
#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 = 0x10;
#endif
// Set P0 as output
P0DIR = 0;
// Enable the radio clock
RFCKEN = 1;
// Enable RF interrupt
RF = 1;
// Enable global interrupt
EA = 1;
// Configure radio as primary receiver (PTX)
hal_nrf_set_operation_mode(HAL_NRF_PRX);
// Set payload width to 3 bytes
hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, 3);
// Power up radio
hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
// Enable receiver
CE_HIGH();
for(;;){}
}
| NRF_ISR | ( | ) |
Definition at line 97 of file main.c.
{
uint8_t irq_flags;
// Read and clear IRQ flags from radio
irq_flags = hal_nrf_get_clear_irq_flags();
// If data received
if((irq_flags & (1<<(uint8_t)HAL_NRF_RX_DR)) > 0)
{
// Read payload
while(!hal_nrf_rx_fifo_empty())
{
hal_nrf_read_rx_payload(payload);
}
// Write received payload[0] to port 0
P0 = payload[0];
}
}
1.7.2