Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

rfm12b initialization in codevisionavr

Status
Not open for further replies.

vvarlord

Member level 4
Joined
Mar 15, 2012
Messages
74
Helped
4
Reputation
8
Reaction score
3
Trophy points
1,288
Activity points
1,756
i need some help on rfm12b initialization in codevisionavr
thanks
 

i want to use rfm12b with atmega 8l
the pages you mentioned are c, but are not ment to be used for atmega8l codevisionavr
if anyone know ,i'll be glad to be told about it
 

The majority of AVRs can run the same code and m8 is identical to m88.
All the documents I have provided include ready solutions using C to initialize the device so you are 99% there but you seem to be asking for others to do the job for you and provide you a ready solution.
 
i didn't have a problem with the micro dear alexan
i just said the c compiler that's used isn't the same with codevision's
it just has libraries that like avr/io avr/intrupt that , do not exist in codevision
any further assistance would be apperciated
 

If you know how to use codevision then I don't understand why you are troubled with the headers.

avrgcc #include <avr/io.h> is equivalent to codevision #include <mega8.h>

avrgcc #include <util/delay.h> is equivalent to codevision #include <delay.h>

avrgcc #include <avr/interrupt.h> doesn't exist in codevision, the interrupt work without a header

sei() and cli() in gcc are equivalent to #asm("sei") and #asm("cli")
_delay_ms() is equivalent to delay_ms();
 
that's exactly what i didn't know about codevision avr
i'll try to check it
thanks alexan,,, i'll have more question for you!
you seem to know what i don't!

- - - Updated - - -

#include <avr/pgmspace.h>
#include <avr/eeprom.h>
what are the equvilant for these headers?
 

There is no equivalent for these headers either.

The first one is to store variables in flash, in codevision you simply write
Code:
const flash var_type var_name
this will be a variable saved to flash which of course can only be set at compile time, once stored in flash you can't change it during execution
for example
Code:
const flash unsigned char my_char=123;
const flash int my_int=1234;

The eeprom header, there is also no equivalent of that in codevision because you can use it in a similar way like the flash
Code:
eeprom var_type var_name
This is a variable stored in eeprom, it can be read ot written during execution.
Here is an example
Code:
eeprom unsigned char my_eeprom_char;
if you want to assign a default value that will be stored in eeprom during programming you use
Code:
eeprom unsigned char my_eeprom_char =12;
 
Last edited:
i tird to change the format of the avrgcc files , but alot of errors occured out of my knowledge to solve
i'll be glad if anyone could give me a clue to start with

- - - Updated - - -

where should i begin to write my own code for initialization of the rfm12b modules in code vision

- - - Updated - - -

where should i begin to write my own code for initialization of the rfm12b modules in code vision
 

when i compile this file a pop up error comes and says: "errors occured during assembley " when i press ok another one appears: "can't read file:..."
and my code is:
Code:
#include <mega8.h>
#include <stdlib.h>
#include "global.h"
#include "rf12.h"     

#define F_CPU 8000000UL
#include <delay.h>
unsigned char i;
void send(void);
void receive(void);

void main(void)
{
	rf12_init();					// ein paar Register setzen (z.B. CLK auf 10MHz)
	rf12_setfreq(RF12FREQ(433.92));	// Sende/Empfangsfrequenz auf 433,92MHz einstellen
	rf12_setbandwidth(4, 1, 4);		// 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm 
	rf12_setbaud(19200);			// 19200 baud
	rf12_setpower(0, 6);			// 1mW Ausgangangsleistung, 120kHz Frequenzshift

	#asm("sei");

	for (;;)
	{
		receive();
	}
}

void receive(void)
{	unsigned char test[32];	
	rf12_rxdata(test,32);	
	for (i=0; i<32; i++);
}

void send(void)
{	unsigned char test[]="Dies ist ein 433MHz Test !!!\n   ";	
	rf12_txdata(test,32);
}
the rfm12b c file is changed to this:

Code:
#include <mega8.h>
#include "global.h"
#include "rf12.h"

#define F_CPU 8000000UL
#include <delay.h>

#define RF_PORT	PORTB
#define RF_DDR	DDRB
#define RF_PIN	PINB

#define SDI		3
#define SCK		5
#define CS		2
#define SDO		4
 
unsigned short rf12_trans(unsigned short wert)
{
    unsigned char i;
	#asm("cbi(RF_PORT, CS)");
	for (i=0; i<16; i++)
	{	if (wert&32768)
			#asm("sbi(RF_PORT, SDI)");
		else
			#asm("cbi(RF_PORT, SDI)");
		wert<<=1;
		if (RF_PIN&(1<<SDO))
			wert|=1;
		#asm("sbi(RF_PORT, SCK)");
		#asm("nop");
		#asm("nop");
		#asm("cbi(RF_PORT, SCK)");
	}
	#asm("sbi(RF_PORT, CS)");
	return wert;
}

void rf12_init(void)
{   unsigned char i;
	RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
	RF_PORT=(1<<CS);

	for (i=0; i<50; i++)
		delay_ms(10);			// wait until POR done
	rf12_trans(0xC0E0);			// AVR CLK: 10MHz
	rf12_trans(0x80D7);			// Enable FIFO
	rf12_trans(0xC2AB);			// Data Filter: internal
	rf12_trans(0xCA81);			// Set FIFO mode
	rf12_trans(0xE000);			// disable wakeuptimer
	rf12_trans(0xC800);			// disable low duty cycle
	rf12_trans(0xC4F7);			// AFC settings: autotuning: -10kHz...+7,5kHz
}

void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
	rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}

void rf12_setfreq(unsigned short freq)
{	if (freq<96)				// 430,2400MHz
		freq=96;
	else if (freq>3903)			// 439,7575MHz
		freq=3903;
	rf12_trans(0xA000|freq);
}

void rf12_setbaud(unsigned short baud)
{
	if (baud<664)
		baud=664;
	if (baud<5400)					// Baudrate= 344827,58621/(R+1)/(1+CS*7)
		rf12_trans(0xC680|((43104/baud)-1));	// R=(344828/8)/Baud-1
	else
		rf12_trans(0xC600|((344828UL/baud)-1));	// R=344828/Baud-1
}

void rf12_setpower(unsigned char power, unsigned char mod)
{	
	rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}

void rf12_ready(void)
{    #asm("cbi(RF_PORT, SDI)");
     #asm("cbi(RF_PORT, CS)");
	#asm("nop");
	while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}

void rf12_txdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x8238);			// TX on
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB82D);
	rf12_ready();
	rf12_trans(0xB8D4);
	for (i=0; i<number; i++)
	{		rf12_ready();
		rf12_trans(0xB800|(*data++));
	}
	rf12_ready();
	delay_us(10);
	rf12_trans(0x8208);			// TX off
}

void rf12_rxdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x82C8);			// RX on
	rf12_trans(0xCA81);			// set FIFO mode
	rf12_trans(0xCA83);			// enable FIFO
	for (i=0; i<number; i++)
	{	rf12_ready();
		*data++=rf12_trans(0xB000);
	}
	rf12_trans(0x8208);			// RX off
}

- - - Updated - - -

when i compile this file a pop up error comes and says: "errors occured during assembley " when i press ok another one appears: "can't read file:..."
and my code is:
Code:
#include <mega8.h>
#include <stdlib.h>
#include "global.h"
#include "rf12.h"     

#define F_CPU 8000000UL
#include <delay.h>
unsigned char i;
void send(void);
void receive(void);

void main(void)
{
	rf12_init();					// ein paar Register setzen (z.B. CLK auf 10MHz)
	rf12_setfreq(RF12FREQ(433.92));	// Sende/Empfangsfrequenz auf 433,92MHz einstellen
	rf12_setbandwidth(4, 1, 4);		// 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm 
	rf12_setbaud(19200);			// 19200 baud
	rf12_setpower(0, 6);			// 1mW Ausgangangsleistung, 120kHz Frequenzshift

	#asm("sei");

	for (;;)
	{
		receive();
	}
}

