//powers up the 24L01 with all necessary delays
//this function takes the existing contents of the CONFIG register and sets the PWR_UP 
//the argument rx_active_mode is only used if the user is setting up the
//  24L01 as a receiver.  If the argument is false, the receiver will remain in
//  standby mode and not monitor for packets.  If the argument is true, the CE
//  pin will be set and the 24L01 will monitor for packets.  In TX mode, the value
//  of this argument is insignificant.
//note: if the read value of the CONFIG register already has the PWR_UP bit set, this function
//  exits in order to not make an unecessary register write.
void nrf24l01_power_up(bool rx_active_mode)
{
	unsigned char config;
	
	nrf24l01_read_register(nrf24l01_CONFIG, &config, 1);
	
	if((config & nrf24l01_CONFIG_PWR_UP) != 0)
		return;
		
	config |= nrf24l01_CONFIG_PWR_UP;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);
	
	delay_us(1500);
	
	if((config & nrf24l01_CONFIG_PRIM_RX) == 0)
		nrf24l01_clear_ce();
	else
	{
		if(rx_active_mode != false)
			nrf24l01_set_ce();
		else
			nrf24l01_clear_ce();
	}
}
//powers down the 24L01
//this function allows the user to set the contents of the CONFIG register, but the function
//  clears the PWR_UP bit in the CONFIG register, so the user does not need to.
void nrf24l01_power_down_param(unsigned char config)
{
	config &= (~nrf24l01_CONFIG_PWR_UP);
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	nrf24l01_clear_ce();
}
//executes the R_RX_PAYLOAD instruction
//unsigned char * data is the actual payload that has been received by the nrf24l01.
//	The user must size data according to the payload width specified to the nrf24l01.
//	This variable is filled by this function, so individual byte values need not be
//	initialized by the user.
//unsigned int len is the length of the payload being clocked out of the nrf24l01 (this
//	should be sized according to the payload length specified to the nrf24l01).
//returns the value of the STATUS register
unsigned char nrf24l01_read_rx_payload(unsigned char * data, unsigned int len)
{
	unsigned char status;
	
	nrf24l01_clear_ce();
	status = nrf24l01_execute_command(nrf24l01_R_RX_PAYLOAD, data, len, true);
	nrf24l01_set_ce();
	
	return status;
}
Esempio n. 4
0
//powers up the 24L01 with all necessary delays
//this function allows the user to set the contents of the CONFIG register, but the function
//  sets the PWR_UP bit in the CONFIG register, so the user does not need to.
//the argument rx_active_mode is only used if the user is setting up the
//  24L01 as a receiver.  If the argument is false, the receiver will remain in
//  standby mode and not monitor for packets.  If the argument is true, the CE
//  pin will be set and the 24L01 will monitor for packets.  In TX mode, the value
//  of this argument is insignificant.
void nrf24l01_power_up_param(bool rx_active_mode, unsigned char config)
{
	
	config |= nrf24l01_CONFIG_PWR_UP;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	Delay_US(1500);

	if((config & nrf24l01_CONFIG_PRIM_RX) == 0)
		nrf24l01_clear_ce();
	else
	{
		if(rx_active_mode != false)
			nrf24l01_set_ce();
		else
			nrf24l01_clear_ce();
	}
}
//sets up the 24L01 as a transmitter
//this function takes the existing contents of the CONFIG register and simply
//  clears the PRIM_RX bit in the CONFIG register.
//note: if the read value of the CONFIG register already has the PRIM_RX bit cleared, this 
//  function exits in order to not make an unecessary register write.
void nrf24l01_set_as_tx()
{
	unsigned char config;
	
	nrf24l01_read_register(nrf24l01_CONFIG, &config, 1);
	
	if((config & nrf24l01_CONFIG_PRIM_RX) == 0)
		return;
	
	config &= (~nrf24l01_CONFIG_PRIM_RX);
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	nrf24l01_clear_ce();
}
//powers down the 24L01
//this function takes the existing contents of the CONFIG register and simply
//  clears the PWR_UP bit in the CONFIG register.
//note: if the read value of the CONFIG register already has the PWR_UP bit cleared, this 
//  function exits in order to not make an unecessary register write.
void nrf24l01_power_down()
{
	unsigned char config;
	
	nrf24l01_read_register(nrf24l01_CONFIG, &config, 1);
	
	if((config & nrf24l01_CONFIG_PWR_UP) == 0)
		return;
	
	config &= (~nrf24l01_CONFIG_PWR_UP);
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	nrf24l01_clear_ce();
}
//sets up the 24L01 as a receiver with all necessary delays
//this function takes the existing contents of the CONFIG register and sets the PRIM_RX 
//  bit in the CONFIG register.
//if the argument rx_active_mode is false, the receiver will remain in standby mode
//  and not monitor for packets.  If the argument is true, the CE pin will be set 
//  and the 24L01 will monitor for packets.
//note: if the read value of the CONFIG register already has the PRIM_RX bit set, this function
//  exits in order to not make an unecessary register write.
void nrf24l01_set_as_rx(bool rx_active_mode)
{
	unsigned char config;
	unsigned char status;
	
	status = nrf24l01_read_register(0, &config, 1);

	if((config & nrf24l01_CONFIG_PRIM_RX) != 0)
		return;

	config |= nrf24l01_CONFIG_PRIM_RX;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	if(rx_active_mode != false)
		nrf24l01_set_ce();
	else
		nrf24l01_clear_ce();
}
//transmits the current tx payload
void nrf24l01_transmit()
{
	nrf24l01_set_ce();
	delay_us(10);
	nrf24l01_clear_ce();
}
//takes a 24L01 that is already in active RX mode and puts it in RX standy mode
void nrf24l01_rx_active_to_standby()
{
	nrf24l01_clear_ce();
}
Esempio n. 10
0
//transmits the current tx payload
void nrf24l01_transmit()
{
	nrf24l01_set_ce();
	Delay_US(10);
	nrf24l01_clear_ce();
}