My RFM12 doesn,t work !!!!

RFM12 Wireless module discussion.

My RFM12 doesn,t work !!!!

Postby ajchavez1 » Thu Oct 02, 2008 9:38 pm

I've programmed a PIC182520 using the following code -extremely simple, by the way- but it doesn't work, even though they were based in the routines published in everything robotics. The STATUS register goes crazy responding 0xA100 as transmitter and changing between 0x03FE ~ 0x 03E0 ~ 0x03DF ~ 0x03DE ~ etc as receiver. Please, check my code and tell me if I have something wrong: :? ...

/////////////////////////////////////////////////////////////////////////////////////////////////////////
LIBRARY
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "rfm12.h"
#include "delay4MHZ.h"
#include "general.h"
#include "serial.h"

Tubuf buffer;

void ini_RFM12(void)
{
SDI_hope_io=0; // SDI Port RFM12 (Serial Data input)
SDI_hope=0; // Output
SCK_hope_io=0; // SCK Port RFM12 (Serial Data Clock)
SCK_hope=0; // Output ( Default 0)
nSEL_hope_io=0; // nSEL Port RFM12 (Chip Select -active low-)
nSEL_hope=1; // Output (Default 1)
SDO_hope_io=1; // SDO Port RFM12 (Serial Data output) Input
delay_ms(2000); // Waiting Two seconds!!!!! while the module starts
WriteCMD(0x80D7); // EL,EF,433band,12.0pF
#ifdef RFMTX
WriteCMD(0x8239); // !er,!ebb,ET,ES,EX,!eb,!ew,DC ...TX
#endif
#ifdef RFMRX
WriteCMD(0x82D9); // er,ebb,!ET,ES,EX,!eb,!ew,DC ...RX
#endif
WriteCMD(0xA640); // 434MHz
WriteCMD(0xC647); // 4.8kbps
WriteCMD(0x94A0); // VDI,FAST,134kHz,0dBm,-103dBm
WriteCMD(0xC2AC); // AL,!ml,DIG,DQD4
WriteCMD(0xCA81); // FIFO8,SYNC,!ff,DR
WriteCMD(0xCED4); // SYNC=2DD4;
WriteCMD(0xC483); // @PWR,NO RSTRIC,!st,!fi,OE,EN
WriteCMD(0x9850); // !mp,90kHz,MAX OUT
WriteCMD(0xCC77); // OB1,OB0, LPX,!ddy,DDIT,BW0
WriteCMD(0xE000); // NOT USE
WriteCMD(0xC800); // NOT USE
WriteCMD(0xC040); // 1.66MHz,2.2V
delay_ms(2000); // Waiting Two seconds!!!!! while the module starts
}

*******************************************************************************//
unsigned int WriteCMD(unsigned int CMD)
{
unsigned int RESULT=0; // Save the received data SPI
unsigned char n=16; // Bits Number to send
nSEL_hope=0; // nSEL (CS) LOW
while(n--) // Sends 16 bits (MSB first)
{
if (CMD&0x8000) // Check MSB
SDI_hope=1; // Writes 1
else
SDI_hope=0; // Writes 0
SCK_hope=1; // Clock bit
RESULTADO<<=1; // Shift left for next bit
if(SDO_hope==1) // Check if receive 1
RESULT |= 0x0001; // RESULT LSB = 1
CMD<<=1; // Shift left for next bit
SCK_hope=0; // clock
}
nSEL_hope=1; // nSEL (CS) LOW -finished command-
delay_ms(100);
return RESULT;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
MAIN
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
CONF_PORTS(); // Ports Conf
CONF_OSC(); // Osc Conf
CONF_T0(); // Timer Conf
conf_serial(25);
GIE=1; // Global Interrupt Activation
ini_RFM12();

while(1)
{
#ifdef RFMTX
WriteCMD(0x0000);
WriteCMD(0xB8AA);
WriteCMD(0xB8AA);
WriteCMD(0xB8AA);
WriteCMD(0xB82D);
WriteCMD(0xB8D4);
WriteCMD(0xB832);
WriteCMD(0xB878);
#endif
#ifdef RFMRX
WriteCMD(0x0000);
WriteCMD(0xB000);
WriteCMD(0xCA81);
WriteCMD(0xCA83);
#endif

delay_ms(200);
RB5=!RB5;
}
}

I really appreciate your help... I've have working without success like 4 days!!!!

Regards, Albert
ajchavez1
 
Posts: 1
Joined: Thu Oct 02, 2008 7:00 pm

Re: My RFM12 doesn,t work !!!!

Postby seaton » Fri Oct 03, 2008 10:07 am

