Example #1
0
void mirf_send(uint8_t *value, uint8_t len) {

	PMODE = TXMODE; // Set to transmitter mode

	TX_POWERUP; // Power up
	_delay_ms(5); // wait for transmitter to come up



	mirf_CSN_lo; // Pull down chip select

	SPI.transfer(FLUSH_TX);  // Write cmd to flush tx fifo

	mirf_CSN_hi; // Pull up chip select



	mirf_CSN_lo;  // Pull down chip select

	SPI.transfer(W_TX_PAYLOAD); // Write cmd to write payload

	spi_write_data(value, len); // Write payload

	mirf_CSN_hi; // Pull up chip select



	mirf_CE_hi; // Start transmission

	_delay_us(15);

	mirf_CE_lo;

}
Example #2
0
// Send data and wait for an ACK
uint8_t mirf_transmit_data(void) {
	TX_POWERUP; // Power up to transmitter mode
	
	mirf_CSN_lo; // Pull down chip select
	spi_transfer(FLUSH_TX); // Write cmd to flush tx fifo
	mirf_CSN_hi; // Pull up chip select
	
	mirf_CSN_lo;  // Pull down chip select
	spi_transfer(W_TX_PAYLOAD); // Write cmd to write payload
	spi_write_data(data_out, mirf_PAYLOAD); // Write payload
	mirf_CSN_hi; // Pull up chip select
	
	mirf_CE_hi; // Start transmission
	_delay_us(15);
	mirf_CE_lo;
	
	int waitcount = 0;
	while (!(mirf_status() & (1<<TX_DS))) { // Wait until we receive an ACK back
		_delay_us(500); // Wait the auto retransmit time
		if (mirf_status() & (1<<MAX_RT)) { // If maximum retries reached
			mirf_config_register(STATUS, 1<<MAX_RT); // Reset maximum retries to be able to transmit again next time
			mirf_CE_hi;
			_delay_us(15);
			mirf_CE_lo;
		}
		waitcount++;
		if (waitcount >= 10) { // If we haven't heard back in 5ms, exit
			mirf_config_register(STATUS, 1<<MAX_RT); // Reset maximum retries to be able to transmit again next time
			return 0;
		}
	}
	
	mirf_config_register(STATUS,(1<<TX_DS)); // Reset status register
	
	return 1;
}
Example #3
0
// Writes an array of bytes into the MiRF register
void mirf_write_register(uint8_t reg, uint8_t *value, uint8_t len) {
	mirf_CSN_lo;
	spi_transfer(W_REGISTER | (REGISTER_MASK & reg));
	spi_write_data(value, len);
	mirf_CSN_hi;
}