Пример #1
0
//****************************************************************************
// Sets the rx address of a given RX pipe.  See nRF24L01+ for more details
//*****************************************************************************
static __INLINE int32_t wireless_set_rx_addr(
  uint8_t  *rx_addr,
  uint8_t   pipe
)
{
  uint8_t dataIn[6];
  uint8_t dataOut[6];
  uint8_t wireless_reg = 0;
  
  switch(pipe)
  {
    case 0: { wireless_reg = NRF24L01_RX_ADDR_P0_R; break; }
    case 1: { wireless_reg = NRF24L01_RX_ADDR_P1_R; break; }
    case 2: { wireless_reg = NRF24L01_RX_ADDR_P2_R; break; }
    case 3: { wireless_reg = NRF24L01_RX_ADDR_P3_R; break; }
    case 4: { wireless_reg = NRF24L01_RX_ADDR_P4_R; break; }
    case 5: { wireless_reg = NRF24L01_RX_ADDR_P5_R; break; }
    default: {return -1;}
  }

  dataIn[0] = wireless_reg |  NRF24L01_CMD_W_REGISTER   ;
  dataIn[1] = *(rx_addr +0 );
  dataIn[2] = *(rx_addr +1 );
  dataIn[3] = *(rx_addr +2 );
  dataIn[4] = *(rx_addr +3 );
  dataIn[5] = *(rx_addr +4 );
  wireless_CSN_low();
  spiTx(wirelessPinConfig.wireless_spi_base,dataIn, 6, dataOut);
  wireless_CSN_high();
  return 0;
}
Пример #2
0
//*****************************************************************************
// On initialization, we remove any messages that are sitting in the RX Fifo
//*****************************************************************************
static __INLINE void wireless_flush_rx_fifo( void )
{
  uint8_t dataIn[1];
  uint8_t dataOut[1];
  
    dataIn[0] = NRF24L01_CMD_FLUSH_RX;
    wireless_CSN_low();
    spiTx(wirelessPinConfig.wireless_spi_base,dataIn, 1, dataOut);
    wireless_CSN_high();
}
Пример #3
0
//*****************************************************************************
// ADD CODE
// This function reads a single byte of data from the register at the 5-bit 
// address specificed by the lower 5 bits of paramter reg. 
//
// The value at that register is returned to the  user as a uint8_t.  
//
// Page 51 of the data sheet lists the supported commnads for the nRF24L01+.  
// The first two entries entries describe how to read/write a single byte of 
// data to a register.
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE uint8_t wireless_reg_read(uint8_t reg)
{
	uint8_t t[2];
	uint8_t com[2];
	com[0] = reg & 0x1F;
	wireless_CSN_low();

	spiTx(wirelessPinConfig.wireless_spi_base, &com[0], 2, t);
	wireless_CSN_high();	 
	return t[1];
}
Пример #4
0
//*****************************************************************************
// Returns the contents of the nRF24L01+ status register
//*****************************************************************************
static __INLINE uint8_t wireless_get_status( void )
{
  uint8_t dataIn[1];
  uint8_t dataOut[1];
  
  dataIn[0] = NRF24L01_CMD_NOP;
  wireless_CSN_low();
  spiTx(wirelessPinConfig.wireless_spi_base,dataIn, 1, dataOut);
  wireless_CSN_high();
  
  return dataOut[0];
}
Пример #5
0
//*****************************************************************************
// ADD CODE
// This function writes a single byte of data from the register at the 5-bit 
// address specificed by the lower 5 bits of paramter reg. 
//  
// Page 51 of the data sheet lists the supported commnads for the nRF24L01+.  
// The first two entries entries describe how to read/write a single byte of 
// data to a register.
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE void wireless_reg_write(uint8_t reg, uint8_t data)
{
	uint8_t t[2];
	uint8_t com[2];
	reg = (reg & 0x1F) | 0x20;
	
	com[0] = reg;
	com[1] = data;
	wireless_CSN_low();

	spiTx(wirelessPinConfig.wireless_spi_base, &com[0], 2, t);
	wireless_CSN_high();	 
}
Пример #6
0
//*****************************************************************************
// ADD CODE
// This function writes 4 bytes of data to the nRF24L01+ Tx FIFO using the 
// W_TX_PAYLOAD command found on page 51 of the nRF24L01+ datasheet.
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE void wireless_tx_data_payload( uint32_t data)
{
	uint8_t t[5];
	uint8_t com[5];
	com[0] = NRF24L01_CMD_W_TX_PAYLOAD;
	com[1] = data >> 24;
	com[2] = data >> 16;
	com[3] = data >> 8;
	com[4] = data;
	wireless_CSN_low();

	spiTx(wirelessPinConfig.wireless_spi_base, &com[0], 5, t);
	wireless_CSN_high();
}
Пример #7
0
//*****************************************************************************
// This function writes a single byte of data from the register at the 5-bit 
// address specificed by the lower 5 bits of paramter reg. 
//  
// Page 51 of the data sheet lists the supported commnads for the nRF24L01+.  
// The first two entries entries describe how to read/write a single byte of 
// data to a register.
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE void wireless_reg_write(uint8_t reg, uint8_t data)
{
	uint8_t din[2];
	uint8_t dout[2];
	
	din[0] = ((reg & 0x1F) | 0x20);
	din[1] = data;

	wireless_CSN_low();
	
	spiTx(SSI1_BASE, din, 2, dout);
	
	wireless_CSN_high();
}
Пример #8
0
//*****************************************************************************
// ADD CODE
// This function reads 4 bytes of data from the nRF24L01+ Tx FIFO using the 
// R_RX_PAYLOAD command found on page 51 of the nRF24L01+ datasheet.
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE void wireless_rx_data_payload( uint32_t *data)
{
 uint8_t command = NRF24L01_CMD_R_RX_PAYLOAD;
 uint8_t sendData[5];
 uint8_t returnData[5];
 sendData[0] = command;
 wireless_CSN_low();
 spiTx(wirelessPinConfig.wireless_spi_base,sendData,5,returnData);
 wireless_CSN_high();
 *data = 0;
 *data |= returnData[4];
 *data |= (returnData[3] << 8);
 *data |= (returnData[2] << 16);
 *data |= (returnData[1] << 24);
}
Пример #9
0
//*****************************************************************************
// ADD CODE
// This function writes 5 bytes of data to the TX_ADDR register found on page
// 60 of the nRF24L01+ data sheet.  
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE void wireless_set_tx_addr(uint8_t  *tx_addr)
{
	uint8_t t[6];
	uint8_t com[6];
	com[0] =  0x30;
	com[1] = tx_addr[0];
	com[2]=  tx_addr[1];
	com[3] = tx_addr[2];
	com[4] = tx_addr[3];
	com[5] = tx_addr[4];
	wireless_CSN_low();

	spiTx(wirelessPinConfig.wireless_spi_base, &com[0], 6, t);
	wireless_CSN_high();
}
Пример #10
0
//*****************************************************************************
// This function reads a single byte of data from the register at the 5-bit 
// address specificed by the lower 5 bits of paramter reg. 
//
// The value at that register is returned to the  user as a uint8_t.  
//
// Page 51 of the data sheet lists the supported commnads for the nRF24L01+.  
// The first two entries entries describe how to read/write a single byte of 
// data to a register.
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE uint8_t wireless_reg_read(uint8_t reg)
{
	uint8_t din[2];
	uint8_t dout[2];
	
	din[0] = (reg & 0x1F);
	din[1] = 0xFF;

	wireless_CSN_low();
	
	spiTx(SSI1_BASE, din, 2, dout);
	
	wireless_CSN_high();
	
	return dout[1];
}
Пример #11
0
//*****************************************************************************
// This function writes 4 bytes of data to the nRF24L01+ Tx FIFO using the 
// W_TX_PAYLOAD command found on page 51 of the nRF24L01+ datasheet.
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE void wireless_tx_data_payload( uint32_t data)
{
	uint8_t din[5];
	uint8_t dout[5];
	
	din[0] = 0xA0;
	din[1] = data & 0x000000FF;
	din[2] = (data & 0x0000FF00) >> 8;
	din[3] = (data & 0x00FF0000) >> 16;
	din[4] = (data & 0xFF000000) >> 24;
	

	wireless_CSN_low();
	
	spiTx(SSI1_BASE, din, 5, dout);
	
	wireless_CSN_high();
}
Пример #12
0
//*****************************************************************************
// This function writes 5 bytes of data to the TX_ADDR register found on page
// 60 of the nRF24L01+ data sheet.  
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE uint32_t wireless_set_tx_addr(uint8_t  *tx_addr)
{
  uint8_t din[6];
	uint8_t dout[6];
	
	din[0] = ((0x10 & 0x1F) | 0x20);
	din[1] = tx_addr[0];
	din[2] = tx_addr[1];
	din[3] = tx_addr[2];
	din[4] = tx_addr[3];
	din[5] = tx_addr[4];

	wireless_CSN_low();
	
	spiTx(SSI1_BASE, din, 6, dout);
	
	wireless_CSN_high();
}
Пример #13
0
//*****************************************************************************
// This function reads 4 bytes of data from the nRF24L01+ Tx FIFO using the 
// R_RX_PAYLOAD command found on page 51 of the nRF24L01+ datasheet.
//
// Use spiTx() to send the data via the SPI interface.  This function can be
// found in spi.c.  You will also need to use wireless_CSN_low() and 
// wireless_CSN_high() to manually set the SPI chip select.
//*****************************************************************************
static __INLINE void wireless_rx_data_payload( uint32_t *data)
{
	uint8_t din[5];
	uint8_t dout[5];
	
	din[0] = 0x61;
	din[1] = 0xFF;
	din[2] = 0xFF;
	din[3] = 0xFF;
	din[4] = 0xFF;
	
	wireless_CSN_low();
	
	spiTx(SSI1_BASE, din, 5, dout);
	
	wireless_CSN_high();

	*data = 0;
	*data |= dout[1];
	*data |= dout[2] << 8;
	*data |= dout[3] << 16;
	*data |= dout[4] << 24;
}