This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Testing connection between atmega32 and nRF24L01 isn't working

I am trying to interface an atmega32 with an nRF24L01. I am trying to communicate between two nRF's. But before proceeding to that, I set out to test the SPI connection between the atmega and nRF.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* nRF Transmitter.c
*
* Created: 27-Jul-18 7:40:11 PM
* Author : DELL
*/
#define F_CPU 1e6
#include <avr/io.h>
#include <util/delay.h>
#include "nRF24L01.h"
#define MOSI PB5
#define SCK PB7
#define CSN PB4 /* CSN == SS */
#define CE PD7 /* Chip Enable */
#define READ 0
#define WRITE 1
/* SPI - to communicate between Master MCU and Slave nRF */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

This is the nRF24L01.h header file:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Memory Map */
#define CONFIG 0x00
#define EN_AA 0x01
#define EN_RXADDR 0x02
#define SETUP_AW 0x03
#define SETUP_RETR 0x04
#define RF_CH 0x05
#define RF_SETUP 0x06
#define STATUS 0x07
#define OBSERVE_TX 0x08
#define CD 0x09
#define RX_ADDR_P0 0x0A
#define RX_ADDR_P1 0x0B
#define RX_ADDR_P2 0x0C
#define RX_ADDR_P3 0x0D
#define RX_ADDR_P4 0x0E
#define RX_ADDR_P5 0x0F
#define TX_ADDR 0x10
#define RX_PW_P0 0x11
#define RX_PW_P1 0x12
#define RX_PW_P2 0x13
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This is a picture of my connection. I've used the upper atmega32 and an nRF24L01 and USBASP V2.0 from LC Technology. I'm using atmel studio 7 to write the code and extreme burner AVR to burn the code. I'm using a PAKKO 6F22 9V Heavy duty battery as the power source. I have used two potentiometers to divide the voltage. Atmega32 is given around ~4.8V and nRF around ~3.2 V. But with this current configuration, power fluctuates a lot. I'm using LED on PORTA to test my code. But sometimes the LED lights up and sometimes it doesn't. (PORTA = 0x04 don't get executed) I've checked the connection thoroughly, but can't figure out why it is behaving like this. And if it does light up, it is not giving the correct output, i.e the value I've written to the registers is not reflected on the LED. (If condition in while loop is not executed) Can you guys give me some suggestions to work out the power issue and to get the intended output on LEDs?

Note : Code is taken mainly from Gizmosnack's tutorial. 

Link: http://gizmosnack.blogspot.com/2013/04/tutorial-nrf24l01-and-avr.html

I'm using