Hello everyone,
I am trying to communicate among 2 NRF24L01+ modules using 2 ATmega16A microcontrollers. My SPI communication is working fine as I am able to write and read registers of the module.But unfortunately I do not receive any data on the receiver side and I get a MAX_RT interrupt on the transmitter side.I have tried almost every configuration of the registers but still no luck. I have also ensured that the power supply is proper for the devices and they are placed fairly close to each other.
I am trying to use the Enhanced ShockBurst mode with auto ACK. I will post my code for both TX and RX side:
Receiver:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "SPI_master.h"
#include "nrf24l01+.c"
#include "UART.h"
unsigned char tx_addr[5]={0x11,0x12,0x13,0x14,0x15},rx_addr[5]={0x11,0x12,0x13,0x14,0x15};
void NRF_init(void){
NRF_portinit();
_delay_ms(150);
set_reg(SETUP_RETR,0xFF);
set_reg(RF_SETUP,0b00100110);
set_reg(CONFIG,0b00001100);
set_reg(DYNPD,0x00);
reset_status();
flush_tx();
flush_rx();
}
void open_writing_pipe(void){
change_address(RX_ADDR_P0,tx_addr[4],tx_addr[3],tx_addr[2],tx_addr[1],tx_addr[0]);
change_address(TX_ADDR,tx_addr[4],tx_addr[3],tx_addr[2],tx_addr[1],tx_addr[0]);
set_reg(RX_PW_P0,PAY_LEN);
}
void open_reading_pipe(void){
change_address(RX_ADDR_P1,rx_addr[4],rx_addr[4],rx_addr[4],rx_addr[4],rx_addr[4]);
set_reg(RX_PW_P1,PAY_LEN);
set_reg(EN_RXADDR,(1<<ERX_P1));
}
void startlistening(void){
set_mode(receive);
reset_status();
flush_rx();
flush_tx();
NRF_PORT |= (1<<CE);
_delay_us(130);
}
void power_down(void){
set_reg(CONFIG, (get_reg(CONFIG) & ~(1<<PWR_UP)));
}
int main(void){
unsigned char status;
UART_init();
INT0_init();
NRF_init();
while(1){
open_reading_pipe();
startlistening();
UART_send(get_reg(CONFIG));
UART_send(get_reg(EN_RXADDR));
status=get_reg(STATUS);
UART_send(status);
while(!(get_reg(STATUS)& (1<<RX_DR)));
if(status & (1<<RX_DR))
UART_send('R');
}`enter code here`
return 0;
}
Transmitter:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "SPI_master.h"
#include "nrf24l01+.c"
#include "UART.h"
unsigned char tx_addr[5]={0x11,0x12,0x13,0x14,0x15},rx_addr[5]={0x11,0x12,0x13,0x14,0x15};
void NRF_init(void){
NRF_portinit();
_delay_ms(150);
set_reg(SETUP_RETR,0xFF);
set_reg(RF_SETUP,0b00100110);
set_reg(CONFIG,0b00001100);
set_reg(DYNPD,0x00);
reset_status();
flush_tx();
flush_rx();
}
void open_writing_pipe(void){
change_address(RX_ADDR_P0,tx_addr[4],tx_addr[3],tx_addr[2],tx_addr[1],tx_addr[0]);
change_address(TX_ADDR,tx_addr[4],tx_addr[3],tx_addr[2],tx_addr[1],tx_addr[0]);
set_reg(RX_PW_P0,PAY_LEN);
}
void open_reading_pipe(void){
change_address(RX_ADDR_P1,rx_addr[4],rx_addr[4],rx_addr[4],rx_addr[4],rx_addr[4]);
set_reg(RX_PW_P1,PAY_LEN);
set_reg(EN_RXADDR,0x02);
}
void startlistening(void){
set_mode(receive);
reset_status();
flush_rx();
flush_tx();
NRF_PORT |= (1<<CE);
_delay_us(130);
}
void power_down(void){
set_reg(CONFIG, (get_reg(CONFIG) & ~(1<<PWR_UP)));
}
int main(void){
unsigned char status;
UART_init();
INT0_init();
NRF_init();
open_writing_pipe();
NRF_transmit('g');
UART_send(get_reg(CONFIG));
UART_send(get_reg(STATUS));
while(!(get_reg(STATUS) & ((1<<TX_DS) |(1<<MAX_RT)) ));
status=get_reg(STATUS);
if(status & (1<<MAX_RT))
UART_send('M');
if(status & (1<<TX_DS))
UART_send('T');
while(1){
}
return 0;
}
I am running on 250Kbps mode and 0dBm power.Please help.