1 | /*
|
2 | * nRF24L01_Testempfänger.c
|
3 | *
|
4 | * Created: 06/13/2016 16:53:10
|
5 | * Author: thobe
|
6 |
|
7 | PB0: CE
|
8 | PB1: CSN
|
9 | PB2: SSnot
|
10 | PB3: MOSI
|
11 | PB4: MISO
|
12 | PB5: SCK
|
13 | PB6: XTAL
|
14 | PB7: XTAL
|
15 |
|
16 | PC0:
|
17 | PC1:
|
18 | PC2:
|
19 | PC3:
|
20 | PC4:
|
21 | PC5:
|
22 | RESETnot: 3,3V
|
23 |
|
24 | PD0:
|
25 | PD1:
|
26 | PD2:
|
27 | PD3:
|
28 | PD4:
|
29 | PD5:
|
30 | PD6:
|
31 | PD7: IRQ (PCint23)
|
32 | */
|
33 |
|
34 | #ifndef F_CPU //Define F_CPU if not done
|
35 | #define F_CPU 16000000UL
|
36 | #endif
|
37 |
|
38 |
|
39 | #define BAUD 9600UL
|
40 | #define MYURBB F_CPU/16/BAUD-1
|
41 | #define UART_PUFFER_MAX 20
|
42 |
|
43 |
|
44 | #include <avr/io.h>
|
45 | #include <avr/interrupt.h>
|
46 | #include <util/delay.h>
|
47 | #include <stdlib.h>
|
48 | #include <string.h>
|
49 | #include "wl_module.h"
|
50 | #include "nRF24L01.h"
|
51 | #include "spi.h"
|
52 |
|
53 | //Variablen
|
54 | volatile uint8_t PTX; //Global Variable
|
55 | char itoabuffer[20];
|
56 | //volatile uint8_t uart_str_complete = 0;
|
57 | //volatile uint8_t uart_str_count = 0;
|
58 | //volatile char uart_string[UART_PUFFER_MAX + 1] = "";
|
59 | /*
|
60 | ISR (USART_RX_vect)
|
61 | {
|
62 | unsigned char nextChar;
|
63 | //Daten aus dem Puffer lesen
|
64 | nextChar = UDR0;
|
65 | if(uart_str_complete == 0)
|
66 | {
|
67 | if((nextChar =! '\n') && (nextChar =! '\r') && (uart_str_count < UART_PUFFER_MAX))
|
68 | {
|
69 | uart_string[uart_str_count] = nextChar;
|
70 | uart_str_count++;
|
71 | }
|
72 | else
|
73 | {
|
74 | uart_string[uart_str_count] = '\0';
|
75 | uart_str_count = 0;
|
76 | uart_str_complete = 1;
|
77 | }
|
78 | }
|
79 | }*/
|
80 | //UART Settings
|
81 | void USART_Init(unsigned int ubrr)
|
82 | { // set baud rate
|
83 | UBRR0H = (uint8_t) (ubrr >> 8);
|
84 | UBRR0L = (uint8_t) (ubrr);
|
85 | // activate Rx and Tx
|
86 | UCSR0B = /*(1<<RXEN0) | (1<<RXCIE0) | */(1<<TXEN0);
|
87 | // select async 8N1
|
88 | UCSR0C = (3<<UCSZ00);
|
89 | }
|
90 | void uart_putchar(char c)
|
91 | { while (!(UCSR0A & (1 << UDRE0))); // wait for buffer ready
|
92 | UDR0 = c;
|
93 | }
|
94 | void uart_write(char *str)
|
95 | { while(*str) {uart_putchar(*str); str++;}
|
96 | }
|
97 |
|
98 |
|
99 | int main(void)
|
100 | {
|
101 | uint8_t payload[wl_module_PAYLOAD]; //holds the payload
|
102 | uint8_t nRF_status = 0; //STATUS information of nRF24L01+
|
103 | uint8_t zaehler = 0;
|
104 |
|
105 | //initialize UART
|
106 | USART_Init(MYURBB);
|
107 | //Init nRF Module
|
108 | wl_module_init();
|
109 | _delay_ms(50); //wait for Module
|
110 | sei(); //activate Interrupts
|
111 | wl_module_rx_config(); //config nRF as RX Module
|
112 | wl_module_config_register(EN_AA,ENAA_P0); //Auto Acknowledgment bei P0
|
113 |
|
114 | uart_write("main_complete\r\n");
|
115 | _delay_ms(1000);
|
116 |
|
117 | while(1)
|
118 | {
|
119 | uart_write("while....data ready\r\n");
|
120 | //_delay_ms(300);
|
121 | while (!wl_module_data_ready()); //waits for RX_DR Flag in STATUS
|
122 | nRF_status = wl_module_get_data(payload); //reads the incomming Data to Array payload
|
123 | zaehler = payload[0];
|
124 | itoa(zaehler, itoabuffer, 10); //conversion into String
|
125 |
|
126 | // Send message to RS232
|
127 | //if (uart_str_complete ==1)
|
128 | //{
|
129 | uart_write(itoabuffer); uart_write("\r\n");
|
130 | itoa(nRF_status, itoabuffer,16);
|
131 | uart_write(itoabuffer); uart_write("\r\n\n");
|
132 | //uart_str_complete = 0;
|
133 | //}
|
134 | }
|
135 | }
|