Esempio n. 1
0
/*******************************************************************************
 * Reads an array of bytes from the given start position in the MiRF registers *
 ******************************************************************************/
void mirf_read_register(uint8_t reg, uint8_t * value, uint8_t len)
{
    mirf_CSN_lo;
    spi_fast_shift(R_REGISTER | (REGISTER_MASK & reg));
    spi_transfer_sync(value,value,len);
    mirf_CSN_hi;
}
Esempio n. 2
0
void NRF24L01_LOW_read_register(uint8_t regaddr, uint8_t* data, uint8_t len)
{
	NRF24L01_CSN_LOW;
	spi_fast_shift(NRF24L01_CMD_R_REGISTER | regaddr);
	spi_transfer_sync(data, data, len);
	NRF24L01_CSN_HIGH;
}
Esempio n. 3
0
/*******************************************************************************
 * Reads mirf_PAYLOAD bytes into data array                                    *
 ******************************************************************************/
extern void mirf_get_data(uint8_t * data)
{
    mirf_CSN_lo;								// Pull down chip select
    spi_fast_shift(R_RX_PAYLOAD);				// Send cmd to read rx payload
    spi_transfer_sync(data,data,mirf_PAYLOAD);	// Read payload
    mirf_CSN_hi;								// Pull up chip select
    mirf_config_register(STATUS,(1<<RX_DR));	// Reset status register
}
Esempio n. 4
0
void mirf_read_register(uint8_t reg, uint8_t * value, uint8_t len)
// Reads an array of bytes from the given start position in the MiRF registers.
{
    mirf_CSN_lo;
    spi_fast_shift(R_REGISTER | (REGISTER_MASK & reg));
    spi_transfer_sync(value,value,len);
    mirf_CSN_hi;
}
Esempio n. 5
0
void nrf_read_register(uint8_t reg, uint8_t * value, uint8_t len)
// Reads an array of bytes from the given start position in the NRF24L01+ registers.
{
    CSN_LOW     // ISP Slave on
    spi_fast_shift(R_REGISTER | (REGISTER_MASK & reg));
    spi_transfer_sync(value,value,len);
    CSN_HIGH    // ISP Slave off
}
Esempio n. 6
0
extern void NRF24L01_get_received_data(uint8_t* data, uint8_t len)
{
	NRF24L01_CSN_LOW;
	spi_fast_shift(NRF24L01_CMD_R_RX_PAYLOAD);
	spi_transfer_sync(data, data, len);
	NRF24L01_CSN_HIGH;
	NRF24L01_LOW_set_register(NRF24L01_REG_STATUS, NRF24L01_MASK_STATUS_RX_DR);
}
Esempio n. 7
0
/* Read data from radio.
   Since more than one radio could be present in a channel, this function check Node_Number to see if the
   Package belong to this node, if does, it update the Global DATA variables and return 1, 
   if not it retransmit the package and return 0. 
*/
uint8_t nrf_read_payload(void) 

{
	
    uint8_t ReturnFlag  = 0;

    CSN_LOW                    // Pull down chip select
    spi_fast_shift( R_RX_PAYLOAD ); // Send Read Payload Command
    spi_transfer_sync(buffer,buffer, PAYLOAD_WIDTH);   // Read payload
    CSN_HIGH                    // Pull up chip select
	
	// clear status register flag IRQ, write 1 to clear bit.
	nrf_config_register(STATUS,(1<<RX_DR) | (1<<TX_DS) | (1<<MAX_RT)); 
	
	
	// Verify the the Received Node Number before accepting the data.

	if (NODE_NUMBER == buffer[5]){
		DATA0 = buffer[0];
		DATA1 = buffer[1];
		DATA2 = buffer[2];
		DATA3 = buffer[3];
		RECV_MSGID = buffer[4];
        ReturnFlag = 1;
	}
	// Else forward the message	
	else {
		// short delay to avoid collitions		
		_delay_loop_2(NODE_NUMBER * 100);

		// configure radio in TX
		nrf_tx_config();

		// send package
		nrf_send(buffer);

		// configure radio as rx again.
		nrf_rx_config();

	}


// Return 1 if received packaged pertained to this node, else return 0.
    return ReturnFlag;
}
Esempio n. 8
0
// Read Configuration data package and save data in eeprom
void nrf_read_cfg_payload(void) 

{
		uint8_t data_input[CFG_PAYLOAD_WIDTH];
		uint8_t trash_out[CFG_PAYLOAD_WIDTH];
	
	
    CSN_LOW                    // Pull down chip select
    spi_fast_shift( R_RX_PAYLOAD ); // Send Read Payload Command
    spi_transfer_sync(trash_out,data_input, CFG_PAYLOAD_WIDTH);   // Read payload
    CSN_HIGH                    // Pull up chip select
	
	// save received data in eeprom
	remote_cfg_toEEPROM(data_input);
	
	// clear status register flag IRQ, write 1 to clear bit.
	nrf_config_register(STATUS,(1<<RX_DR) | (1<<TX_DS) | (1<<MAX_RT)); 
}
Esempio n. 9
0
void nrf_read_cfg_payload(void) 
// Sends a data package to the default address. Be sure to send the correct
// amount of bytes as configured as payload on the receiver.
{
		uint8_t data_input[CFG_PAYLOAD_WIDTH];
		uint8_t trash_out[CFG_PAYLOAD_WIDTH];
	
	
    CSN_LOW                    // Pull down chip select
    spi_fast_shift( R_RX_PAYLOAD ); // Send Read Payload Command
    spi_transfer_sync(trash_out,data_input, CFG_PAYLOAD_WIDTH);   // Read payload
    CSN_HIGH                    // Pull up chip select
	
	// save received data in eeprom
	remote_cfg_toEEPROM(data_input);
	
	// clear status register flag IRQ, write 1 to clear bit.
	nrf_config_register(STATUS,(1<<RX_DR) | (1<<TX_DS) | (1<<MAX_RT)); 
}