First things first....is your SPI routines working between the MCU and the RFM12? these need to be working before anything else works.

I found the best way to test the SPI if you don't have a Logic analyser is to change the frequency of the RFM CLK pin and monitor it on a CRO.

As a note the routines I've posted are only bit bashed, I couldn't get the hardware SPI working sending out a 16 bit command, I did it as x2 8 bytes sent as close together as I could, but the RFM12 did not like the delay in between the 2 bytes pause that was caused by the routines I was using.

Make sure the the CS is going LOW before each CMD is sent and goes high right after the command is finished.

Also make sure you have good voltage supply with good decoupling, the RFM12B is a 3.3v device (although my development platform is running at 5 and it all works ok), the RFM12 is a 5v device

Once you have have the SPI working then the next thing is to get them talking at a low baud rate, say 9600, using the settings I've posted in the working code, then build up from there, i.e. checksum, higher speed, bigger packets and so on

The problem is what comes first? the chicken or the egg? (as far the the Tx/Rx goes). I found the HopeRF Demo unit invaluable in this respect as I could switch it to just transmit while I worked on my Rx code, and visa versa with the Tx side of things, however not everyone has this and alot of users have got theirs working without one.

The Tx is the easiest to get going, but you need to have your characters ready for transmission before you enable the Tx side of things, the receiver will loose lock/sync if it does not have a continuous stream of data coming in. Then you need to sent the preamble and Sync bytes again.

Before transmission begins I load the 2 registers with preamble (0xAA) and appended to the end of my packet I also have the preamble, so when I turn off the Tx there will be preamble in the rtx register ready for next transmission.

The Rx is more tricky and is more like a wing and a prayer, but make sure that the Rx bandwidth is larger than the Tx deviation, the code has good starting values that work reliably for 915MHZ, should be any different for 433MHZ except the Frequency. The example code posted works in polling mode, not interrupt mode so it is looking for a change of the first bit returned of the status register, i.e. clk out a 0 on MOSI and read the bit returned on MISO, if 0 then nothing received, if 1 then read and handle the byte. Before enabling the Rx make sure that you reset and clear the FIFO.

The code I posted does work for the PIC16F84, so there may be some timing issues etc with the MCU you are using, make sure that the SPI signals are getting to the RFM12, i.e. CLK, MOSI, CS MISO

Really start off with little steps and build upon them.

Let me know how you go (I will be without internet access fover the next 4-5 days)

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

Re: My RFM12 doesn,t work !!!!

Postby hottube » Mon Oct 06, 2008 8:08 pm

seaton wrote:As a note the routines I've posted are only bit bashed, I couldn't get the hardware SPI working sending out a 16 bit command, I did it as x2 8 bytes sent as close together as I could, but the RFM12 did not like the delay in between the 2 bytes pause that was caused by the routines I was using.


I got this working on a atmega168/ avr-gcc
RFM12 is sharing SPI with an DOG LCD Display

init for SPI:
// aktivate SPI, Master, clock rate fck/2 (clk = 5MHz)
SPCR = (1<<SPE)|(1<<MSTR) |(1<<SPI2X); //|(1<<SPR0);
DDRB = (1<<LCD_RS) | (1<<LCD_CS) | (1<<RFM12_CS) | (1<<SPI_MOsi) | (1<<SPI_SCK) | (1<<Buzzer); // Set output Port B

Code for sending SPI to RFM12

unsigned short rf12_trans(unsigned short wert)
{ unsigned char wertupp, wertlow;

wertupp = wert >> 8; //cut to high and low byte
wertlow = wert & 0xFF; // take low byte

RF_PORT &= ~(1 << CS); // RFM12 CS active low

SPDR = wertupp; // start transfer
while(!(SPSR & (1<<SPIF))); // wait until ready
wertupp=SPDR;

SPDR = wertlow; // start transrer
while(!(SPSR & (1<<SPIF))); // wait until ready
wertlow=SPDR;

RF_PORT |= (1 << CS); // RFM12 disable

wert = (wertupp << 8) | wertlow; // join return value
return wert;
}


It does the job but still can be enhanced to gain a higer transfearrate
hottube
 
Posts: 2
Joined: Mon Oct 06, 2008 12:21 pm
Location: Germany near Frankfurt

Re: My RFM12 doesn,t work !!!!

Postby seaton » Mon Oct 13, 2008 9:17 am

hottube wrote:
I got this working on a atmega168/ avr-gcc
RFM12 is sharing SPI with an DOG LCD Display

It does the job but still can be enhanced to gain a higer transfearrate


Thanks for that, have moved over to AVR from PIC and when I get some time I'll be playing with it and the RFM12B

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