Problem with RFM12 and ATmega8(very urgent,pls help us)

RFM12 Wireless module discussion.

Problem with RFM12 and ATmega8(very urgent,pls help us)

Postby src_virus » Thu Oct 16, 2008 1:26 pm

We are trying to send and recieve data using two RFM12 modules(One is transmitting and another is recieving). ATmega8 is used to control the radio modules. But the system is not working properly.

In the recieving end:

1. VDI is rapidly changing state between high and low
2. FFIT bit of RFM12 is never set(FIFO interrupt level is set to 1 bit).
3. No data is recieved

Reciever code:
Code: Select all
#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>

#define INPUT 0
#define OUTPUT 1

#define PORT_SS PORTB //PB2
#define PIN_SS PINB
#define DDR_SS DDRB

#define PORT_MOSI PORTB //PB3
#define PIN_MOSI PINB
#define DDR_MOSI DDRB

#define PORT_INT0 PORTD//PD2
#define PIN_INT0 PIND
#define DDR_INT0 DDRD

#define PORT_SCK PORTB//PB5
#define PIN_SCK PINB
#define DDR_SCK DDRB

#define PORT_MISO PORTB//PB4
#define PIN_MISO PINB
#define DDR_MISO DDRB

#define PORT_DATA PORTD//PD4
#define PIN_DATA PIND
#define DDR_DATA DDRD

#define PB7_OSC 7
#define PB6_OSC 6
#define PB5_SCK 5
#define PB4_MISO 4
#define PB3_MOSI 3
#define PB2_SS 2
#define PD2_INT0 2
#define PD4_DATA 4
#define PB1_NC 1
#define PB0_NC 0

#define LED5_OFF() PORTD &= ~( 1 << 5 )
#define LED5_ON() PORTD |= ( 1 << 5 )
#define LED6_OFF() PORTD &= ~( 1 << 6 )
#define LED6_ON() PORTD |= ( 1 << 6 )
#define LED7_OFF() PORTD &= ~( 1 << 7 )
#define LED7_ON() PORTD |= ( 1 << 7 )


void powerOnIndicator()
{
   LED5_ON();
   LED6_ON();
   LED7_ON();

   _delay_ms(3000);
   
   LED5_OFF();   
   LED6_OFF();
   LED7_OFF();   

   _delay_ms(3000);
}

void microcontrollerPortInit()
{
   DDR_SS |= ( 1 << PB2_SS );   // SS pin output
   DDR_MOSI |= ( 1 << PB3_MOSI );// MOSI pin output
   DDR_MISO &= ~( 1 << PB4_MISO ); //MISO pin input
   DDR_SCK |= ( 1 << PB5_SCK ); // SCK pin output

   PORT_SS &= ~( 1 << PB2_SS); //port SS 0
   PORT_MOSI &= ~( 1 << PB3_MOSI );//port MOSI 1
   PORT_SCK &= ~( 1 << PB5_SCK ); //port SCK 0

   DDRD |= ( 1 << 5 ); //led pin direction output
   DDRD |= ( 1 << 6 );
   DDRD |= ( 1 << 7 );

   //DDRB &= ~( 1 << 7 );

   DDRC = 0xFF; //recieved data pin output
   PORTC = 0xFF;

   DDR_INT0 &= ~( 1 << PD2_INT0 ); //InT0 pin input
}


unsigned int writeCommandToRFM(unsigned int command)
{
   unsigned char i;
   unsigned int rev;//recived value
   rev = 0;

   PORT_SCK &= ~( 1 << PB5_SCK );   //sck low
   //PORT_SS &= ~( 1 << PB2_SS );   //ss low

   for(i = 0 ; i < 16 ; i++ )
   {
       PORT_SCK &= ~( 1 << PB5_SCK );//sck low
      if( command & 0x8000 )
      {
         PORT_MOSI |= ( 1 << PB3_MOSI ); // MOSI hi
      }
      else
      {
         PORT_MOSI &= ~( 1 << PB3_MOSI ); // MOSI low
      }
      
      PORT_SCK |= ( 1 << PB5_SCK ); //SCK hi

      rev <<= 1;
      if (PIN_MISO & (1 << PB4_MISO))
      {
         rev |= 0x0001;
      }

      command <<= 1;
   }

   //_delay_ms(10);
   PORT_SCK &= ~( 1 << PB5_SCK ); //SCK low
   //PORT_SS |= ( 1 << PB2_SS); //port SS hi

   return rev;
}