void receive(void)
{	unsigned char test[32];	
	rf12_rxdata(test,32);	
	for (i=0; i<32; i++);
}

void send(void)
{	unsigned char test[]="Dies ist ein 433MHz Test !!!\n   ";	
	rf12_txdata(test,32);
}
the rfm12b c file is changed to this:

Code:
#include <mega8.h>
#include "global.h"
#include "rf12.h"

#define F_CPU 8000000UL
#include <delay.h>

#define RF_PORT	PORTB
#define RF_DDR	DDRB
#define RF_PIN	PINB

#define SDI		3
#define SCK		5
#define CS		2
#define SDO		4
 
unsigned short rf12_trans(unsigned short wert)
{
    unsigned char i;
	#asm("cbi(RF_PORT, CS)");
	for (i=0; i<16; i++)
	{	if (wert&32768)
			#asm("sbi(RF_PORT, SDI)");
		else
			#asm("cbi(RF_PORT, SDI)");
		wert<<=1;
		if (RF_PIN&(1<<SDO))
			wert|=1;
		#asm("sbi(RF_PORT, SCK)");
		#asm("nop");
		#asm("nop");
		#asm("cbi(RF_PORT, SCK)");
	}
	#asm("sbi(RF_PORT, CS)");
	return wert;
}

void rf12_init(void)
{   unsigned char i;
	RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
	RF_PORT=(1<<CS);

	for (i=0; i<50; i++)
		delay_ms(10);			// wait until POR done
	rf12_trans(0xC0E0);			// AVR CLK: 10MHz
	rf12_trans(0x80D7);			// Enable FIFO
	rf12_trans(0xC2AB);			// Data Filter: internal
	rf12_trans(0xCA81);			// Set FIFO mode
	rf12_trans(0xE000);			// disable wakeuptimer
	rf12_trans(0xC800);			// disable low duty cycle
	rf12_trans(0xC4F7);			// AFC settings: autotuning: -10kHz...+7,5kHz
}

void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
	rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}

void rf12_setfreq(unsigned short freq)
{	if (freq<96)				// 430,2400MHz
		freq=96;
	else if (freq>3903)			// 439,7575MHz
		freq=3903;
	rf12_trans(0xA000|freq);
}

void rf12_setbaud(unsigned short baud)
{
	if (baud<664)
		baud=664;
	if (baud<5400)					// Baudrate= 344827,58621/(R+1)/(1+CS*7)
		rf12_trans(0xC680|((43104/baud)-1));	// R=(344828/8)/Baud-1
	else
		rf12_trans(0xC600|((344828UL/baud)-1));	// R=344828/Baud-1
}

void rf12_setpower(unsigned char power, unsigned char mod)
{	
	rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}

void rf12_ready(void)
{    #asm("cbi(RF_PORT, SDI)");
     #asm("cbi(RF_PORT, CS)");
	#asm("nop");
	while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}

void rf12_txdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x8238);			// TX on
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB82D);
	rf12_ready();
	rf12_trans(0xB8D4);
	for (i=0; i<number; i++)
	{		rf12_ready();
		rf12_trans(0xB800|(*data++));
	}
	rf12_ready();
	delay_us(10);
	rf12_trans(0x8208);			// TX off
}

void rf12_rxdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x82C8);			// RX on
	rf12_trans(0xCA81);			// set FIFO mode
	rf12_trans(0xCA83);			// enable FIFO
	for (i=0; i<number; i++)
	{	rf12_ready();
		*data++=rf12_trans(0xB000);
	}
	rf12_trans(0x8208);			// RX off
}

- - - Updated - - -

when i compile this file a pop up error comes and says: "errors occured during assembley " when i press ok another one appears: "can't read file:..."
and my code is:
Code:
#include <mega8.h>
#include <stdlib.h>
#include "global.h"
#include "rf12.h"     

