Discussion in "AVR Discussion Forum" started by    lucky6772    Sep 1, 2013.
Sun Sep 01 2013, 11:38 am
#1

Working on wireless communication using CC2500 and Atmega8 using SPI
But am not able to receive any data!!
Also while configuring If I send received status byte to some port,some data is received which shows that modules are working but yet no successful communication after configuration...
Thugh main calls send() only but code contains functions of both transmitter(send()) and receiver(receive)


Heres the code:
//GDO0 PIN IS CONNECTED AT PIND5 OF PORTD
//O/P IS TAKEN AT PIN PORTC-TEMPORARY CHECKING OF RECEIVED DATA


#include<avr/io.h>

#include<avr/delay.h>


#define SS PB2
#define MOSI PB3
#define SCLK PB5
#define MISO PB4

void SPI_init(); //initialize SPI interface of atmega8
unsigned char SPI_TX(unsigned char); //transmit one byte from AVR to CC
void send();//Send data packet wirelessly
void receive();//Receive data packet
void command(unsigned char a); //Sends commands to CC2500
char my=0;


//assign values to the registers
#define CC_IOCFG2_value	 0x2F
#define CC_IOCFG1_value	 0x2E
#define CC_IOCFG0D_value	0x06
#define CC_FIFOTHR_value	0x07
#define CC_SYNC1_value	 0xD3
#define CC_SYNC0_value	 0x91
#define CC_PKTLEN_value	 0x03
#define CC_PKTCTRL1_value	0x84
#define CC_PKTCTRL0_value	0x04
#define CC_ADDR_value	 0x00
#define CC_CHANNR_value	 0x00
#define CC_FSCTRL1_value	0x09
#define CC_FSCTRL0_value	0x00
#define CC_FREQ2_value	 0x5D
#define CC_FREQ1_value	 0xD8
#define CC_FREQ0_value	 0x9D
#define CC_MDMCFG4_value	0x2D
#define CC_MDMCFG3_value	0x3B
#define CC_MDMCFG2_value	0x73
#define CC_MDMCFG1_value	0x23
#define CC_MDMCFG0_value	0x3B
#define CC_DEVIATN_value	0x01
#define CC_MCSM2_value	 0x07
#define CC_MCSM1_value 0x30
#define CC_MCSM0_value 0x18
#define CC_FOCCFG_value	 0x1D
#define CC_BSCFG_value	 0x1C
#define CC_AGCCTRL2_value	0xC7
#define CC_AGCCTRL1_value	0x00
#define CC_AGCCTRL0_value	0xB2
#define CC_WOREVT1_value	0x87
#define CC_WOREVT0_value	0x6B
#define CC_WORCTRL_value	0xF8
#define CC_FREND1_value	 0xB6
#define CC_FREND0_value	 0x10
#define CC_FSCAL3_value	 0xEA
#define CC_FSCAL2_value	 0x0A
#define CC_FSCAL1_value	 0x00
#define CC_FSCAL0_value	 0x11
#define CC_RCCTRL1_value	0x41
#define CC_RCCTRL0_value	0x00
#define CC_FSTEST_value	 0x59
#define CC_PTEST_value	 0x7F
#define CC_AGCTEST_value	0x3F
#define CC_TEST2_value	 0x88
#define CC_TEST1_value	 0x31
#define CC_TEST0_value	 0x0B
#define SRES 0x30
#define SFSTXON 0x31
#define SXOFF 0x32
#define SCAL 0x33
#define SRX 0x34
#define STX 0x35
#define SIDLE 0x36
#define SAFC 0x37
#define SWOR 0x38
#define SPWD 0x39
#define SFRX 0x3A
#define SFTX 0x3B
#define SWORRST 0x3C
#define SNOP 0x3D

