///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // void rf_set_rf_channel(uint8_t channel) // // Description: // Sets the RF channel of the device (2400 MHz + (channel * 1 MHz)) // // Parameters: // uint8_t channel - new RF channel // // Return value: // None // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void rf_set_rf_channel(uint8_t channel) { if(channel <= RF_RF_CH_MAX_CHAN_NUM) { rf_write_register(RF_RF_CH, &channel, 1); } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // void rf_set_as_rx(bool rx_active_mode) // // Description: // Sets the device as an RX, giving the user the option to go into active or standby mode // // Parameters: // bool rx_active_mode - true to take to RX active mode (if RX), false otherwise // // Return value: // None // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void rf_set_as_rx(bool rx_active_mode) { unsigned char config; rf_read_register(RF_CONFIG, &config, 1); //Read the current CONFIG value //If the device is already configured as an RX, exit if((config & RF_CONFIG_PRIM_RX) != 0) { return; } //Set the PRIM_RX bit, then write the old value of CONFIG back to the device config |= RF_CONFIG_PRIM_RX; rf_write_register(RF_CONFIG, &config, 1); //Set the CE pin if active RX mode is requested, and clear it otherwise if(rx_active_mode != false) { rf_set_ce(); } else { rf_clear_ce(); } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // void rf_power_up_param(bool rx_active_mode, unsigned char config) // // Description: // Powers up the device, but allows the user to pass in the value sent to the CONFIG register, as well as whether or not to go to // RX active mode (if RX is desired) // // Parameters: // bool rx_active_mode - true to take to RX active mode (if RX), false otherwise // unsigned char config - value to be written to the CONFIG register (the PWR_UP bit will obviously be cleared) // // Return value: // None // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void rf_power_up_param(bool rx_active_mode, unsigned char config) { //Force the value of PWR_UP set in the passed in version of config, then write the value config |= RF_CONFIG_PWR_UP; rf_write_register(RF_CONFIG, &config, 1); delay_us(1); //Delay for power up //Operate CE based on whether RX standby/RX active/TX is requested if((config & RF_CONFIG_PRIM_RX) == 0) { rf_clear_ce(); //Clear CE for TX mode } else { //Set the CE pin if active RX mode is requested, and clear it otherwise if(rx_active_mode != false) { rf_set_ce(); } else { rf_clear_ce(); } } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // void rf_set_as_tx() // // Description: // Sets the device as a TX // // Parameters: // None // // Return value: // None // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void rf_set_as_tx() { uint8_t config; uint8_t ce_status = rf_get_ce(); rf_read_register(RF_CONFIG, &config, 1); //Read the current CONFIG value //If the device is already configured as a TX, exit if((config & RF_CONFIG_PRIM_RX) == 0) { return; } rf_clear_ce(); //Clear the CE pin to enter TX mode //Clear the PRIM_RX bit, then write the old value of CONFIG back to the device config &= (~RF_CONFIG_PRIM_RX); rf_write_register(RF_CONFIG, &config, 1); //Set the CE pin if it was set coming into this function if(ce_status) { rf_set_ce(); } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // void rf_set_rx_addr(unsigned char * address, unsigned int len, unsigned char rxpipenum) // // Description: // Sets the device's RX address on the specified pipe // // Parameters: // unsigned char * address - pointer to the address for the pipe // unsigned int len - number of bytes for the address // unsigned char rxpipenum - pipe number to which the address should be written // // Return value: // None // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void rf_set_rx_addr(unsigned char * address, unsigned int len, unsigned char rxpipenum) { //Do not allow writes to pipes that don't exist if(rxpipenum > 5) { return; } rf_write_register(RF_RX_ADDR_P0 + rxpipenum, address, len); //Write the requested address to the requested RX pipe }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // void rf_set_data_rate(uint8_t data_rate) // // Description: // Sets the data transmission rate of the device (250kbps, 1Mbps, 2Mbps) // // Parameters: // uint8_t power - new power level RF_RF_SETUP_RF_DR_[250_KBPS|1_MBPS|2_MBPS] // // Return value: // None // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void rf_set_data_rate(uint8_t data_rate) { if ((data_rate == RF_RF_SETUP_RF_DR_250_KBPS) || (data_rate == RF_RF_SETUP_RF_DR_1_MBPS) || (data_rate == RF_RF_SETUP_RF_DR_2_MBPS)) { uint8_t rf_setup = rf_read_register_1_byte(RF_RF_SETUP) & ~RF_RF_SETUP_RF_DR; rf_setup = (rf_setup & ~RF_RF_SETUP_RF_PWR) | data_rate; rf_write_register(RF_RF_SETUP, &rf_setup, 1); } }