void radio_send_packet( uint8_t* packet, uint8_t length ) { // trans. in progress; RF_BUSY radio_set_status( RF_BUSY ); // load message into radio switch( radio_mode ) { case DEVICE_PRX_PL: hal_nrf_write_ack_pload( 0, packet, length ); break; case DEVICE_PTX_PL: hal_nrf_write_tx_pload( packet, length ); break; case DEVICE_PRX_SB: break; case DEVICE_PTX_SB: break; case DEVICE_PRX_ESB: break; case DEVICE_PTX_ESB: break; } //hal_nrf_write_tx_pload( packet, length ); // send packet chip_enable_pulse(); // Set back to idle radio_set_status( RF_IDLE ); }
void radio_send_packet(uint8_t *packet, uint8_t length) { hal_nrf_write_tx_pload(packet, length); // load message into radio CE_PULSE(); // send packet radio_set_status (RF_BUSY); // trans. in progress; RF_BUSY }
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_irq(void) { if (RADIO_ACTIVITY()) // Check if an interupt is { // triggered switch(hal_nrf_get_clear_irq_flags ()) { case (1<<HAL_NRF_MAX_RT): // Max retries reached hal_nrf_flush_tx(); // flush tx fifo, avoid fifo jam radio_set_status (RF_MAX_RT); break; case (1<<HAL_NRF_TX_DS): // Packet sent radio_set_status (RF_TX_DS); break; case (1<<HAL_NRF_RX_DR): // Packet received while (!hal_nrf_rx_fifo_empty ()) { hal_nrf_read_rx_pload(pload); } radio_set_status (RF_RX_DR); break; case ((1<<HAL_NRF_RX_DR)|(1<<HAL_NRF_TX_DS)): // Ack payload recieved while (!hal_nrf_rx_fifo_empty ()) { hal_nrf_read_rx_pload(pload); } radio_set_status (RF_TX_AP); break; default: break; } RESET_RADIO_ACTIVITY(); } }
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 device_prx_mode_esb(void) { CE_HIGH(); // Set Chip Enable (CE) pin high to enable reciever while(true) { start_timer(110); // Run until either 110ms has lapsed // OR there is data on the radio do { radio_irq (); } while ((radio_get_status () == RF_IDLE) && !timer_done()); if ((radio_get_status ()) == RF_RX_DR) { // Get the payload from the PTX and set LED1 if (radio_get_pload_byte (0) == 1) { LED1_ON(); } else { LED1_OFF(); } } else { LED1_OFF(); } // Set radio status to idle radio_set_status (RF_IDLE); } }
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 }