//creating array for assigned register values
const unsigned char CC_rfSettings[0x2F]=
{
CC_IOCFG2_value,
CC_IOCFG1_value,
CC_IOCFG0D_value,
CC_FIFOTHR_value,
CC_SYNC1_value,
CC_SYNC0_value,
CC_PKTLEN_value,
CC_PKTCTRL1_value,
CC_PKTCTRL0_value,
CC_ADDR_value,
CC_CHANNR_value,
CC_FSCTRL1_value,
CC_FSCTRL0_value,
CC_FREQ2_value,
CC_FREQ1_value,
CC_FREQ0_value,
CC_MDMCFG4_value,
CC_MDMCFG3_value,
CC_MDMCFG2_value,
CC_MDMCFG1_value,
CC_MDMCFG0_value,
CC_DEVIATN_value,
CC_MCSM2_value,
CC_MCSM1_value,
CC_MCSM0_value,
CC_FOCCFG_value,
CC_BSCFG_value,
CC_AGCCTRL2_value,
CC_AGCCTRL1_value,
CC_AGCCTRL0_value,
CC_WOREVT1_value,
CC_WOREVT0_value,
CC_WORCTRL_value,
CC_FREND1_value,
CC_FREND0_value,
CC_FSCAL3_value,
CC_FSCAL2_value,
CC_FSCAL1_value,
CC_FSCAL0_value,
CC_RCCTRL1_value,
CC_RCCTRL0_value,
CC_FSTEST_value,
CC_PTEST_value,
CC_AGCTEST_value,
CC_TEST2_value,
CC_TEST1_value,
CC_TEST0_value
};

unsigned char p,q,r,t;

int main()
{
OSCCAL=0xAB;
unsigned char i;
_delay_ms(5);
SPI_init(); 
DDRC=0xff;
PORTC=0x00;

PORTB|=(1<<SS);

for(i=0x00;i<0x2F;i++) // configure registers of CC2500
{
PORTB&=(~(1<<SS));
while(((PINB)&(1<<MISO)==(1<<MISO)));
SPI_TX(i); //address byte
SPI_TX(CC_rfSettings[i]);// data byte
PORTB|=(1<<SS);
//_delay_ms(3000);
}
while(1)
{
//use send()in transmitter and receive() in receiver
send();
_delay_ms(3000);
PORTC=my;//for tx only
//receive();
}
}
void SPI_init()	//SPI initialization in atmega8
{
DDRB=(1<<MOSI)|(1<<SCLK)|(1<<SS);	// set MISO ,SS,SCLK as output pin
SPCR=(1<<SPE)|(1<<MSTR)|(1<<SPR0);	// Enable SPI,Set device as master, Set sck as fosc/8
}
unsigned char SPI_TX(unsigned char a) // atmega 8 send one byte to CC and receive one byte from CC
{
SPDR=a;
while(!(SPSR &(1<<SPIF)));	//wait until SPIF get high
return SPDR;
}

void send() // send data in CC wirelessly
{
my=(~my);
command(SFTX); //flush tx FIFO
command(SIDLE); //turn CC2500 into idle mode
command(SCAL);
PORTB&=(~(1<<SS));
while(((PINB)&(1<<MISO))==(1<<MISO));
SPI_TX(0x7F); // tx FIFO address in burst mode
SPI_TX(0x55); // data byte1
SPI_TX(0xAA); // data byte2
SPI_TX(my);//data byte3
PORTB|=(1<<SS);
command(STX); //command to send data in tx FIFO wirelessly
_delay_us(10);
}

//receive data serially from CC2500
void receive() 
{
command(SRX);	 // command to receive data wirelessly
//command(SRX);
while(!((PIND)&(1<<PD5))); // check GD0pin of CC2500
PORTB&=(~(1<<SS));
while(((PINB)&(1<<MISO))==(1<<MISO));
SPI_TX(0xFF); // rx FIFO address burst mode
p=SPI_TX(0x00); // data byte1
q=SPI_TX(0x00);// data byte2
r=SPI_TX(0x00);// data byte3
PORTB|=(1<<SS);
command(SFRX); // flush receiver FIFO
command(SIDLE); // turn CC2500 into idle mode
command(SCAL);
PORTC=r;
}

