1 | #define FOSC 8000000UL
|
2 |
|
3 | #include <avr/io.h>
|
4 | #include <avr/interrupt.h>
|
5 | #include <util/delay.h>
|
6 | #include "nRF24L01.h"
|
7 | #include "nrf24.h"
|
8 | #include "spi.h"
|
9 | #include "setbit.h"
|
10 |
|
11 | /* -- USART -- */
|
12 | #define USART_BAUD 1200
|
13 | #define USART_MYUBRR FOSC/16/USART_BAUD-1
|
14 | /* -- -- */
|
15 |
|
16 | ISR (TIMER0_OVF_vect);
|
17 | ISR (INT0_vect);
|
18 | void extern_interrupt_init(void);
|
19 | void timer_interrupt_init(void);
|
20 | void io_init(void);
|
21 | void usart_init(unsigned int ubrr);
|
22 | void usart_transmit_char(unsigned char data);
|
23 | void usart_transmit_string (char *s);
|
24 |
|
25 | volatile unsigned int sekunde_over = 0;
|
26 | volatile unsigned char usart_data;
|
27 |
|
28 | uint8_t spi_temp;
|
29 | uint8_t spi_q = 0;
|
30 | char spi_itoabuffer[33];
|
31 | uint8_t spi_var =0;
|
32 | uint8_t spi_data_array[4];
|
33 | uint8_t spi_tx_address[5] = {0xE7,0xE7,0xE7,0xE7,0xE7};
|
34 | uint8_t spi_rx_address[5] = {0xD7,0xD7,0xD7,0xD7,0xD7};
|
35 |
|
36 | int main(void){
|
37 | //extern_interrupt_init(); // INT0 -> falling edge
|
38 | usart_init(USART_MYUBRR);
|
39 | timer_interrupt_init(); // Timer0 -> 1ms
|
40 | io_init(); // PD5 -> output -> low
|
41 | spi_init();
|
42 | nrf24_init(); // initialize hardware pins
|
43 | nrf24_config(2,4); // channel #2, payload length: 4
|
44 |
|
45 | /* Set the device addresses */
|
46 | nrf24_tx_address(spi_tx_address);
|
47 | nrf24_rx_address(spi_rx_address);
|
48 |
|
49 | sei(); // Global Interrupts activate
|
50 | usart_transmit_string("> USART Ready to use \r\n");
|
51 | while (1){
|
52 | /* Fill the data buffer */
|
53 | spi_data_array[0] = 0x00;
|
54 | spi_data_array[1] = 0xAA;
|
55 | spi_data_array[2] = 0x55;
|
56 | spi_data_array[3] = spi_q++;
|
57 |
|
58 | /* Automatically goes to TX mode */
|
59 | nrf24_send(spi_data_array);
|
60 |
|
61 | /* Wait for transmission to end */
|
62 | while(nrf24_isSending());
|
63 |
|
64 | /* Make analysis on last transmission attempt */
|
65 | spi_temp = nrf24_lastMessageStatus();
|
66 | if(spi_temp == NRF24_TRANSMISSON_OK)
|
67 | {
|
68 | usart_transmit_string("> Tranmission OK\r\n");
|
69 | }
|
70 | else if(spi_temp == NRF24_MESSAGE_LOST)
|
71 | {
|
72 | usart_transmit_string("> Message is lost ...\r\n");
|
73 | }
|
74 |
|
75 | _delay_ms(2000);
|
76 |
|
77 | }
|
78 | }
|