Exemplo n.º 1
0
void setup() {
  serial_init(9600);
  serial_println("Loading...");
  
  spi_init(SPI_CLOCK_DIV128, SPI_MODE0);
  
  DDR_LED |= (1<<PIN_LED);  // LED pin output
  PORT_LED |= (1<<PIN_LED); // LED pin high
  
  DDR_nRF24L01_IRQ &= ~(1<<PIN_nRF24L01_IRQ);  // nRF24L01_IRQ pin input
  PORT_nRF24L01_IRQ &= ~(1<<PIN_nRF24L01_IRQ); // nRF24L01_IRQ pin low

  DDR_nRF24L01_CS |= (1<<PIN_nRF24L01_CS);  // nRF24L01_CS pin output
  PORT_nRF24L01_CS |= (1<<PIN_nRF24L01_CS); // nRF24L01_CS pin high

  DDR_nRF24L01_CE |= (1<<PIN_nRF24L01_CE);  // nRF24L01_CE pin output
  PORT_nRF24L01_CE &= ~(1<<PIN_nRF24L01_CE); // nRF24L01_CE pin low
  
  _delay_ms(5);

  nRF24L01_SetRxAddress(rxAddress);
  nRF24L01_WriteRegister(nRF24L01_REG_RF_CH, CHANNEL);
  nRF24L01_WriteRegister(nRF24L01_REG_RX_PW_P0, PAYLOAD_SIZE);
  nRF24L01_WriteRegister(nRF24L01_REG_RX_PW_P1, PAYLOAD_SIZE);
  nRF24L01_PrintRegisters();
  nRF24L01_PowerUpRx();
  nRF24L01_FlushRx();
  nRF24L01_PrintRegisters();

  serial_println("Begin TX");
}
nRF24L01_StatusTypeDef nRF24L01_Test(void)
{
	uint8_t writeBuf[5] = {0x34, 0x34, 0x34, 0x34, 0x34};
	uint8_t readBuf[5] = {0x00, 0x00, 0x00, 0x00, 0x00};
	uint8_t status, i;
	const uint8_t power = 0x0D;

	/*power off*/
	//status = nRF24L01_WriteRegister(0x20, (uint8_t*)&power, 1);

	status = nRF24L01_WriteRegister(0x2A, (uint8_t*)&writeBuf, 5);
	status = nRF24L01_ReadRegister(0x0A, (uint8_t*)&readBuf, 5);

	for(i = 0; i < 5; i++)
	{
		if(readBuf[i+1] != writeBuf[i])
			return NRF24L01_ERROR;
	}

	return NRF24L01_OK;

}