hardware/Rmodule/main.c

49 lines
939 B
C
Raw Normal View History

2013-11-15 14:42:41 +07:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
2013-12-09 21:06:29 +07:00
#include <util/delay.h>
#include "nrf24l01/nrf24.h"
2013-11-15 14:42:41 +07:00
2013-12-09 21:06:29 +07:00
typedef struct data_arr{
uint8_t buffer[32];
}data_array;
2013-11-15 14:42:41 +07:00
2013-12-09 21:06:29 +07:00
uint8_t tx_mac[5] = {0xE7,0xE7,0xE7,0xE7,0xE7};
uint8_t rx_mac[5] = {0xD7,0xD7,0xD7,0xD7,0xD7};
2013-11-17 21:26:03 +07:00
int main(void){
2013-12-09 21:06:29 +07:00
/* initializes hardware pins */
nrf24_init();
/* RF channel: #2 , payload length: 4 */
nrf24_config(2,32);
/* Set the module's own address */
nrf24_rx_address(rx_mac);
/* Set the transmit address */
nrf24_tx_address(tx_mac);
2013-11-17 21:26:03 +07:00
sei();
2013-12-09 21:06:29 +07:00
data_array buff;
2013-11-18 21:27:01 +07:00
while(1){
2013-12-09 21:06:29 +07:00
if(nrf24_dataReady()){
nrf24_getData((uint8_t *) &buff);
nrf24_send((uint8_t*) &buff);
/* Wait for transmission to end */
while(nrf24_isSending());
/* Optionally, go back to RX mode ... */
nrf24_powerUpRx();
/* Wait a little ... */
_delay_ms(10);
}
2013-11-15 14:42:41 +07:00
}
}