Hi all
as promised here is two programs which test the transmitter and
receiver using an Atmel processor wired as per my cmos 4050
voltage conversion mentioned in previous thread basically its just
a conversion from other programing methods over to codevision
from other peoples posts email me if you require further help
happy programming
Transmit side
/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.2c Standard
Automatic Program Generator
© Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
e-mail:office@hpinfotech.ro
Project : rf24tx test
Version :
Date : 7/6/2005
Author : Fletch
Company :
Comments:
Test the rf24g on transmit
sends 4 bytes to the receiver which will output on the leds for checking
uses SPI and control as per defines and spi as per processor.
used cmos 4050 for voltage conversion Atmel @5v ARf24g @3v3 as per my
wiring described in my previous post
Chip type : ATMEL 90s8535
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include <90s8535.h>
#include <delay.h>
#include <spi.h>
#define TX_DR PORTB.0
#define TX_CE PORTB.1
#define TX_CS PORTB.2
void configure_transmitter(void)
{
//Config Mode
TX_CE = 0; TX_CS = 1;
//Delay of 5us from CS to Data (page 30)
delay_ms(5);
/*config word Gives u lowest error rate, if u want a 8 byte payload
just change Data1_W to 0b00001000. It operates in shockburst/250kbs
16 bit crc on channel #2, full rf pwr, 1 channel rx only, 16mhz rf24g clk
addr width 5 bytes IE 40bits
*/
//All this is the same setup in the receiver bit 0 is changed to rx/tx as req
spi(0b00100000); //Data1_W - 32 bits in payload 4 bytes
spi(0x00); //ADDR2 - 1 //We only use 1 addr so set this to zero
spi(0x00); //ADDR2 - 2
spi(0x00); //ADDR2 - 3
spi(0x00); //ADDR2 - 4
spi(0x00); //ADDR2 - 5
spi(0xAA); //ADDR1 - 1 //1 - 5 This is our tx and rx addr
spi(0x55); //ADDR1 - 2
spi(0xFF); //ADDR1 - 3
spi(0x00); //ADDR1 - 4
spi(0xAA); //ADDR1 - 5
spi(0b10100011); //ADDR_W - 40 bits wide - CRC en 16bits
spi(0b01001111); //Full pwr- 16mhzclk- 250kbs-shkburst-1 chan only
spi(0b00000100); //RF Channel #2 and TX/RX - TX = 0 bit 0;
//Configuration is actived on falling edge of CS (page 10)
TX_CE = 0; TX_CS = 0;
}
// this sends address then sends data
void transmit_data(void)
{
TX_CE = 1; //set up for transmit
delay_ms(5);
spi(0xAA); //ADDR1 - 1 Send addr our receive is expecting
spi(0x55); //ADDR1 - 2
spi(0xFF); //ADDR1 - 3
spi(0x00); //ADDR1 - 4
spi(0xAA); //ADDR1 - 5
spi(0x12); //4 bytes data to transmit to the receiver
spi(0x34);
spi(0xAB);
spi(0xCD);
TX_CE = 0; //Start transmission
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
PORTA=0x00;
DDRA=0x00;
// Port B initialization
PORTB=0x00;
DDRB=0xB6; //Applicable to my spi example set as you wired it up
// Port C initialization
PORTC=0x00;
DDRC=0x00;
// Port D initialization
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
GIMSK=0x00;
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 250 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x51; //set this to 0x50 for 1 mbits
SPSR=0x00;
configure_transmitter();
while (1)
{
transmit_data(); //send addr and 4 bytes of data as per routine
delay_ms(5000); //wait 5 secs to send next packet
}
}
Receive side
/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.2c Standard
Automatic Program Generator
© Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
e-mail:office@hpinfotech.ro
Project :Rf24G Receive test program Receives 4 bytes from transmitter
then outputs their value to Leds on Port A for checking
Wiring is as per my SPI wiring through a cmos 4050 hex buffer
with voltage conversion from 5v Atmel to RF24g 3.3v
This is just a rehash of other programs but written in codevision
Program tested and works good
Version :
Date : 7/10/2005
Author : Fletch
Company :
Comments:
Chip type : mega8535
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*****************************************************/
#include <mega8535.h>
#include <stdio.h>
#include <delay.h>
#include <spi.h>
#define CS PORTB.2
#define CE PORTB.1
#define DR PINB.0
unsigned data_array[4];
void configure_receiver(void)
{
CE = 0; //CE set for config
CS = 1; //CS set for config only time CS is used is to configure
delay_ms(5);
spi(0b00100000); //Data1_W - 32 bits in payload 4Bytes
spi(0x00); //ADDR2 - 1 //Dont use Addr2 so set them all to zero
spi(0x00); //ADDR2 - 2
spi(0x00); //ADDR2 - 3
spi(0x00); //ADDR2 - 4
spi(0x00); //ADDR2 - 5
spi(0xAA); //ADDR1 - 1 //This is our Addr to rx on
spi(0x55); //ADDR1 - 2 //This must be the same addr transmitted
spi(0xFF); //ADDR1 - 3
spi(0x00); //ADDR1 - 4
spi(0xAA); //ADDR1 - 5
spi(0b10100011); //ADDR_W - 40 bits wide - 16bits -CRC en
spi(0b01001111); //RF Full pwr- 16mhzclk- 250kbs-shkburst-1 chan only
spi(0b00000101); //RF Channel #2 and direction & TX/RX - RX = 1
CS=0; //CS Clr CE already clr
delay_ms(5);
//Start monitoring the air
CE = 1; //CE set
}
void receive_data(void)
{
int i;
//CE = 0;//Power down RF Front end CE up to you if you want to do this
//Erase data array so we know we are looking at actual received data
data_array[0] = 0x00;
data_array[1] = 0x00;
data_array[2] = 0x00;
data_array[3] = 0x00;
for(i = 0 ; i < 4 ; i++) //4 bytes
{
data_array*=spi(0); //Load Received data in RG24g into our data array*
}
//CE = 1; //Power up RF Front end if you disabled it
}
// Declare your global variables here
void main(void)
{
// Input/Output Ports initialization
//Porta initialization set up with 8 led for output
PORTA=0x00;
DDRA=0xFF;
// Port B initialization SPI and Control all on this port
PORTB=0x00;
DDRB=0xB6;
// Port C initialization
PORTC=0x00;
DDRC=0x00;
// Port D initialization
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
//GIMSK=0x00;
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 250 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x51; //set this to 0x50 for 1 mbits
SPSR=0x00;
configure_receiver(); //Set up the receiver
while (1)
{
if(DR==1) //data pin goes high when it has data
{
receive_data(); //start transferring data from RF24g
PORTA=(~data_array[0]); //~is invert led data as leds are wired High
delay_ms(1000); //some delay so you can read the leds
PORTA=(~data_array[1]);
delay_ms(1000);
PORTA=(~data_array[2]);
delay_ms(1000);
PORTA=(~data_array[3]);
delay_ms(1000);
PORTA=0XFF; //clr leds down
}
}
}