Beispiel #1
0
///Enables / Disables auctomatic packet acknowledgement for the givent pipe.
///By default all pipes have this feature turned on.
extern void	NRF24L01_set_autoack_pipe(uint8_t pipe, uint8_t state)
{
	uint8_t auto_ack_pipes = NRF24L01_LOW_get_register(NRF24L01_REG_EN_AA);
	auto_ack_pipes &= ~(1<<pipe);
	auto_ack_pipes |= (1<<pipe);
	NRF24L01_LOW_set_register(NRF24L01_REG_EN_AA, auto_ack_pipes);
}
Beispiel #2
0
///Enables the dynamic acknowledge feature. This feature allows single packets to
///contain a 'do not acknowledge' flag. The receiver will then not send an automatic 
///acknowledgment for this packet.
extern void NRF24L01_enable_dyn_ack(uint8_t enable)
{
	uint8_t features = NRF24L01_LOW_get_register(NRF24L01_REG_FEATURE);
	features &= ~NRF24L01_MASK_FEATURE_EN_DYN_ACK;
	features |= NRF24L01_MASK_FEATURE_EN_DYN_ACK & (enable ? TRUE : FALSE);
	NRF24L01_LOW_set_register(NRF24L01_REG_FEATURE, features);
}
Beispiel #3
0
///Enables the acknowledge payload feature. Should only be used with dynamic
///payload size. Otherwise ack payloads my be discarded by the receiver
extern void NRF24L01_enable_ack_pld(uint8_t enable)
{
	uint8_t features = NRF24L01_LOW_get_register(NRF24L01_REG_FEATURE);
	features &= ~NRF24L01_MASK_FEATURE_EN_ACK_PAY;
	features |= NRF24L01_MASK_FEATURE_EN_ACK_PAY & ((enable ? TRUE : FALSE) << 1);
	NRF24L01_LOW_set_register(NRF24L01_REG_FEATURE, features);
}
Beispiel #4
0
///Enables the dynamic payload feature.
extern void NRF24L01_enable_dyn_pld(uint8_t enable)
{
	uint8_t features = NRF24L01_LOW_get_register(NRF24L01_REG_FEATURE);
	features &= ~NRF24L01_MASK_FEATURE_EN_DPL;
	features |= NRF24L01_MASK_FEATURE_EN_DPL & ((enable ? TRUE : FALSE) << 2);
	NRF24L01_LOW_set_register(NRF24L01_REG_FEATURE, features);
}
Beispiel #5
0
extern void NRF24L01_set_tx_pwr(uint8_t tx_pwr)
{
	nrf24l01_rf_setup_t* rf_setup = malloc(sizeof(nrf24l01_rf_setup_t));
	rf_setup->value = NRF24L01_LOW_get_register(NRF24L01_REG_RF_SETUP);
	rf_setup->rf_pwr = tx_pwr;
	NRF24L01_LOW_set_register(NRF24L01_REG_RF_SETUP, rf_setup->value);
	free(rf_setup);
}
Beispiel #6
0
///Puts the NRF24L01 into transmit mode
void NRF24L01_set_tx(void)
{
	uint8_t config = NRF24L01_LOW_get_register(NRF24L01_REG_CONFIG);
	config &= ~NRF24L01_MASK_CONFIG_PRIM_RX;
	config |= NRF24L01_MASK_CONFIG_PWR_UP;
	config &= NRF24L01_MASK_CONFIG;
	NRF24L01_LOW_set_register(NRF24L01_REG_CONFIG, config);
}
Beispiel #7
0
///Reads fifo status and returns if rx fifo is not empty
extern uint8_t NRF24L01_data_ready(void)
{
	uint8_t fifo_status = NRF24L01_LOW_get_register(NRF24L01_REG_FIFO_STATUS);
	if((fifo_status & NRF24L01_MASK_FIFO_STATUS_RX_EMPTY) == 0)
		return TRUE;
	else
		return FALSE;
}
Beispiel #8
0
///Sets the tx power of the NRF24L01
///Must be inside range [0 .. 3]
///0 = -18 dBm -> 0.016 mW
///1 = -12 dBm -> 0.063 mW
///2 = - 6 dBm -> 0.251 mW
///3 =   0 dBm -> 1.000 mW
extern void NRF24L01_set_tx_pwr(uint8_t tx_pwr)
{
	uint8_t rf_setup = NRF24L01_LOW_get_register(NRF24L01_REG_RF_SETUP);
	rf_setup &= ~NRF24L01_MASK_RF_SETUP_RF_PWR;
	rf_setup |= (tx_pwr << 1) & NRF24L01_MASK_RF_SETUP_RF_PWR;
	rf_setup &= NRF24L01_MASK_RF_SETUP;
	NRF24L01_LOW_set_register(NRF24L01_REG_RF_SETUP, rf_setup);
}
Beispiel #9
0
///Enables / Disables single data pipes. By default pipe 0 and pipe 1 are enabled
void NRF24L01_enable_pipe(uint8_t pipe, uint8_t state)
{
	uint8_t pipes = NRF24L01_LOW_get_register(NRF24L01_REG_EN_RXADDR);
	if(state)
		pipes |= (1<<pipe);
	else
		pipes &= ~(1<<pipe);
	NRF24L01_LOW_set_register(NRF24L01_REG_EN_RXADDR, pipes);
}
Beispiel #10
0
///Enables the dynamic payload feature for the given pipe.
///Overrides the payload width setting for the pipe.
extern void NRF24L01_enable_dyn_pld_pipe(uint8_t pipe, uint8_t state)
{
	uint8_t dynpld_pipes = NRF24L01_LOW_get_register(NRF24L01_REG_DYNPD);
	if(state)
	dynpld_pipes |= (1 << pipe);
	else
	dynpld_pipes &= ~(1 << pipe);
	NRF24L01_LOW_set_register(NRF24L01_REG_DYNPD, dynpld_pipes);
}
Beispiel #11
0
void NRF24L01_set_tx(void)
{
	nrf24l01_config_t* config = malloc(sizeof(nrf24l01_config_t));
	config->value = NRF24L01_LOW_get_register(NRF24L01_REG_CONFIG);
	config->prim_rx = 0;
	config->pwr_up = 1;
	config->reserved = 0;
	NRF24L01_LOW_set_register(NRF24L01_REG_CONFIG, config->value);
	free(config);
}