void RFMInit()
{
   //writeCommandToRFM(0x80D7);//TX,RX FIFO buffer,433,12.0
   writeCommandToRFM(0x80D8);//TX,RX FIFO buffer,433,12.5
   writeCommandToRFM(0x8218);//!er,!ebb,!et,es,ex,!eb,!ex,!dc
   //writeCommandToRFM(0x8209);//!er,!ebb,!et,!es,ex,!eb,!ex,dc
   writeCommandToRFM(0xA640);//434MHz
   writeCommandToRFM(0xC647);//4800bps
   //writeCommandToRFM(0xC68F);//2400bps
   //writeCommandToRFM(0xC6A3);//1200bps
   writeCommandToRFM(0x94A0);//VDI,fast,134KHz,0db - 103 db
   //writeCommandToRFM(0x94A0);//VDI,fast,67KHz,0db - 103 db
   //writeCommandToRFM(0xC2AC);//auto lock,slow,digital,DQD4
   writeCommandToRFM(0xC22C);//!auto lock,slow,digital,DQD4
   writeCommandToRFM(0xCA11);//8 bits,2DD4H,!iff,dr
   //writeCommandToRFM(0xC483);//!fi
   writeCommandToRFM(0xC4F7);//POR value,fi
   writeCommandToRFM(0x9850);//frequency deviation = 90kHz
   //writeCommandToRFM(0x9820);//frequency deviation = 45kHz
   writeCommandToRFM(0xE000);
   writeCommandToRFM(0xC800);
   writeCommandToRFM(0xC040);

}

unsigned char recieve()
{
   unsigned int data;
   unsigned int status;

   while(1)
   {
      
      status = writeCommandToRFM(0x0000);//read FIFO status
      

      if( status & 0x8000 )
      {
         data = writeCommandToRFM(0xB000);//FIFO read command
         //LED6_ON();
         
         return ( data & 0x00FF );
      }
      /*status = PINB;
      if( status & 0x0080 )
      {
         data = writeCommandToRFM(0xB000);//FIFO read command
         LED6_ON();
         LED7_ON();
         _delay_ms(3000);
         LED6_OFF();
         LED7_OFF();
         LED5_OFF();
         return ( data & 0x00FF );
      }*/
   }
   
   /*while( PIN_INT0 & ( 1 << PD2_INT0 ) );
//   LED6_ON();
   writeCommandToRFM(0x0000);
   data = writeCommandToRFM(0xB000);//FIFO read command
   return ( data & 0x00FF );*/
}

void main()
{
   unsigned char i;
   unsigned char checkSum;

   //cli();

   microcontrollerPortInit();

   LED5_OFF();
   LED6_OFF();
   LED7_OFF();

   powerOnIndicator();

   LED5_OFF();
   LED6_OFF();
   LED7_OFF();

   RFMInit();

   writeCommandToRFM(0xCA11);//initialize FIFO
   //writeCommandToRFM(0xCA11);

   while(1)
   {
      checkSum = 0;

      LED5_ON();
      //_delay_ms(3000);
      //LED5_OFF();
      
      //writeCommandToRFM(0x0000);
      writeCommandToRFM(0x82D8);//reciever ON
      writeCommandToRFM(0xCA13);//enable FIFO
      //writeCommandToRFM(0xCA13);
      

      checkSum += recieve();
      LED6_ON();
      i = recieve();
      
      //writeCommandToRFM(0x8209);
      writeCommandToRFM(0xCA11);//reset FIFO
      //writeCommandToRFM(0xCA11);

      if( checkSum == i ) //checking
      {
         LED5_OFF();
      }

       PORTC = checkSum;
      _delay_ms(1);
      LED7_ON();
      
   }
}


