// Configures RF parameters before Enhanced Shockburst can be used. void configureRF() { packet_received = false; send_success = false; // Enable the radio clock RFCKEN = 1; // Set payload width to 32 bytes hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, PAYLOAD_SIZE); // Set auto-retries to 5 with 500 us intervals hal_nrf_set_auto_retr(5, 500); // Set pipe address hal_nrf_set_address(HAL_NRF_PIPE0, default_pipe_address); hal_nrf_set_address(HAL_NRF_TX, default_pipe_address); // Set initial channel hal_nrf_set_rf_channel(default_channels[1]); // Configure radio as primary receiver (PTX) hal_nrf_set_operation_mode(HAL_NRF_PRX); // Wait for the xtal to power up while (hal_clk_get_16m_source() != HAL_CLK_XOSC16M) ; // Power up radio hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Enable receiver CE_HIGH(); return; }
/** Initialized the RF configurations and powre up the RF. * Use this function to initialize RF configurations. * Note that the pipe isn't opened in this function, * please use "rf_rcv_pipe_config" after using this * function to configure RX pipe. * * @param in_channel RF Frequency (in_channel + 2400MHz) * @param in_datarate Data rate of the RF transmission. (1Mbps or 2Mbps) * @param in_output_power RF output power configuration. * @param in_auto_retr Enable auto retransmission or not. * @param in_auto_retr_delay Auto retransmission delay. * @param in_addr_width Address width configuration for both PTX and PRX pipe. * @param in_crc_mode CRC enable or disable configuration. * @param in_spi_clk_rate SPI clock rate. (SPI speed) * @param in_rf_int RF interrupt enable bit. */ void epl_rf_en_init(unsigned char in_channel, epl_rf_en_datarate_t in_datarate, char in_output_power, unsigned char in_auto_retr, unsigned int in_auto_retr_delay, char in_addr_width, epl_rf_en_crc_mode_t in_crc_mode, unsigned char in_rf_int) { RFCKEN = 1; // RF clock enable. CE_LOW(); //--- Default static setup. These setting is optimized to match the RF protocol with nRF24E1. ---// hal_nrf_close_pipe(HAL_NRF_ALL); // Close all pipes first. By default, pipe0 and pipe1 are opened. hal_nrf_set_datarate(in_datarate); hal_nrf_set_auto_retr(in_auto_retr, in_auto_retr_delay); // First parameter is set to zero indicating the auto retransmission is off. hal_nrf_set_output_power(in_output_power); // Maximum radio output power (0dbm). hal_nrf_set_crc_mode(in_crc_mode); hal_nrf_set_address_width(in_addr_width); // Both RX and TX's address width are Configured. hal_nrf_set_operation_mode(HAL_NRF_PTX); // Enter RF TX mode hal_nrf_set_rf_channel(in_channel); hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Power up radio hal_nrf_get_clear_irq_flags(); // IEN1 RF interrupt enable bit RF = in_rf_int; }
void radio_sb_init( hal_nrf_operation_mode_t operational_mode ) { if( !bus_initialized ) radio_bus_init(); switch( operational_mode ) { case HAL_NRF_PRX: radio_mode = DEVICE_PRX_SB; break; case HAL_NRF_PTX: radio_mode = DEVICE_PTX_SB; break; } hal_nrf_close_pipe(HAL_NRF_ALL); // First close all radio pipes // Pipe 0 and 1 open by default hal_nrf_open_pipe(HAL_NRF_PIPE0, false); // Open pipe0, without/autoack hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT); // Operates in 16bits CRC mode hal_nrf_set_auto_retr(0, RF_RETRANS_DELAY); // Disables auto retransmit hal_nrf_set_address_width(HAL_NRF_AW_5BYTES); // 5 bytes address width hal_nrf_set_address(HAL_NRF_TX, address); // Set device's addresses hal_nrf_set_address(HAL_NRF_PIPE0, address); // Sets recieving address on // pipe0 if(operational_mode == HAL_NRF_PTX) // Mode depentant settings { hal_nrf_set_operation_mode(HAL_NRF_PTX); // Enter TX mode } else { hal_nrf_set_operation_mode(HAL_NRF_PRX); // Enter RX mode hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH); // Pipe0 expect // PAYLOAD_LENGTH byte payload // PAYLOAD_LENGTH in radio.h } hal_nrf_set_rf_channel(RF_CHANNEL); // Operating on static channel // Defined in radio.h. // Frequenzy = // 2400 + RF_CHANNEL hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Power up device //hal_nrf_set_datarate(HAL_NRF_1MBPS); // Uncomment this line for // compatibility with nRF2401 // and nRF24E1 radio_wait(); radio_set_status (RF_IDLE); // Radio now ready }
void radio_esb_init( hal_nrf_operation_mode_t operational_mode ) { if( !bus_initialized ) radio_bus_init(); switch( operational_mode ) { case HAL_NRF_PRX: radio_mode = DEVICE_PRX_ESB; break; case HAL_NRF_PTX: radio_mode = DEVICE_PTX_ESB; break; } hal_nrf_close_pipe( HAL_NRF_ALL ); // First close all radio pipes // Pipe 0 and 1 open by default hal_nrf_open_pipe( HAL_NRF_PIPE0, true ); // Then open pipe0, w/autoack // Changed from sb/radio_sb.c hal_nrf_set_crc_mode( HAL_NRF_CRC_16BIT ); // Operates in 16bits CRC mode hal_nrf_set_auto_retr( RF_RETRANSMITS, RF_RETRANS_DELAY ); // Enables auto retransmit. // 3 retrans with 250ms delay // Changed from sb/radio_sb.c hal_nrf_set_address_width( HAL_NRF_AW_5BYTES ); // 5 bytes address width hal_nrf_set_address( HAL_NRF_TX, address ); // Set device's addresses hal_nrf_set_address( HAL_NRF_PIPE0, address ); // Sets recieving address on // pipe0 if( operational_mode == HAL_NRF_PTX ) // Mode depentant settings { hal_nrf_set_operation_mode( HAL_NRF_PTX ); // Enter TX mode } else { hal_nrf_set_operation_mode( HAL_NRF_PRX ); // Enter RX mode hal_nrf_set_rx_pload_width( (uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH ); // Pipe0 expect // PAYLOAD_LENGTH byte payload // PAYLOAD_LENGTH in radio.h } hal_nrf_set_rf_channel( RF_CHANNEL ); // Operating on static channel // Defined in radio.h. // Frequenzy = // 2400 + RF_CHANNEL hal_nrf_set_power_mode( HAL_NRF_PWR_UP ); // Power up device radio_wait(); radio_set_status( RF_IDLE ); // Radio now ready }
void radio_sb_init (const uint8_t *address, hal_nrf_operation_mode_t operational_mode) { hal_nrf_close_pipe(HAL_NRF_ALL); // First close all radio pipes // Pipe 0 and 1 open by default hal_nrf_open_pipe(HAL_NRF_PIPE0, FALSE); // Open pipe0, without/autoack hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT); // Operates in 16bits CRC mode hal_nrf_set_auto_retr(0, RF_RETRANS_DELAY); // Disables auto retransmit hal_nrf_set_address_width(HAL_NRF_AW_5BYTES); // 5 bytes address width hal_nrf_set_address(HAL_NRF_TX, address); // Set device's addresses hal_nrf_set_address(HAL_NRF_PIPE0, address); // Sets recieving address on // pipe0 if(operational_mode == HAL_NRF_PTX) // Mode depentant settings { hal_nrf_set_operation_mode(HAL_NRF_PTX); // Enter TX mode } else { hal_nrf_set_operation_mode(HAL_NRF_PRX); // Enter RX mode hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH); // Pipe0 expect // PAYLOAD_LENGTH byte payload // PAYLOAD_LENGTH in radio.h } hal_nrf_set_rf_channel(RF_CHANNEL); // Operating on static channel // Defined in radio.h. // Frequenzy = // 2400 + RF_CHANNEL hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Power up device hal_nrf_set_datarate(HAL_NRF_250KBPS); // Uncomment this line for // compatibility with nRF2401 // and nRF24E1 //hal_nrf_set_output_power(hal_nrf_output_power_t power); //default reset value is 0dbm // Wait for the radio to power up, max. 4.5ms depending on crystal Ls Timeout_SetTimeout2(5); while(!Timeout_IsTimeout2()); radio_set_status (RF_IDLE); // Radio now ready }
void init_radio() { // Enable the radio clock RFCKEN = 1; // Enable RF interrupt RF = 1; // Power up radio hal_nrf_set_power_mode(HAL_NRF_PWR_UP); hal_nrf_set_output_power(HAL_NRF_0DBM); hal_nrf_enable_ack_payload(1); hal_nrf_enable_dynamic_payload(1); hal_nrf_setup_dynamic_payload(1); // Set up PIPE 0 to handle dynamic lengths hal_nrf_set_rf_channel(125); // 2525 MHz hal_nrf_set_auto_retr(5, 250); // Retry 5x // Configure radio as primary receiver (PTX) hal_nrf_set_operation_mode(HAL_NRF_PTX); // Set payload width to 32 bytes // hal_nrf_set_rx_payload_width(HAL_NRF_PIPE0, MAXLENGTH); // Enable global interrupt EA = 1; }
// Resets RF parameters to default values. // Must be called before jumping to new firmware. void resetRF() { // Reset values set by the RF setup. CE_LOW(); // PWR_UP = 0 hal_nrf_set_power_mode(HAL_NRF_PWR_DOWN); // PRIM_RX = 0 hal_nrf_set_operation_mode(HAL_NRF_PTX); // RF_CH = 0x02; hal_nrf_set_rf_channel(reset_channel); // AW = 11 (Default = 5 bytes) // RX_ADDR_P0 = TX_ADDR = 0xE7E7E7E7E7 hal_nrf_set_address(HAL_NRF_TX, reset_pipe_address); hal_nrf_set_address(HAL_NRF_PIPE0, reset_pipe_address); // ARD = 0000, ARC = 0011 hal_nrf_set_auto_retr(3, 250); // RX_PW_P0 = 0x00 hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, 0); // Disable radio clock RFCKEN = 0; return; }
void radio_pl_init (const uint8_t *address, hal_nrf_operation_mode_t operational_mode) { hal_nrf_close_pipe(HAL_NRF_ALL); // First close all radio pipes // Pipe 0 and 1 open by default hal_nrf_open_pipe(HAL_NRF_PIPE0, true); // Then open pipe0, w/autoack hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT); // Operates in 16bits CRC mode hal_nrf_set_auto_retr(RF_RETRANSMITS, RF_RETRANS_DELAY); // Enables auto retransmit. // 3 retrans with 250ms delay hal_nrf_set_address_width(HAL_NRF_AW_5BYTES); // 5 bytes address width hal_nrf_set_address(HAL_NRF_TX, address); // Set device's addresses hal_nrf_set_address(HAL_NRF_PIPE0, address); // Sets recieving address on // pipe0 /***************************************************************************** * Changed from esb/radio_esb.c * * Enables: * * - ACK payload * * - Dynamic payload width * * - Dynamic ACK * *****************************************************************************/ hal_nrf_enable_ack_pl(); // Try to enable ack payload // When the features are locked, the FEATURE and DYNPD are read out 0x00 // even after we have tried to enable ack payload. This mean that we need to // activate the features. if(hal_nrf_read_reg(FEATURE) == 0x00 && (hal_nrf_read_reg(DYNPD) == 0x00)) { hal_nrf_lock_unlock (); // Activate features hal_nrf_enable_ack_pl(); // Enables payload in ack } hal_nrf_enable_dynamic_pl(); // Enables dynamic payload hal_nrf_setup_dyn_pl(ALL_PIPES); // Sets up dynamic payload on // all data pipes. /***************************************************************************** * End changes from esb/radio_esb.c * *****************************************************************************/ if(operational_mode == HAL_NRF_PTX) // Mode depentant settings { hal_nrf_set_operation_mode(HAL_NRF_PTX); // Enter TX mode } else { hal_nrf_set_operation_mode(HAL_NRF_PRX); // Enter RX mode hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH); // Pipe0 expect // PAYLOAD_LENGTH byte payload // PAYLOAD_LENGTH in radio.h } hal_nrf_set_rf_channel(RF_CHANNEL); // Operating on static channel // Defined in radio.h. // Frequenzy = // 2400 + RF_CHANNEL hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Power up device start_timer(RF_POWER_UP_DELAY); // Wait for the radio to wait_for_timer(); // power up radio_set_status (RF_IDLE); // Radio now ready }