[phpBB Debug] PHP Warning: in file /mnt/forum-shared/ext/sitesplat/BBCore/event/listener.php on line 70: in_array() expects parameter 2 to be array, boolean given
more RF24G problems! Help pls! - SparkFun Electronics

SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By rich
#2396
Right...
I've finally hooked up the rf24g to my atmega128 on the stk501 board. I've configured it for no crc, 8 bit address and then run an infinite while loop calling a receive method.

Hopeful outcome: To receive lots of rubbish and have the DR1 line toggling nicely. Unfortunately this does'nt happen. In fact very little happens.

I put out the data on PORTC (led's) and every now and then the lights change to 00000011. Either it does nothing, or changes to 00000011 and then does nothing. I am extremely confused.
Here is my code, i hope I'm doing something obviously stupid and some genius picks it up immediately.
Code: Select all
int main(void)
{
	u08 data;
	//initiate SPI
	cbi(DDRD,0);	//set PD0/DR1 as input
	cbi(PORTD,0);	//initialise PORTD to 0
	cbi(PIND,0);               //initialise PIND to 0
	sbi(DDRB, 1);	// set SCK as output
	sbi(DDRB, 5);	// set CS as output
	sbi(DDRB, 4);	// set CE as output
	cbi(DDRB, 3);	// set MISO as input
	sbi(DDRB, 2);	// set MOSI as output
	sbi(DDRB, 0);	// SS must be output for Master mode 	sbi(SPCR, MSTR);
	sbi(SPCR, SPR0);//SET UP CLOCK this is MCU clock/128
	sbi(SPCR, SPR1);
	cbi(SPCR, CPOL);// CPOL = 0, CPHA = 1
	sbi(SPCR,CPHA);//setup rising, sample falling
	cbi(SPCR,DORD);// Data order MSB first
	sbi(SPCR, SPE);// enable SPI
	SPSR&= 0x3E;// clear status
	sbi(SPCR, SPIE);// enable SPI interrupt
	cbi(SPSR,SPI2X);
	sei();//enable interrupts
	
	DDRC= 0xFF; //PORT C output
	PORTC = 0xAA;//default pattern
	cbi(PORTB,4);//pull CE, CS low 	
                cbi(PORTB,5);//putting tRF2.4GHz into standby mode
	ms_spin(3); //wait 3ms to settle
	while(1)
	{
		//*****RECEIVES A BYTE AND WRITES TO PORT C
		cbi(PORTB,4);//pull CE low
		sbi(PORTB,5);//pull CS high
		//wait 5 us to settle
		data = 0x03;
		spiSendByte(data);//set up 2.4GHz and receive 		sbi(PORTB,4);//pull CE high
		//wait 195 us to settle
		us_spin(195);
		while((PIND&0x01))//wait till DR1 is pulled high
		{
		}
		cbi(PORTB,4);//pull CE low
		PORTC =  spiReceiveByte();
	}
	return 0;
}

void spiSendByte(u08 data)
{
	// send a byte over SPI and ignore reply
	#ifdef SPI_USEINT
		while(!spiTransferComplete);
	#else
		while(!(inp(SPSR) & (1<<SPIF)));
	#endif
	spiTransferComplete = FALSE;
	SPDR = data;
	#ifdef SPI_USEINT
	while(!spiTransferComplete);
	#endif
}

u08 spiReceiveByte(void)
{
	#ifdef SPI_USEINT
		while(!spiTransferComplete);
	#else
		while(!(inp(SPSR) & (1<<SPIF)));
		spiTransferComplete = TRUE;
	#endif
	// return the received data
	return SPDR;
}
Sorry for the long code, but i've been stuck for almost a week now and don't want to leave anything out. btw I'm using WinAVR as my c compiler.

Your infinite wisdom on this subject would be much appreciated.

Richard

ADMIN EDIT : Use the code button please
By rich
#2399
sorry. left of my configuration method.....
Code: Select all
void initialconfigure(void)
{
	u08 data;
	sbi(PORTB,5);//pull CS high, CE low
	cbi(PORTB,4);
	us_spin(5);//wait 5 us to settle
	data = 0x8E;//default
	spiSendByte(data);
	data = 0x08;//default
	spiSendByte(data);
	data = 0x1C;//default
	spiSendByte(data);
	data = 0x08;//data2 width (NOT VITAL)
	spiSendByte(data);
	data = 0x08;//data1 width
	spiSendByte(data);
	data = 0x00;//address receiver 2(NOT VITAL)
	spiSendByte(data);
	spiSendByte(data);
	spiSendByte(data);
	spiSendByte(data);
	data = 0x0A;//setting address of channel 2 to oxoa
	spiSendByte(data);
	data = 0x00;//address receiver 1
	spiSendByte(data);
	spiSendByte(data);
	spiSendByte(data);
	spiSendByte(data);
	data = 0x0A;//setting address of channel 1 to oxoa
	spiSendByte(data);
	//no crc short address should receive all kinds of kak
	data = 0x20;
	//data = 0xA3;//setting address width to 8 bits no CRC	spiSendByte(data);
	//==========================
	//these 2 bytes need be updated
	data = 0x4D;//configure modes etc.
	spiSendByte(data);
	data = 0x02;//set up 2.4GHz and transmit channel 1
	spiSendByte(data);
	//pull CS low
	cbi(PORTB,5);

}
ADMIN EDIT : Use the code button please