Transmitter code:

Code: Select all
#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>

#define INPUT 0
#define OUTPUT 1

#define PORT_SS PORTB
#define PIN_SS PINB
#define DDR_SS DDRB

#define PORT_MOSI PORTB
#define PIN_MOSI PINB
#define DDR_MOSI DDRB

#define PORT_INT0 PORTD
#define PIN_INT0 PIND
#define DDR_INT0 DDRD

#define PORT_SCK PORTB
#define PIN_SCK PINB
#define DDR_SCK DDRB

#define PORT_MISO PORTB
#define PIN_MISO PINB
#define DDR_MISO DDRB

#define PB7_OSC 7
#define PB6_OSC 6
#define PB5_SCK 5
#define PB4_MISO 4
#define PB3_MOSI 3
#define PB2_SS 2
#define PD2_INT0 2
#define PB1_NC 1
#define PB0_NC 0

#define LED5_OFF() PORTD &= ~( 1 << 5 )
#define LED5_ON() PORTD |= ( 1 << 5 )
#define LED6_OFF() PORTD &= ~( 1 << 6 )
#define LED6_ON() PORTD |= ( 1 << 6 )
#define LED7_OFF() PORTD &= ~( 1 << 7 )
#define LED7_ON() PORTD |= ( 1 << 7 )

void powerOnIndicator()
{
   LED5_ON();
   LED6_ON();
   LED7_ON();

   _delay_ms(3000);

   LED5_OFF();   
   LED6_OFF();
   LED7_OFF();   

   _delay_ms(3000);

}


void microcontrollerPortInit()
{
   DDR_SS |= ( 1 << PB2_SS );   // SS pin output
   DDR_MOSI |= ( 1 << PB3_MOSI );// MOSI pin output
   DDR_MISO &= ~( 1 << PB3_MOSI );// MISO pin input
   DDR_SCK |= ( 1 << PB5_SCK ); // SCK pin output

   PORT_SS &= ~( 1 << PB2_SS); //port SS 1
   PORT_MOSI &= ~( 1 << PB3_MOSI );//port MOSI 1
   PORT_SCK &= ~( 1 << PB5_SCK ); //port SCK 0

   DDRD |= ( 1 << 5 ); //led pin direction output
   DDRD |= ( 1 << 6 );
   DDRD |= ( 1 << 7 );

   DDR_INT0 &= ~( 1 << PD2_INT0 ); //InT0 pin input

}

unsigned int writeCommandToRFM(unsigned int command)
{
   unsigned char i;
   unsigned int rev;//recived value
   rev = 0;

   PORT_SCK &= ~( 1 << PB5_SCK );   //sck low
   //PORT_SS &= ~( 1 << PB2_SS );   //ss low

   for(i = 0 ; i < 16 ; i++ )
   {
       PORT_SCK &= ~( 1 << PB5_SCK );//sck low
      if( command & 0x8000 )
      {
         PORT_MOSI |= ( 1 << PB3_MOSI ); // MOSI hi
      }
      else
      {
         PORT_MOSI &= ~( 1 << PB3_MOSI ); // MOSI low
      }
      
      PORT_SCK |= ( 1 << PB5_SCK ); //SCK hi

      rev <<= 1;
      if (PIN_MISO & (1 << PB4_MISO))
      {
         rev |= 0x0001;
      }

      command <<= 1;
   }

   //_delay_ms(10);
   PORT_SCK &= ~( 1 << PB5_SCK ); //SCK low
   //PORT_SS |= ( 1 << PB2_SS); //port SS hi

   return rev;
}

