Ich versuche seit ein paar Tagen zwei Atmega2560 über zwei nrf24L01
miteinander kommunizieren zu lassen. Dabei habe ich mich an dem Code aus
diesem Tutorial orientiert
http://www.mikrocontroller.net/articles/NRF24L01_Tutorial. Dabei habe
ich ein paar kleine Änderungen vorgenommen.
Ich habe in den defines die Pinbelegung an den Atmega2560 angepasst und
in der wl_module.c den Interrupt für den Atmega2560 hinzugefügt.
1 | #if defined(__AVR_ATmega2560__)
|
2 | // Initialize external interrupt on port PK6 (PCINT22)
|
3 | DDRK &= ~(1<<PK6);
|
4 | PCMSK2 = (1<<PCINT22);
|
5 | PCICR = (1<<PCIE2);
|
6 | #endif
|
Beim Sender habe ich den Interrupt auch an den Atmega2560 angepasst.
Mein Sender und Empfänger sehen so aus:
Sender:
1 | #define F_CPU 16000000UL
|
2 |
|
3 | #include <avr/io.h>
|
4 | #include <util/delay.h>
|
5 | #include <avr/interrupt.h>
|
6 | #include <stdlib.h>
|
7 | #include <spi.h>
|
8 | #include <spi.c>
|
9 | #include <wl_module.h>
|
10 | #include <wl_module.c>
|
11 | #include <nRF24L01.h>
|
12 |
|
13 | volatile uint8_t timercounter;
|
14 |
|
15 | int main(void)
|
16 | {
|
17 | uint8_t payload[wl_module_PAYLOAD]; //Array for Payload
|
18 |
|
19 | wl_module_init(); //initialize nRF24L01+ Module
|
20 | _delay_ms(50); //wait for nRF24L01+ Module
|
21 | sei();
|
22 |
|
23 | wl_module_tx_config(wl_module_TX_NR_0); //Config Module
|
24 |
|
25 | while(1)
|
26 | {
|
27 | _delay_ms(1000);
|
28 | payload[0] = 5;
|
29 | wl_module_send(payload,wl_module_PAYLOAD);
|
30 | }
|
31 | }
|
32 |
|
33 | ISR(PCINT2_vect)
|
34 | {
|
35 | uint8_t status;
|
36 |
|
37 | // Read wl_module status
|
38 | wl_module_CSN_lo; // Pull down chip select
|
39 | status = spi_fast_shift(NOP); // Read status register
|
40 | wl_module_CSN_hi; // Pull up chip select
|
41 |
|
42 |
|
43 | if (status & (1<<TX_DS)) // IRQ: Package has been sent
|
44 | {
|
45 | wl_module_config_register(STATUS, (1<<TX_DS)); //Clear Interrupt Bit
|
46 | PTX=0;
|
47 | }
|
48 |
|
49 | if (status & (1<<MAX_RT)) // IRQ: Package has not been sent, send again
|
50 | {
|
51 | wl_module_config_register(STATUS, (1<<MAX_RT)); // Clear Interrupt Bit
|
52 | wl_module_CE_hi; // Start transmission
|
53 | _delay_us(10);
|
54 | wl_module_CE_lo;
|
55 | }
|
56 |
|
57 | if (status & (1<<TX_FULL)) //TX_FIFO Full <-- this is not an IRQ
|
58 | {
|
59 | wl_module_CSN_lo; // Pull down chip select
|
60 | spi_fast_shift(FLUSH_TX); // Flush TX-FIFO
|
61 | wl_module_CSN_hi; // Pull up chip select
|
62 | }
|
63 |
|
64 | }
|
Empfänger:
1 | #define F_CPU 16000000UL
|
2 |
|
3 | #include <avr/io.h>
|
4 | #include <util/delay.h>
|
5 | #include <avr/interrupt.h>
|
6 | #include <stdlib.h>
|
7 | #include <spi.h>
|
8 | #include <spi.c>
|
9 | #include <wl_module.h>
|
10 | #include <wl_module.c>
|
11 | #include <nRF24L01.h>
|
12 |
|
13 | volatile uint8_t PTX; //Global Variable
|
14 | char itoabuffer[20];
|
15 |
|
16 | int main(void)
|
17 | {
|
18 | DDRB |= (1<<PB5);
|
19 | uint8_t payload[wl_module_PAYLOAD]; //holds the payload
|
20 | uint8_t nRF_status; //STATUS information of nRF24L01+
|
21 |
|
22 | wl_module_init(); //Init nRF Module
|
23 | _delay_ms(50); //wait for Module
|
24 | sei(); //activate Interrupts
|
25 | wl_module_config(); //config nRF as RX Module, simple Version
|
26 |
|
27 | while(1)
|
28 | {
|
29 | while (!wl_module_data_ready()); //waits for RX_DR Flag in STATUS
|
30 | nRF_status = wl_module_get_data(payload); //reads the incoming Data to Array payload
|
31 | if (payload[0] == 5)
|
32 | {
|
33 | PORTB |= (1<<PB5);
|
34 | }
|
35 | }
|
36 | }
|
Es soll ein Paket gesendet werden und wenn dieses ankommt eine LED
seitens des Empfängers angeschaltet werden. Das passiert allerdings
nicht und ich weiß nicht was an dem Code falsch ist.
Hoffe mir kann jemand helfen.
Mfg Dennis