#define F_CPU 8000000UL
#include <delay.h>
unsigned char i;
void send(void);
void receive(void);

void main(void)
{
	rf12_init();					// ein paar Register setzen (z.B. CLK auf 10MHz)
	rf12_setfreq(RF12FREQ(433.92));	// Sende/Empfangsfrequenz auf 433,92MHz einstellen
	rf12_setbandwidth(4, 1, 4);		// 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm 
	rf12_setbaud(19200);			// 19200 baud
	rf12_setpower(0, 6);			// 1mW Ausgangangsleistung, 120kHz Frequenzshift

	#asm("sei");

	for (;;)
	{
		receive();
	}
}

void receive(void)
{	unsigned char test[32];	
	rf12_rxdata(test,32);	
	for (i=0; i<32; i++);
}

void send(void)
{	unsigned char test[]="Dies ist ein 433MHz Test !!!\n   ";	
	rf12_txdata(test,32);
}
the rfm12b c file is changed to this:

Code:
#include <mega8.h>
#include "global.h"
#include "rf12.h"

#define F_CPU 8000000UL
#include <delay.h>

#define RF_PORT	PORTB
#define RF_DDR	DDRB
#define RF_PIN	PINB

#define SDI		3
#define SCK		5
#define CS		2
#define SDO		4
 
unsigned short rf12_trans(unsigned short wert)
{
    unsigned char i;
	#asm("cbi(RF_PORT, CS)");
	for (i=0; i<16; i++)
	{	if (wert&32768)
			#asm("sbi(RF_PORT, SDI)");
		else
			#asm("cbi(RF_PORT, SDI)");
		wert<<=1;
		if (RF_PIN&(1<<SDO))
			wert|=1;
		#asm("sbi(RF_PORT, SCK)");
		#asm("nop");
		#asm("nop");
		#asm("cbi(RF_PORT, SCK)");
	}
	#asm("sbi(RF_PORT, CS)");
	return wert;
}

void rf12_init(void)
{   unsigned char i;
	RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
	RF_PORT=(1<<CS);

	for (i=0; i<50; i++)
		delay_ms(10);			// wait until POR done
	rf12_trans(0xC0E0);			// AVR CLK: 10MHz
	rf12_trans(0x80D7);			// Enable FIFO
	rf12_trans(0xC2AB);			// Data Filter: internal
	rf12_trans(0xCA81);			// Set FIFO mode
	rf12_trans(0xE000);			// disable wakeuptimer
	rf12_trans(0xC800);			// disable low duty cycle
	rf12_trans(0xC4F7);			// AFC settings: autotuning: -10kHz...+7,5kHz
}

void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
	rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}

void rf12_setfreq(unsigned short freq)
{	if (freq<96)				// 430,2400MHz
		freq=96;
	else if (freq>3903)			// 439,7575MHz
		freq=3903;
	rf12_trans(0xA000|freq);
}

void rf12_setbaud(unsigned short baud)
{
	if (baud<664)
		baud=664;
	if (baud<5400)					// Baudrate= 344827,58621/(R+1)/(1+CS*7)
		rf12_trans(0xC680|((43104/baud)-1));	// R=(344828/8)/Baud-1
	else
		rf12_trans(0xC600|((344828UL/baud)-1));	// R=344828/Baud-1
}

void rf12_setpower(unsigned char power, unsigned char mod)
{	
	rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}

void rf12_ready(void)
{    #asm("cbi(RF_PORT, SDI)");
     #asm("cbi(RF_PORT, CS)");
	#asm("nop");
	while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}

void rf12_txdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x8238);			// TX on
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB82D);
	rf12_ready();
	rf12_trans(0xB8D4);
	for (i=0; i<number; i++)
	{		rf12_ready();
		rf12_trans(0xB800|(*data++));
	}
	rf12_ready();
	delay_us(10);
	rf12_trans(0x8208);			// TX off
}