void command(unsigned char a) // give commands to CC2500
{
PORTB&=(~(1<<SS));
while(((PINB)&(1<<MISO))==(1<<MISO));
SPI_TX(a);
PORTB|=(1<<SS);
}
Mon Sep 02 2013, 02:57 am
#2
You and RollNoThree seem to be working on the same project.
I am minded to delete one of your threads.
Which one should I delete ?
Mon Sep 02 2013, 01:45 pm
#3
YA U CAN DELETE ROLLONETHREE BUT PLZ HELP ME FIRST...:)
Tue Sep 03 2013, 03:33 pm
#4
I am not sure how you're checking GDO0 status as you never configured GDO0 for interrupts. moreover default state of GDOx pins are different e.g. GDO0 gives CLK/192 output. Please see page 53 of datasheet and see if you've configured everything correctly or not.
Tue Sep 03 2013, 07:22 pm
#5
Thank you Ajay Bharghav for reply
I have configured GDO0 as 0x06 as per datasheet and I am continuously monitoring it @PD5 in receive subroutine.
Thu Sep 05 2013, 10:47 am
#6
is it working for you now? or you still have issues?
Thu Sep 05 2013, 10:51 am
#7
we have made some changes but still not working kindly help.. there is no help on anywhere on internet..!
/*

//GDO0 PIN IS CONNECTED AT PIND5 OF PORTD
//O/P IS TAKEN AT PIN PC0-TEMPORARY CHECKING OF RECEIVED DATA
*/
#include<avr/io.h>
#include<avr/delay.h>
#define SS PB2
#define MOSI PB3
#define SCLK PB5
#define MISO PB4
#define SPI_PORT PORTB

void SPI_init(); //initialize SPI interface of atmega8
unsigned char SPI_TX(unsigned char); //transmit one byte from AVR to CC
void send();
void receive();
void command(unsigned char a);
void Initial_PA_table();
void Power_on_reset_CC2500();
char my=0;

