Esempio n. 1
0
extern void nRF24L01_interrupt () 
{
    uint8_t status;   
    // If still in transmitting mode then finish transmission
    PORTD ^= 1<<0; //toggle bit
    if (PTX) {
    
        // Read nRF24L01 status 
        nRF24L01_CSN_lo;			// Pull down chip select
        status = spi_transmit_byte(NOP);	// Read status register
        nRF24L01_CSN_hi;			// Pull up chip select

    	nRF24L01_CSN_lo;			// Pull down chip select
    	spi_transmit_byte( FLUSH_TX );		// Write cmd to flush tx fifo
   	nRF24L01_CSN_hi;			// Pull up chip select

        nRF24L01_CE_lo;				// Deactivate transreceiver
        RX_POWERUP;                             // Power up in receiving mode
        nRF24L01_CE_hi;				// Listening for pakets
        PTX = 0;				// Set to receiving mode

        // Reset status register for further interaction
        nRF24L01_config_register(STATUS,(1<<TX_DS)|(1<<MAX_RT)); // Reset status register
    }
}
Esempio n. 2
0
void nRF24L01_config_register(uint8_t reg, uint8_t value)
// Clocks only one byte into the given nRF24L01 register
{
	nRF24L01_CSN_lo;
	spi_transmit_byte(W_REGISTER | (REGISTER_MASK & reg));
	spi_transmit_byte(value);
	nRF24L01_CSN_hi;
}
Esempio n. 3
0
//============================================================
void write_buffer(uint16_t BufferOffset,uint8_t data)
{			
	CLR_SS_AT45DB();		
	spi_transmit_byte(0x84);//84			  						
	spi_transmit_byte(0xff);						
	spi_transmit_byte((uint8_t)(BufferOffset>>8));	
	spi_transmit_byte((uint8_t)BufferOffset);		
	spi_transmit_byte(data);		
	SET_SS_AT45DB();	
}
Esempio n. 4
0
//================================================================
uint8_t read_buffer(uint16_t BufferOffset)
{		
    uint8_t temp;
	CLR_SS_AT45DB();
 	spi_transmit_byte(0xD4);//54
	spi_transmit_byte(0xff);
	spi_transmit_byte((uint8_t)(BufferOffset>>8));
	spi_transmit_byte((uint8_t)BufferOffset);
	spi_transmit_byte(0xff);
	spi_transmit_byte(0xff);
	temp=SPDR;	  
	SET_SS_AT45DB();
    return temp;								
}
Esempio n. 5
0
extern void nRF24L01_interrupt () 
{
        // Read nRF24L01 status 
	uint8_t status;
        nRF24L01_CSN_lo;			// Pull down chip select
        status = spi_transmit_byte(NOP);	// Read status register
        nRF24L01_CSN_hi;			// Pull up chip select
	
	//based upon the status register decide what to do


	//if TX sucess
	if ( status & (1<<TX_DS) )
	{
		nRF24L01_powerdown();		// Return to low power state
	}
	//maximum retrys reached
	else if ( status & (1<<MAX_RT) )
	{
		//set some flag
		nRF24L01_powerdown();		// Return to low power state
	}
	//recieved a packet
	else if ( status & (1<<RX_DR) )
	{
		nRF24L01_get_data(buffer);
		nRF24L01_powerdown();
	}


        // Reset status register for further interaction
        nRF24L01_config_register(STATUS,( (1<<RX_DR) | (1<<TX_DS) | (1<<MAX_RT) ) ); // Reset status register

}
Esempio n. 6
0
void nRF24L01_write_register(uint8_t reg, uint8_t * value, uint8_t len) 
// Writes an array of bytes into inte the nRF24L01 registers.
{
	nRF24L01_CSN_lo;
	spi_transmit_byte(W_REGISTER | (REGISTER_MASK & reg));
	spi_transmit_array(value,len);
	nRF24L01_CSN_hi;
}
Esempio n. 7
0
void nRF24L01_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.
{
	nRF24L01_CSN_lo;
	spi_transmit_byte(R_REGISTER | (REGISTER_MASK & reg));
	spi_transfer_array(value,value,len);
	nRF24L01_CSN_hi;
}
Esempio n. 8
0
extern void nRF24L01_get_data(uint8_t * data) 
// Reads nRF24L01_PAYLOAD bytes into data array
{
	
	nRF24L01_CSN_lo;				// Pull down chip select
	nRF24L01_CE_lo;
	spi_transmit_byte( R_RX_PAYLOAD );		// Send cmd to read rx payload
	spi_transfer_array(data,data,nRF24L01_PAYLOAD); // Read payload
	nRF24L01_CSN_hi;				// Pull up chip select
	nRF24L01_config_register(STATUS,(1<<RX_DR));	// Reset status register
	nRF24L01_CE_hi;

	//Clear the TX FIFO
	nRF24L01_CSN_lo;				// Pull down chip select
	spi_transmit_byte( FLUSH_TX );			// Write cmd to flush tx fifo
	nRF24L01_CSN_hi;				// Pull up chip select
}
Esempio n. 9
0
extern uint8_t nRF24L01_data_ready() 
// Checks if data is available for reading
{
	// Read nRF24L01 status 
	uint8_t status;
	nRF24L01_CSN_lo;				// Pull down chip select
	status = spi_transmit_byte(NOP);		// Read status register
	nRF24L01_CSN_hi;				// Pull up chip select
	return status & (1<<RX_DR);
}
Esempio n. 10
0
extern void nRF24L01_powerdown()
//place nRF24L01 in powerdown mode
{
	//empty the TX FIFO
	nRF24L01_CSN_lo;			// Pull down chip select
    	spi_transmit_byte( FLUSH_TX );		// Write cmd to flush tx fifo
   	nRF24L01_CSN_hi;			// Pull up chip select

        nRF24L01_CE_lo;				// Deactivate transceiver
	PWR_DOWN;				// power down transceiver
        nRF24L01_CE_hi;				// 
}
Esempio n. 11
0
void nRF24L01_send(uint8_t * value, uint8_t len) 
// Sends a data package to the default address. Be sure to send the correct
// amount of bytes as configured as payload on the receiver.
{
	while (PTX) {}				// Wait until last paket is send

	nRF24L01_CE_lo;

	PTX = 1;				// Set to transmitter mode
	TX_POWERUP;				// Power up
    
	nRF24L01_CSN_lo;			// Pull down chip select
	spi_transmit_byte( FLUSH_TX );		// Write cmd to flush tx fifo
	nRF24L01_CSN_hi;			// Pull up chip select
    
	nRF24L01_CSN_lo;			// Pull down chip select
	spi_transmit_byte( W_TX_PAYLOAD );	// Write cmd to write payload
	spi_transmit_array(value,len);		// Write payload
	nRF24L01_CSN_hi;			// Pull up chip select
    
	nRF24L01_CE_hi;				// Start transmission
}