bool RHReliableDatagram::available() {
	bool ret = nrf24_rx_fifo_data();

	if (!ret)
		nrf24_rx_mode();
	return ret;
}
static int nrf24_tx_result_wait(void) {
	uint8_t status;
	uint16_t count = 10000; /* ~100ms timeout */

	status = nrf24_read_status();

	/* Reset CE early so that a new Tx or Rx op can start sooner. */
	nrf24_ce(0);

	while ((!(status & (1 << TX_DS)) || (status & (1 << TX_FULL))) &&
			!(status & (1 << MAX_RT)) && --count) {
		delay8((int) (F_CPU / 8000L * 0.01));
		status = nrf24_read_status();
	}

	/* Reset status bits */
	nrf24_write_reg(STATUS, (1 << MAX_RT) | (1 << TX_DS));

	if (nrf24_in_rx) {
		nrf24_in_rx = 0;

		nrf24_rx_mode();
	}

	return (status & (1 << TX_DS)) ? 0 : -1;
}
bool RHReliableDatagram::init() {
	spi_init();

	if (nrf24_init())
		return 0;

	update_rx_addr(addr);
	nrf24_rx_mode();

	return 1;
}
Beispiel #4
0
void setup(void) {
	uint8_t s = SREG;
	uint8_t m = MCUCR;
	uint8_t i, addrs[6];

	wdt_disable();
	serial_init();
	timer_init();
	spi_init();
	nrf24_init();
	sei();

	/*
	 * Set our radio address and the remote end's radio address, read
	 * the addresses from EEPROM where they need to be saved first.
	 */
	for (i = 0; i < 6; i ++)
		addrs[i] = eeprom_read(i);

	nrf24_set_rx_addr(addrs + 0);
	nrf24_set_tx_addr(addrs + 3);

	/* Write something to say hello */
	serial_write_str("SREG:");
	serial_write_hex16(s);
	serial_write_str(", MCUCR:");
	serial_write_hex16(m);
	serial_write_str(", our addr: ");
	serial_write1(addrs[0]);
	serial_write1(addrs[1]);
	serial_write1(addrs[2]);
	serial_write_eol();

	nrf24_rx_mode();

	serial_set_handler(handle_input);
}
void RHReliableDatagram::setThisAddress(uint8_t new_addr) {
	addr = new_addr;
	nrf24_idle_mode(1);
	update_rx_addr(addr);
	nrf24_rx_mode();
}