void rf12_rxdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x82C8);			// RX on
	rf12_trans(0xCA81);			// set FIFO mode
	rf12_trans(0xCA83);			// enable FIFO
	for (i=0; i<number; i++)
	{	rf12_ready();
		*data++=rf12_trans(0xB000);
	}
	rf12_trans(0x8208);			// RX off
}
 

What is the point of posting three times the same thing?

- - - Updated - - -

I don't think there is a cbi and sbi in codevision

Code:
#define RF_PORT	PORTB
#define RF_DDR	DDRB
#define RF_PIN	PINB

#define SDI		3
#define SCK	5
#define CS		2
#define SDO	4

#asm("cbi(RF_PORT, CS)");
#asm("sbi(RF_PORT, SDI)");

cbi is clear bit (to 0) and sbit sets a bit (to 1)

#asm("cbi(RF_PORT, CS)"); based on the defines is #asm("cbi(PORTB, 2)"); , it is the same as PORTB.2=0;

the same way #asm("sbi(RF_PORT, SDI)"); is PORTB.3=1;

Change any other occurrences of similar code

- - - Updated - - -

What is the point of posting three times the same thing?

Note by the way that this is called bumbing and it against the rules of the forum so I would suggest you stop doing that.
 

sorry about posting 3 times,, i didn't know it was posted, so i clicked again

i changed the codes as you mentioned
i put both .c files into one and now i get 1 error: Error: E:\REza\codevision save files\New folder (101)\101.c(278): undefined symbol 'RF12FREQ'
here's my final code:
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 12/26/2012
Author  : PerTic@n
Company : If You Like This Software,Buy It
Comments: 


Chip type               : ATmega16L
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include <mega16.h>
#include <stdlib.h>
// Alphanumeric LCD functions
#include <alcd.h>
#include <delay.h>
// Declare your global variables here

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=0x00;

// Port B 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 
PORTB=0x00;
DDRB=0x00;

// 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 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// USART disabled
UCSRB=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 3
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);




}
#define F_CPU 8000000UL


#define RF_PORT	PORTB
#define RF_DDR	DDRB
#define RF_PIN	PINB

#define SDI		3
#define SCK		5
#define CS		2
#define SDO		4
 
unsigned short rf12_trans(unsigned short wert)
{
    unsigned char i;
	PORTB.2=0;
	for (i=0; i<16; i++)
	{	if (wert&32768)
			PORTB.3=1;
		else
			PORTB.3=0;
		wert<<=1;
		if (RF_PIN&(1<<SDO))
			wert|=1;
		PORTB.5=1;
		#asm("nop");
		#asm("nop");
		PORTB.5=0;
	}
	PORTB.2=1;
	return wert;
}

void rf12_init(void)
{   unsigned char i;
	RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
	RF_PORT=(1<<CS);

	for (i=0; i<50; i++)
		delay_ms(10);			// wait until POR done
	rf12_trans(0xC0E0);			// AVR CLK: 10MHz
	rf12_trans(0x80D7);			// Enable FIFO
	rf12_trans(0xC2AB);			// Data Filter: internal
	rf12_trans(0xCA81);			// Set FIFO mode
	rf12_trans(0xE000);			// disable wakeuptimer
	rf12_trans(0xC800);			// disable low duty cycle
	rf12_trans(0xC4F7);			// AFC settings: autotuning: -10kHz...+7,5kHz
}

void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
	rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}

void rf12_setfreq(unsigned short freq)
{	if (freq<96)				// 430,2400MHz
		freq=96;
	else if (freq>3903)			// 439,7575MHz
		freq=3903;
	rf12_trans(0xA000|freq);
}

void rf12_setbaud(unsigned short baud)
{
	if (baud<664)
		baud=664;
	if (baud<5400)					// Baudrate= 344827,58621/(R+1)/(1+CS*7)
		rf12_trans(0xC680|((43104/baud)-1));	// R=(344828/8)/Baud-1
	else
		rf12_trans(0xC600|((344828UL/baud)-1));	// R=344828/Baud-1
}