void RFMInit()
{
   //writeCommandToRFM(0x80D7);//TX,RX FIFO buffer,433,12.0
   writeCommandToRFM(0x80D8);//TX,RX FIFO buffer,433,12.5
   writeCommandToRFM(0x8218);//!er,!ebb,!et,es,ex,!eb,!ex,!dc
   //writeCommandToRFM(0x8209);//!er,!ebb,!et,!es,ex,!eb,!ex,dc
   writeCommandToRFM(0xA640);//434MHz
   writeCommandToRFM(0xC647);//4800bps
   //writeCommandToRFM(0xC68F);//2400bps
   //writeCommandToRFM(0xC6A3);//1200bps
   writeCommandToRFM(0x94A0);//VDI,fast,134KHz,0db - 103 db
   //writeCommandToRFM(0x94A0);//VDI,fast,67KHz,0db - 103 db
   //writeCommandToRFM(0xC2AC);//auto lock,slow,digital,DQD4
   writeCommandToRFM(0xC22C);//!auto lock,slow,digital,DQD4
   writeCommandToRFM(0xCA11);//8 bits,2DD4H,!iff,dr
   //writeCommandToRFM(0xC483);//!fi
   writeCommandToRFM(0xC4F7);//POR value,fi
   writeCommandToRFM(0x9850);//frequency deviation = 90kHz
   //writeCommandToRFM(0x9820);//frequency deviation = 45kHz
   writeCommandToRFM(0xE000);
   writeCommandToRFM(0xC800);
   writeCommandToRFM(0xC040);

}

void transmit(unsigned char data)
{
   
   while( PIN_INT0 & ( 1 << PD2_INT0 ) );
   
   LED6_ON();
   writeCommandToRFM(0xB800 + data);
   
}

void main()
{
   //int i,j;
   unsigned char checkSum;

   //cli();
   //#asm("cli");
   microcontrollerPortInit();

   LED5_OFF();
   LED6_OFF();
   LED7_OFF();

   powerOnIndicator();

   LED5_OFF();
   LED6_OFF();
   LED7_OFF();

   RFMInit();

   while(1)
   {
      LED5_ON();
      //_delay_ms(500);
      //LED5_OFF();

      checkSum = 0;
      
      writeCommandToRFM(0x0000); //read status reg
      writeCommandToRFM(0x8238); // transmitter ON
      
      transmit(0xAA);//preamble
      transmit(0xAA);
      transmit(0xAA);

      transmit(0x2D);//sync hi byte
      transmit(0xD4);//sync low byte


      transmit(0xFF);  //data
      checkSum += 0xFF;

      transmit(checkSum); //checksum send

      transmit(0xAA);//dummy byte
      transmit(0xAA);
      transmit(0xAA);   

      writeCommandToRFM(0x8218); // transmitter OFF

      LED7_ON();
      //_delay_ms(500);
      //LED7_OFF();
      
   }
}


pls help us , we need to submit this project within 3 days.
src_virus
 
Posts: 1
Joined: Thu Oct 16, 2008 1:12 pm

Re: Problem with RFM12 and ATmega8(very urgent,pls help us)

Postby seaton » Fri Oct 17, 2008 5:05 am

Sorry I haven't used the RFM12 with the AVR as yet so I don't have any working code, I think someone posted a link to an online library for the RFM12 but the site is in German.

What module are you using, SMD or the DIP version? I'm assuming the DIP version, if so make sure that you have the antenna in the right hole on the board, they are unlabelled so you need to check with a multimeter what is GND and what is not.

I'm also assuming that your SPI is working as you can read the status register.

I found the hardest thing in getting these going was the settings so Try the following as a starting point and fine tune it from there:

Frequency: whatever, but obviously the same on Tx and Rx
Datarate: 9600bps

Tx:
45KHz deviation

Rx:
67KHz bandwith
Also as a starting point for the receiver set your AFC set to auto offset
independent of VDI, +3/-4 max dev, fine mode, enable offset register, enable
calculation of offset. Set your datafilter to auto mode, clock recover set,
digital filter, DQD threshold is 4.


Hope this helps,

Stephen...
seaton
Site Admin
 
Posts: 134
Joined: Mon Jan 23, 2006 8:48 am
Location: Bunbury, Western Australia


Return to RFM12

Who is online

Users browsing this forum: No registered users and 1 guest

cron