const unsigned char CC2500_patable_value[8]=
{
	0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

//assign values to the registers
#define CC_IOCFG2_value		0x2F
#define CC_IOCFG1_value		0x2E
#define CC_IOCFG0D_value	              0x06
#define CC_FIFOTHR_value	              0x07
#define CC_SYNC1_value		0xD3
#define CC_SYNC0_value		0x91
#define CC_PKTLEN_value		0x03
#define CC_PKTCTRL1_value	              0x84
#define CC_PKTCTRL0_value	              0x04
#define CC_ADDR_value		0x00
#define CC_CHANNR_value		0x6F
#define CC_FSCTRL1_value	              0x09
#define CC_FSCTRL0_value	              0x00
#define CC_FREQ2_value		0x5D
#define CC_FREQ1_value		0xD8
#define CC_FREQ0_value		0x9D
#define CC_MDMCFG4_value	              0x2D
#define CC_MDMCFG3_value	             0x3B
#define CC_MDMCFG2_value	             0x73
#define CC_MDMCFG1_value	             0x23
#define CC_MDMCFG0_value	             0x3B
#define CC_DEVIATN_value	              0x01
#define CC_MCSM2_value		0x07
#define CC_MCSM1_value  	              0x30
#define CC_MCSM0_value  	               0x18
#define CC_FOCCFG_value		0x1D
#define CC_BSCFG_value		0x1C
#define CC_AGCCTRL2_value	               0xC7
#define CC_AGCCTRL1_value	              0x00
#define CC_AGCCTRL0_value	              0xB2
#define CC_WOREVT1_value	              0x87
#define CC_WOREVT0_value	              0x6B
#define CC_WORCTRL_value	              0xF8
#define CC_FREND1_value	              0xB6
#define CC_FREND0_value		0x10
#define CC_FSCAL3_value		0xEA
#define CC_FSCAL2_value		0x0A
#define CC_FSCAL1_value		0x00
#define CC_FSCAL0_value		0x11
#define CC_RCCTRL1_value	              0x41
#define CC_RCCTRL0_value	              0x00
#define CC_FSTEST_value		0x59
#define CC_PTEST_value		0x7F
#define CC_AGCTEST_value	              0x3F
#define CC_TEST2_value		0x88
#define CC_TEST1_value		0x31
#define CC_TEST0_value		0x0B
#define SRES     			              0x30
#define SFSTXON  			0x31
#define SXOFF    			0x32
#define SCAL     			              0x33
#define SRX      			              0x34
#define STX      			             0x35
#define SIDLE    			            0x36
#define SAFC     			             0x37
#define SWOR     			0x38
#define SPWD     			0x39
#define SFRX     			             0x3A
#define SFTX     			              0x3B
#define SWORRST  			0x3C
#define SNOP     			0x3D
#define PATABLE				0x3E

//creating array for assigned register values
const unsigned char CC_rfSettings[0x2F]=
{
	CC_IOCFG2_value,
	CC_IOCFG1_value,
	CC_IOCFG0D_value,
	CC_FIFOTHR_value,
	CC_SYNC1_value,
	CC_SYNC0_value,
	CC_PKTLEN_value,
	CC_PKTCTRL1_value,
	CC_PKTCTRL0_value,
	CC_ADDR_value,
	CC_CHANNR_value,
	CC_FSCTRL1_value,
	CC_FSCTRL0_value,
	CC_FREQ2_value,
	CC_FREQ1_value,
	CC_FREQ0_value,
	CC_MDMCFG4_value,
	CC_MDMCFG3_value,
	CC_MDMCFG2_value,
	CC_MDMCFG1_value,
	CC_MDMCFG0_value,
	CC_DEVIATN_value,
	CC_MCSM2_value,
	CC_MCSM1_value,
	CC_MCSM0_value,
	CC_FOCCFG_value,
	CC_BSCFG_value,
	CC_AGCCTRL2_value,
	CC_AGCCTRL1_value,
	CC_AGCCTRL0_value,
	CC_WOREVT1_value,
	CC_WOREVT0_value,
	CC_WORCTRL_value,
	CC_FREND1_value,
	CC_FREND0_value,
	CC_FSCAL3_value,
	CC_FSCAL2_value,
	CC_FSCAL1_value,
	CC_FSCAL0_value,
	CC_RCCTRL1_value,
	CC_RCCTRL0_value,
	CC_FSTEST_value,
	CC_PTEST_value,
	CC_AGCTEST_value,
	CC_TEST2_value,
	CC_TEST1_value,
	CC_TEST0_value
};

unsigned char p,q,r,t;

int main()
{
	OSCCAL=0xAB;
	//unsigned int j;
	unsigned char i,b;
	_delay_ms(5);
	DDRD=0x00; //setting pin D5 as input for GDO0 pin of CC2500
	DDRC=0xff;
	PORTC=0x00;
	
	SPI_init(); 
	
	Power_on_reset_CC2500();
	
	//SPI_PORT|=(1<<SS);

	for(i=0x00;i<0x2F;i++)   // configure registers of CC2500
	{
		SPI_PORT&=(~(1<<SS));
		while(bit_is_set(PINB,MISO));
		SPI_TX(i); //address byte
		PORTC=SPI_TX(CC_rfSettings[i]);// data byte
		SPI_PORT|=(1<<SS);
		_delay_ms(3000);
		
	}
	
	Initial_PA_table();
	
	while(1)
	{
		//use send()in transmitter and receive() in receiver
		send();
		PORTC=my;
		_delay_ms(3000);
		
		//receive();
	}
}
void SPI_init()	//SPI initialization in atmega8
{
	DDRB=(1<<MOSI)|(1<<SCLK)|(1<<SS);	// set MISO ,SS,SCLK as output pin
	SPCR=(1<<SPE)|(1<<MSTR)|(1<<SPR0);	// Enable SPI,Set device as master, Set sck as fosc/8
	SPSR=(1<<SPI2X);
}
unsigned char SPI_TX(unsigned char a)  // atmega 8 send one byte to CC and receive one byte from CC
{
	SPDR=a;
	while(!(SPSR &(1<<SPIF)));	//wait until SPIF get high
	SPSR|=(1<<SPIF);
	return SPDR;
}

void send()  // send data in CC wirelessly
{
	my=(~my);
	command(SFTX);      //flush tx FIFO
	command(SIDLE);    //turn CC2500 into idle mode
	command(SCAL);
	PORTB&=(~(1<<SS));
	while(bit_is_set(PINB,MISO));
	SPI_TX(0x7F);    // tx FIFO address in burst mode
	SPI_TX(0x55); // data byte1
	SPI_TX(0xAA); // data byte2
	SPI_TX(my);//data byte3
	PORTB|=(1<<SS);
	command(STX);  //command to send data in tx FIFO wirelessly
	_delay_us(100);
}

//receive data serially from CC2500
void receive() 
{
	command(SRX);	 // command to receive data wirelessly
	//command(SRX);
	while(bit_is_clear(PIND,PIND5)); // check GD0pin of CC2500
	SPI_PORT&=(~(1<<SS));
	while(bit_is_set(PINB,MISO));
	SPI_TX(0xFF); // rx FIFO address burst mode
	p=SPI_TX(0x00); // data byte1
	q=SPI_TX(0x00);// data byte2
	r=SPI_TX(0x00);// data byte3
	SPI_PORT|=(1<<SS);
	command(SFRX); // flush receiver FIFO
	command(SIDLE); // turn CC2500 into idle mode
	command(SCAL);
	PORTC=r;
}

void command(unsigned char a) // give commands to CC
{
	SPI_PORT&=(~(1<<SS));
	while(bit_is_set(PINB,MISO));
	SPI_TX(a);
	SPI_PORT|=(1<<SS);
}

void Initial_PA_table()
{
	char i;
	SPI_PORT&=(~(1<<SS));
	//Bdata_buffer=PATABLE+0x40;
	while(bit_is_set(PINB,MISO));
	SPI_TX(PATABLE+0x40);
	for(i=0;i<8;i++)
	{
		SPI_TX(CC2500_patable_value[i]);
	}
	SPI_PORT|=(1<<SS);
}

void Power_on_reset_CC2500()
{
	//CC2500_module_CSN=1;
	SPI_PORT|=(1<<SS);
	_delay_us(8);
	//NOP();
	SPI_PORT|=(1<<SCLK);
	_delay_us(8);
	SPI_PORT&=(~(1<<MOSI));
	//NOP();
	_delay_us(8);
	command(SIDLE);
	//CC2500_module_CSN=1;
	SPI_PORT|=(1<<SS);
	_delay_us(50);
	//CC2500_module_CSN=0;
	SPI_PORT&=(~(1<<SS));
	//FDelay_4us(2);
	_delay_us(50);
	//CC2500_module_CSN=1;
	SPI_PORT|=(1<<SS);
	//FDelay_4us(15);
	_delay_us(50);
	//CC2500_module_CSN=0;
	SPI_PORT&=(~(1<<SS));
	//Bdata_buffer=SRES;
	while(bit_is_set(PINB,MISO));
	//SSPCON=0x20;
	//FWrite_one_byte_to_RF();
	command(SRES);
	//SSPCON=0x00;
	//while(MISO==1);
	while(bit_is_set(PINB,MISO));
	//MOSI=0;
	SPI_PORT|=(1<<MOSI);
	//CC2500_module_CSN=1;
	SPI_PORT|=(1<<SS);
}





btw nice new look of site..



[ Edited Thu Sep 05 2013, 12:17 pm ]
Thu Sep 05 2013, 12:32 pm
#8
I am really not sure what to answer coz Its hard to figure out the problem by just looking at code. I have never used this module. I would suggest you to take a look at some sample code of CC2500 if available. I am sure if you post for help on TI E2E forum people will help you in a better way.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Danielnof
Sat May 04 2024, 11:12 pm
oriminna
Sat May 04 2024, 08:28 pm
scaneraNom
Sat May 04 2024, 02:21 am
gtaletrzua
Fri May 03 2024, 10:55 am
Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am