void rf12_setpower(unsigned char power, unsigned char mod)
{	
	rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}

void rf12_ready(void)
{    PORTB.3=0;
     PORTB.2=0;
	#asm("nop");
	while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}

void rf12_txdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x8238);			// TX on
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB82D);
	rf12_ready();
	rf12_trans(0xB8D4);
	for (i=0; i<number; i++)
	{		rf12_ready();
		rf12_trans(0xB800|(*data++));
	}
	rf12_ready();
	delay_us(10);
	rf12_trans(0x8208);			// TX off
}

void rf12_rxdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x82C8);			// RX on
	rf12_trans(0xCA81);			// set FIFO mode
	rf12_trans(0xCA83);			// enable FIFO
	for (i=0; i<number; i++)
	{	rf12_ready();
		*data++=rf12_trans(0xB000);
	}
	rf12_trans(0x8208);			// RX off
}

#define F_CPU 8000000UL

unsigned char i;
void send(void);
void receive(void);

void main2(void)
{
	rf12_init();					// ein paar Register setzen (z.B. CLK auf 10MHz)
	rf12_setfreq(RF12FREQ(433.92));	// Sende/Empfangsfrequenz auf 433,92MHz einstellen
	rf12_setbandwidth(4, 1, 4);		// 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm 
	rf12_setbaud(19200);			// 19200 baud
	rf12_setpower(0, 6);			// 1mW Ausgangangsleistung, 120kHz Frequenzshift

	#asm("sei");

	for (;;)
	{
		receive();
	}
}

void receive(void)
{	unsigned char test[32];	
	rf12_rxdata(test,32);	
	lcd_puts(test);
}

void send(void)
{	unsigned char test[]="Dies ist ein 433MHz Test !!!\n   ";	
	rf12_txdata(test,32);
}

- - - Updated - - -

by the way ,this code is for the reciever side

- - - Updated - - -

by the way ,this code is for the reciever side
 

This seems to be a function or a definition that you haven't included, search the library files of rfm12b
 
yeah it was defined in rf12.h header file which was solved by inclusion
now i got 2 warnings:
Warning: E:\REza\codevision save files\New folder (101)\101.c(116): unused function 'rf12_txdata' was removed by the linker
Warning: E:\REza\codevision save files\New folder (101)\101.c(176): unused function 'send' was removed by the linker
which i suppose are given because this one is for the reciever part
now will it work?
i don't have the hardware to test it,,, isn't there anything missing??
 
Last edited:

I have no idea if it will work, I haven't used that modules, I just helped you port a gcc library to codevision
 

tnx anyway
here's my code for reciver & sender,,, it should send word "worked!!" from an atmega8 using rfm12b module to another one and be recieved by an atmega16 and shown on an lcd
i'll try to test it and post the results!

reciever code:
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 12/26/2012
Author  : PerTic@n
Company : If You Like This Software,Buy It
Comments: 


Chip type               : ATmega16L
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include <mega16.h>
#include <stdlib.h>
// Alphanumeric LCD functions
#include <alcd.h>
#include <delay.h>
// Declare your global variables here
#include "rf12.h"

#define F_CPU 8000000UL


#define RF_PORT	PORTB
#define RF_DDR	DDRB
#define RF_PIN	PINB

#define SDI		3
#define SCK		5
#define CS		2
#define SDO		4
 
unsigned short rf12_trans(unsigned short wert)
{
    unsigned char i;
	PORTB.2=0;
	for (i=0; i<16; i++)
	{	if (wert&32768)
			PORTB.3=1;
		else
			PORTB.3=0;
		wert<<=1;
		if (RF_PIN&(1<<SDO))
			wert|=1;
		PORTB.5=1;
		#asm("nop");
		#asm("nop");
		PORTB.5=0;
	}
	PORTB.2=1;
	return wert;
}

