PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Zwei Atmega2560 + nrf24L01



D3nni5
30.11.2016, 08:46
Ich suche nun schon eine ganze Weile nach einer Bibliothek, die dafür geeignet ist, den nrf24L01 über einen Atmega2560 anzusteuern. Bei der Suche stößt man aber nur auf Lösungen für Arduinos und das Umschreiben anderer Biblotheken verursacht Fehlermeldungen oder das Programm funktioniert nicht. Daher wollte ich fragen, ob jemand eine Bibliothek dafür kennt.

Mfg Dennis

D3nni5
05.12.2016, 10:51
Ich habe jetzt dieses Tutorial benutzt: http://www.mikrocontroller.net/articles/NRF24L01_Tutorial
In der Wl-Module.c hab ich noch den Interrupt für den Atmega2560 hinzugefügt.



#if defined(__AVR_ATmega2560__)
// Initialize external interrupt on port PK6 (PCINT22)
DDRK &= ~(1<<PK6);
PCMSK2 = (1<<PCINT22);
PCICR = (1<<PCIE2);
#endif


Bei dem Sender habe ich



#if defined(__AVR_ATmega8__)
ISR(INT0_vect)
#endif // __AVR_ATmega8__
#if defined(__AVR_ATmega88A__)
ISR(INT0_vect)
#endif // __AVR_ATmega88A__
#if defined(__AVR_ATmega168__)
ISR(PCINT2_vect)
#endif // __AVR_ATmega168__


durch



ISR(PCINT2_vect)


ersetzt.

Mein Sender sieht jetzt so aus:



#define F_CPU 16000000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <spi.h>
#include <spi.c>
#include <wl_module.h>
#include <wl_module.c>
#include <nRF24L01.h>

volatile uint8_t timercounter;

int main(void)
{
uint8_t payload[wl_module_PAYLOAD]; //Array for Payload

wl_module_init(); //initialize nRF24L01+ Module
_delay_ms(50); //wait for nRF24L01+ Module
sei();

wl_module_tx_config(wl_module_TX_NR_0); //Config Module

while(1)
{
_delay_ms(1000);
payload[0] = 5;
wl_module_send(payload,wl_module_PAYLOAD);
}
}

ISR(PCINT2_vect)
{
uint8_t status;

// Read wl_module status
wl_module_CSN_lo; // Pull down chip select
status = spi_fast_shift(NOP); // Read status register
wl_module_CSN_hi; // Pull up chip select


if (status & (1<<TX_DS)) // IRQ: Package has been sent
{
wl_module_config_register(STATUS, (1<<TX_DS)); //Clear Interrupt Bit
PTX=0;
}

if (status & (1<<MAX_RT)) // IRQ: Package has not been sent, send again
{
wl_module_config_register(STATUS, (1<<MAX_RT)); // Clear Interrupt Bit
wl_module_CE_hi; // Start transmission
_delay_us(10);
wl_module_CE_lo;
}

if (status & (1<<TX_FULL)) //TX_FIFO Full <-- this is not an IRQ
{
wl_module_CSN_lo; // Pull down chip select
spi_fast_shift(FLUSH_TX); // Flush TX-FIFO
wl_module_CSN_hi; // Pull up chip select
}

}


Under der Empfänger so:



#define F_CPU 16000000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <spi.h>
#include <spi.c>
#include <wl_module.h>
#include <wl_module.c>
#include <nRF24L01.h>

volatile uint8_t PTX; //Global Variable
char itoabuffer[20];

int main(void)
{
DDRB |= (1<<PB5);
uint8_t payload[wl_module_PAYLOAD]; //holds the payload
uint8_t nRF_status; //STATUS information of nRF24L01+

wl_module_init(); //Init nRF Module
_delay_ms(50); //wait for Module
sei(); //activate Interrupts
wl_module_config(); //config nRF as RX Module, simple Version

while(1)
{
while (!wl_module_data_ready()); //waits for RX_DR Flag in STATUS
nRF_status = wl_module_get_data(payload); //reads the incoming Data to Array payload
if (payload[0] == 5)
{
PORTB |= (1<<PB5);
}
}
}


Nach der Übertragung soll eine LED auf PB5 geschaltet werden allerdings tut sich nichts.
Hoffe mir kann jemand helfen.

Mfg Dennis