hi all
this is just a quick example of a test program but written
in codevision hope someone finds it usefull i intend to make
more comprehensive examples available when i have time to
comment them all
/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.2c Standard
Automatic Program Generator
© Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro
Project : rf24g simple receive test
Version :
Date : 7/10/2005
Author : Fletch
Company :
Comments:
It works on rx spi only
Chip type : 90S8535
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*****************************************************/
/*
This is just a rehash of previous c examples but written for codevision
You will receive random data packets in the air im in a rf dead area and
the leds went mad so dont think it wont!
Test rf24module in receive mode just receives random data in the air
just proves that the rf24g module is actually wired and working correctly
data will be present as the crc is set to 8 bits only. output is to the 8 bit leds on port a
just receives random data.. i put a cd4050 level converter on the rf24g side
using the spi wired as my previous post
http://www.sparkfun.com/cgi-bin/phpbb/viewtopic.php?t=1400
*/
#include <90s8535.h>
#include <stdio.h>
#include <delay.h>
#include <spi.h>
#define CS PORTB.2
#define CE PORTB.1
#define DR PINB.0
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(0b00100001); //ADDR_W - 8 bits wide - CRC en 8bits
spi(0b01001111); //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 main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0xFF; //output to the leds
// Port B initialization
// Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=Out Func1=Out Func0=In
// State7=0 State6=T State5=0 State4=0 State3=T State2=0 State1=0 State0=T
PORTB=0x00;
DDRB=0xB6; //if wired as per my example this is the correct port settings
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=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;SPSR=0x00;
// 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;
SPSR=0x00;
configure_receiver(); //only alters up to bit 24 everything else is default
while (1)
{
if(DR==1) //data pin =1 data received
PORTA=spi(0); //output data pattern to 8 bit led module
delay_ms(50); //delay then go have another look
}
}