void rf12_init(void)
{   unsigned char i;
	RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
	RF_PORT=(1<<CS);

	for (i=0; i<50; i++)
		delay_ms(10);			// wait until POR done
	rf12_trans(0xC0E0);			// AVR CLK: 10MHz
	rf12_trans(0x80D7);			// Enable FIFO
	rf12_trans(0xC2AB);			// Data Filter: internal
	rf12_trans(0xCA81);			// Set FIFO mode
	rf12_trans(0xE000);			// disable wakeuptimer
	rf12_trans(0xC800);			// disable low duty cycle
	rf12_trans(0xC4F7);			// AFC settings: autotuning: -10kHz...+7,5kHz
}

void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
	rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}

void rf12_setfreq(unsigned short freq)
{	if (freq<96)				// 430,2400MHz
		freq=96;
	else if (freq>3903)			// 439,7575MHz
		freq=3903;
	rf12_trans(0xA000|freq);
}

void rf12_setbaud(unsigned short baud)
{
	if (baud<664)
		baud=664;
	if (baud<5400)					// Baudrate= 344827,58621/(R+1)/(1+CS*7)
		rf12_trans(0xC680|((43104/baud)-1));	// R=(344828/8)/Baud-1
	else
		rf12_trans(0xC600|((344828UL/baud)-1));	// R=344828/Baud-1
}

void rf12_setpower(unsigned char power, unsigned char mod)
{	
	rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}

void rf12_ready(void)
{    PORTB.3=0;
     PORTB.2=0;
	#asm("nop");
	while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}

void rf12_txdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x8238);			// TX on
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB82D);
	rf12_ready();
	rf12_trans(0xB8D4);
	for (i=0; i<number; i++)
	{		rf12_ready();
		rf12_trans(0xB800|(*data++));
	}
	rf12_ready();
	delay_us(10);
	rf12_trans(0x8208);			// TX off
}

void rf12_rxdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x82C8);			// RX on
	rf12_trans(0xCA81);			// set FIFO mode
	rf12_trans(0xCA83);			// enable FIFO
	for (i=0; i<number; i++)
	{	rf12_ready();
		*data++=rf12_trans(0xB000);
	}
	rf12_trans(0x8208);			// RX off
}


void send(void);
void receive(void);

void main2(void)
{
	rf12_init();					// ein paar Register setzen (z.B. CLK auf 10MHz)
	rf12_setfreq(RF12FREQ(433.92));	// Sende/Empfangsfrequenz auf 433,92MHz einstellen
	rf12_setbandwidth(4, 1, 4);		// 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm 
	rf12_setbaud(19200);			// 19200 baud
	rf12_setpower(0, 6);			// 1mW Ausgangangsleistung, 120kHz Frequenzshift

	#asm("sei");

	for (;;)
	{
		receive();
	}
}

void receive(void)
{	unsigned char test[32];	
	rf12_rxdata(test,32);	
	lcd_puts(test);
}

void send(void)
{	unsigned char test[]="worked!!";	
	rf12_txdata(test,32);
}

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=0x00;

// Port B 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 
PORTB=0x00;
DDRB=0x00;

// 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 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// USART disabled
UCSRB=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 3
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);

main2();


}

sender code:
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 12/26/2012
Author  : PerTic@n
Company : If You Like This Software,Buy It
Comments: 


Chip type               : ATmega8L
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include <mega8.h>
#include <stdlib.h>
#include <delay.h>
// Declare your global variables here
#include "rf12.h"
// Declare your global variables here
#define F_CPU 8000000UL


#define RF_PORT    PORTB
#define RF_DDR    DDRB
#define RF_PIN    PINB

#define SDI        3
#define SCK        5
#define CS        2
#define SDO        4
unsigned char i; 
unsigned short rf12_trans(unsigned short wert)
{
    unsigned char i;
    PORTB.2=0;
    for (i=0; i<16; i++)
    {    if (wert&32768)
            PORTB.3=1;
        else
            PORTB.3=0;
        wert<<=1;
        if (RF_PIN&(1<<SDO))
            wert|=1;
        PORTB.5=1;
        #asm("nop");
        #asm("nop");
        PORTB.5=0;
    }
    PORTB.2=1;
    return wert;
}

void rf12_init(void)
{   unsigned char i;
    RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
    RF_PORT=(1<<CS);

    for (i=0; i<50; i++)
        delay_ms(10);            // wait until POR done
    rf12_trans(0xC0E0);            // AVR CLK: 10MHz
    rf12_trans(0x80D7);            // Enable FIFO
    rf12_trans(0xC2AB);            // Data Filter: internal
    rf12_trans(0xCA81);            // Set FIFO mode
    rf12_trans(0xE000);            // disable wakeuptimer
    rf12_trans(0xC800);            // disable low duty cycle
    rf12_trans(0xC4F7);            // AFC settings: autotuning: -10kHz...+7,5kHz
}

void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
    rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}

void rf12_setfreq(unsigned short freq)
{    if (freq<96)                // 430,2400MHz
        freq=96;
    else if (freq>3903)            // 439,7575MHz
        freq=3903;
    rf12_trans(0xA000|freq);
}

void rf12_setbaud(unsigned short baud)
{
    if (baud<664)
        baud=664;
    if (baud<5400)                    // Baudrate= 344827,58621/(R+1)/(1+CS*7)
        rf12_trans(0xC680|((43104/baud)-1));    // R=(344828/8)/Baud-1
    else
        rf12_trans(0xC600|((344828UL/baud)-1));    // R=344828/Baud-1
}

void rf12_setpower(unsigned char power, unsigned char mod)
{    
    rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}

void rf12_ready(void)
{    PORTB.3=0;
     PORTB.2=0;
    #asm("nop");
    while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}

void rf12_txdata(unsigned char *data, unsigned char number)
{    unsigned char i;
    rf12_trans(0x8238);            // TX on
    rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB8AA);
	rf12_ready();
	rf12_trans(0xB82D);
	rf12_ready();
	rf12_trans(0xB8D4);
	for (i=0; i<number; i++)
	{		rf12_ready();
		rf12_trans(0xB800|(*data++));
	}
	rf12_ready();
	delay_us(10);
	rf12_trans(0x8208);			// TX off
}

void rf12_rxdata(unsigned char *data, unsigned char number)
{	unsigned char i;
	rf12_trans(0x82C8);			// RX on
	rf12_trans(0xCA81);			// set FIFO mode
	rf12_trans(0xCA83);			// enable FIFO
	for (i=0; i<number; i++)
	{	rf12_ready();
		*data++=rf12_trans(0xB000);
	}
	rf12_trans(0x8208);			// RX off
}


void send(void);
void receive(void);

void main2(void)
{
	rf12_init();					// ein paar Register setzen (z.B. CLK auf 10MHz)
	rf12_setfreq(RF12FREQ(433.92));	// Sende/Empfangsfrequenz auf 433,92MHz einstellen
	rf12_setbandwidth(4, 1, 4);		// 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm 
	rf12_setbaud(19200);			// 19200 baud
	rf12_setpower(0, 6);			// 1mW Ausgangangsleistung, 120kHz Frequenzshift

	#asm("sei");

	for (;;)
	{	send();
		for (i=0; i<100; i++)
			delay_ms(10);
		
	}
}

void receive(void)
{	unsigned char test[32];	
	rf12_rxdata(test,32);	
}

void send(void)
{	unsigned char test[]="worked!!";	
	rf12_txdata(test,32);
}
void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port B 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 
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// 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 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: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// USART disabled
UCSRB=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

main2();
}
 
Last edited:

how to initiate LCD without codevision avr wizard??
 

there are many lcd libraries available (maybe you'll need to make a couple of modificatilns if the are written for a different compiler), try a couple and use the one you like.
 

i've got the lcd working manually but, still don't get any result from rfm12b modules
tried everything , but no luck
it'll be appreciated , if anyone have worked with this modules guide me thorough
tnx
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top