RFM12 Tutorial – Part2

Part 2 – RFM12 Hardware Interface

In this next part of the RFM12 tutorials I’ll be covering the hardware interface, signal descriptions and how you go about hooking it up to the MCU of your choice.

Packages

The RFM12 RF module comes in a couple of different packages, DIP and SMD, I’ll mainly be covering the DIP throughout these series, but will touch on the SMD where necessary. There is also a long range version of the RFM12B, this is the RFM12BP and has a reported range of 3000m. The RFM12BP only comes in an extended SMD package, but I won’t be covering it here in the tutorials, although all of the commands will be the same. The only difference is the RFM12BP has an on board power amp, which requires 12V to power the PA portion and has associated control pins for Tx/RX control.

DIP

The DIP package uses a 6×2 2mm pitch header to connect the various signals to the MCU, The size of this header is a bit of a problem if you want to do prototyping as it doesn’t breadboard well, initially I didn’t have any 2mmm pitch female headers so I hand soldered on individual wires to the back of each pin, not really good in the long run as the wires kept on breaking off, so I designed a breakout board to bring out all the signals onto a standard 100mil pitch, much easier to breadboard.

SMD

There are two version of the SMD module, and from what I can gather the only difference is the crystal, one is the standard HCU form factor, while the other is a ceramic oscillator.

Antenna: The only real difference when using the SMD over the DIP package is there is no on-board antenna connection, the antenna comes out via one of the pins, so you need to design in an antenna connection if using the SMD version.

ARSSI: The SMD package allows access to another useful signal that is not available to the DIP version, this is the ARSSI – Analogue Relative Signal Strength Indicator, which is basically the strength of the signal being received by the module, however it’s not bought out on any of the pins, beats me why? There a digital version of this signal accessible though the software interface, from what I can gather there is a difference from the Digital and Analogue versions of this signal. Anyway what it boils down to if you want to access this analogue signal then you have to manually solder on a wire to access this pad (shown as red circle).

UPDATE:  the onboard DRSSI is a single bit returned in the status word that indicates if the RSSI is above the set threshold.   The ARSSI hack mentioned gives an analogue value that is proportional to the RSSI signal received.

ARSSI Connection

Antenna

The antenna mostly used will probably be a whip antenna, basically a piece of wire cut to the right length, I won’t be covering antenna theory here, as I don’t know it ;), but suffice to say the approx lengths involved are as follows (measured from factory supplied antennas):

433Mhz – 173mm

915Mhz – 87mm

UPDATED: 03/07/2009

These antenna lengths are calculated for the respective bands

433 1/4 wave = 164.7mm
433 1/2 wave = 329.4mm
433 full wave = 692.7mm

868 1/4 wave = 82.2mm
868 1/2 wave = 164.3mm
868 full wave = 345.5mm

915 1/4 wave = 77.9mm
915 1/2 wave = 155.9mm
915 full wave = 327.8mm

With these lengths I’ve had no problem reaching 30m+ indoors through a number of walls and 120m+ outside, I’ve not yet trie different types of antennas such as SMA connected rubber duck type but they should work as I’ve spoken to tech support at HopeRF and they tell me that the antenna circuit on both modules is balanced to 50 Ohm, this means that most SMA rubber duck antennas in the right frequency range will also work. Make sure that the antenna is matched to the frequency range required to get the best range, i.e. don’t use a wifi antenna for 2.4GHZ on a 433Mhz module, it may work for short distances, but definately won’t be optimal for long distances, also you may damage your RF module (unconfirmed it this is is the case as these are low power devices), but usually antennas need to be SWR matched to stop reflectance back into the transmitter circuit.

There is also some technical documents on Hopes website for PCB based antennas, but I’ve not used these at all so your milage may vary with them.

As mentioned earlier the SMD has no direct antenna connection so you need to design in a connection, either a solder pad on your board or an SMA connector.

The DIP package on the other hand allows you to solder in the antenna right onto the module, usually you will solder in the wire directly, however you need to make sure that you get the right pad, as there are two very small solder pads right next to each other, one is the antenna, one is ground, both are not marked in anyway as to to their function, and the documentation does not show which one is which. You need to solder in the piece of wire to the one not connected to ground, best to check with a multimeter or continuity tester first.

It looks as though you can also uses these two pads on the DIP module to connect an external SMA connector with a pigtail to the module as well (both ground and antenna).

PIN Connections

The pin connections for the module is described below, I have indicated whether the connection is required or is optional when making connections. The basic connections as described will allow data rates of up to approx 12000bps on an 8Mhz PIC using a bit-bashed SPI, polled approach when handling sending and receiving data, higher data rates will require hardware SPI, higher MCU speed and the use of interrupts, these will be discussed in a later tutorial.

UPDATE:  Please see this article for more detailed information regarding RFM12B bit rates and the different pin connections.

VDD (required) – The nominal working voltage is between 2.2v and 3.8v (NOT 5V), make sure that you have bypass filters in place on the supply rails.

nINT/VDI (optional) – This pin can be configured as either input or output, if configured as an input then it’s function is an active low interrupt request from the MCU, The MCU pulls this line low if it want to interrupt the RF module.
If configured as an output then its the VDI, Valid Data indicator, meaning valid data has been detected by the receiver and outputs a high. Factory Default is VDI

SDI (required) – SPI Data input, where the MCUs MOSI signal needs to be connected to.

SCK(required) – SPI clock input from MCU

nSEL (required) – Chip Select (active low). This signal must be pulled low before any signal is sent via SPI to the RF module,

SDO (required) – SPI Data out, where the MCU MISO signal needs to be connected to.

nIRQ (optional) – Interrupt Request output (active low), this is when the RF module wans to signal the MCU an event has occurred. This should be tied high with a pullup resistor.

FSK/DATA/nFFS (optional but requires 10K pullup when not used):
FSK – Transmit data input
DATA – Received Data output
nFFS – If pulled high then the FIFO is selected then data is transmited / received via the internal FIFO acessed via the SPI interface. If the FIFO is not being used then this is where the data is directly clocked into or out of the Tranceiver. Use this mode for high datarates.

DCLK/CFIL/FFIT (optional):
DCLK – is the data clock when no FIFO is used (used in conjunction with FSK/DATA/nFFS pin).
CFIL – is used to connect an external capacitor when using 256K datarates, this is for the analogue filter, normally the internal digital filter is used by default, only lower data rates are achieved with the digital filter.
FFIT – FIFO interrupt, interrupt signal is generated whenever the FIFO interrupt level is achieved (level is configured via SPI and is covered in the software interface tutorial), normally the interrupt level would be set to 8 if using the FIFO so that an interrupt is generated for every byte received. If using the FSK/DATA to clock in the data then the interrupt level should be set to 1, this way an interrupt is set for every bit sent/received.

CLK (optional) – Clock output, defaults to 1Mhz, but can be configured in increments up to 10Mhz, or switched off. This signal can be used to provide a clock signal to the MCU if it has no internal oscillator, i.e. cuts down on an additional crystal required for the MCU. This signal is also used in the calibration of the RF modules and will be explained later.

nRES (required) – this is reported in the Hope RF documentation as an output but is really an input (active low) and needs to be tied high at all times. If pulled low it will reset the module back to POR default (power on reset) settings.

GND (required) – Power Ground.

ANT (on SMD, required) – Where the antenna is connected.

Back – Part 1 | Next – Part 3a

Similar Posts:

Print Friendly

Author: Stephen Eaton

Geek at heart. Loves to tinker and find out how things work, which inevitably leads to items in pieces and not working for much longer :)

129 thoughts on “RFM12 Tutorial – Part2”

  1. hi,

    i am checking what u r suggest.The frequency and bit rate settings are the same on both TX and Rx.and also correct bandwidth settings on the Rx. It is greater than the Tx FSK settings.Is there any problem in nIRQ pin or SPI,HAL int..

    1. @volt

      I have found that I need to have a pull up on the NIRQ line for it to work, on the AVR I use the internal pullup for that pin. Also make use that you are reading the status as part of the IRQ handling i.e. cmd 0x0000 this resets the NIRQ on the RFM12, else it will stay low.

      Also don’t have any debug/printf to console in your main RFM12 Tx routines. The delay in Tx can cause the Rx to loose FSK sync.

      Stephen…

  2. Hi,

    do you have any idea how can I debug rfm12? Now, I have a transmitter, which send the data out in a loop and I have a receiver, which should receive the data, but it is only waiting in infinite loop and it doesn’t receive anything.
    What can i do in this situation? How can i check the rfm12 got my instruction via SPI? There is a status register in rfm, is it useful check the value of it?
    Thank you for your help!

    Regards,
    Gyorgy (from Hungary)

    1. @sogyu
      debugging the RFM12 can be frustrating, especially on the RFM12 side of things.

      to debug the SPI here is what I did:

      use an oscilliscope to check that the SPI signals looked ok, i.e. the NSEL is pulled low at the start of the SPI command and being returned high at the end of the SPI sequence. also check that the SCK signals looks ok and you have data going in/out from your MOSI/ MISO pins.

      If these look ok then try sending a command to change the frequency of the CLK pin. By default the Poweron value is 1MHZ (from memory) so put an oscilloscope or frequency counter on the output, then send the command to change to 10Mhz. if the SPI is working then you will see the frequency change to the new value.

  3. @Stephen

    Hi, I am trying to connect two PIC micro controllers using the RFM12B Transceivers and am having an issue with sending consistently. Each time I start up the transmitter and receiver sometimes I can start sending right away, and sometimes it takes a bit for the receiver to start catching the data that is being sent.

    Once NIRQ goes low the receiver will constantly receive data until I pause sending for a brief period of time. I have noticed that after I stop sending for a brief period, if I restart sending I begin to get all garbage values. I have also noticed that once NIRQ goes low it will not go back high even once I have stopped sending data. The data I am sending is 5 quick packets each consisting of a preamble, two sync bytes, 4 data bytes, then 3 dummy bytes. I have tried using the read status command to bring NIRQ back up after the 5 packets send but am still having an issue. Is there a way to reset the entire module or another way to pull NIRQ high using software? Any insight or tips would be greatly appreciated.

    -Thanks
    Matt

  4. @ernieb53

    I would try adding a some more pre-amble bytes as it sounds like a FSK lock issue, i.e. the receiver is not getting FSK lock then sync. I think a single pre-amble is not enough, and adding a preamble as the last couple of bytes in your packet, this allows your Tx register to flush out. I run at least 3-4 preamble bytes and tail my packets with 2 pre-amble bytes e.g. http://code.google.com/p/strobit/wiki/WidgetMesh#Design

    As for NIRQ, I’ve found you need a pull up for it to work properly, either an external resistor or easier still an internal one on your MCU port to pull the signal high. Remember when going into low power mode on your MCU you would need to disable the internal pull ups, before entering, and then re-enable when exiting sleep mode.

  5. @Stephen

    Thanks for the quick response and tips. As it turns out I am not using an interrupt but am just polling the NIRQ pin. I have tried the pull up resistor on both the micro and RF side along with the status read after each byte is read in, but I still never see NIRQ go high again. Could this be fixed if I enable interrupt instead of VDI for the p16 status bit? My preamble and dummy bytes are just how you suggested and the receiver does pick up more promptly. I even tried polling the FFIT instead of NIRQ and have found the same results of valid continuous data until I stop for a moment, then all garbage. If you have any other thoughts I would greatly appreciate any additional help. Thanks so much for the advice you’ve already given

    -Matt

    1. @ernieb53

      I always have P16 set to the POR values which is VDI, the INT is only for external interrupt for the RFM12, i.e. will stop the RFM12 from what its doing.

      The RFM12 interrupt system works by latching the interrupt source and then triggering the NIRQ line if any of these IRQ bits are latched (bits 0 – 5 of the status register), these bits are only cleared by doing a status cmd, so If the NIRQ line is permanently low and you are doing a status command as part of how you are handling the NIRQ state then you may need to read out the result of the status command to find the source of the RFM12 NIRQ is, you may find it’s low voltage or something else causing it, not the actual reception process.

      You might need to post or (email them to me via the contact form ) the commands being sent to the RFM12 as part of your initialisation sequence and then your Rx / Tx routines so I can see what’s happening,

      Also It’s important to remember that when initialising the RFM12 is to set the FIFO level to 8 bits (so when 8 bits get received/transmitted it will cause the FFIT interrupt to trigger) and also before you start any transmission/reception of your packet buffer you need to first disable (this resets the FIFO) and then enable the FIFO, then once everything has been transmitted/received you need to disable the FIFO.

      If you are only polling the NIRQ pin, then an easier way is to run the RFM12 in ‘polled mode’ basically this works during the reception (or Transmission process) by bit-banging a single 0 bit out the SPI and reading the single status bit back (FFIT), if the FFIT is 1 then do what ever, if 0 then do it again until a 1 is read back, (basically the same as doing a status CMD but only a single bit long) you don’t need to read the NIRQ line at all, keep in mind the MCU is tied up polling the RFM12, so not the most efficient.

      Basically sequence is:
      SCK = LOW
      NSEL = LOW
      SDI = LOW
      SCK = HIGH
      read SDO pin
      SCK = LOW
      NSEL = HIGH

      Stephen

  6. @Stephen

    Sorry about the delay, but once again thanks so much for your help. I did start using the FFIT read idea and it is working much better. I’m also going to include my code for transmitter, receiving, and initialization (receiver side).

    INIT

    writeCmd(0x80E7);
    writeCmd(0x8299);
    writeCmd(0xA640); //freq select
    writeCmd(0xC647); //4.8kbps
    writeCmd(0x94A0);
    writeCmd(0xC2AC); //AL,!ml,DIG,DQD4
    writeCmd(0xCA81);
    writeCmd(0xCED4); //SYNC=2DD4;
    writeCmd(0xC483);
    writeCmd(0x9850);
    writeCmd(0xCC17);
    writeCmd(0xE000);
    writeCmd(0xC800);
    writeCmd(0xC040); //1.66MHz,2.2V

    Transmit
    void rfSend(unsigned char data)
    {
    while(!NIRQ);
    writeCmd(0xB800 + data);
    }

    unsigned int writeCmd(unsigned int cmd)
    {
    unsigned char i;
    unsigned int recv;
    recv = 0;
    SCK = 0;
    CS = 0;
    for(i=0; i<16; i++)
    {
    if(cmd&0x8000)
    SDI = 1;
    else
    SDI = 0;
    SCK = 1;
    recv<<=1;
    if( SDO == 1 )
    {
    recv|=0x0001;
    }
    SCK = 0;
    cmd<<=1;
    }
    CS = 1;
    return recv;
    }

    short FFITcheck(void)
    {
    SCK = 1;
    CS = 0;
    if (SDO == 1)
    {
    SCK = 0;
    CS = 1;
    return 1;
    }
    else
    {
    SCK = 0;
    CS = 1;
    return 0;
    }
    }

    Receive
    unsigned char rfRecv()
    {
    unsigned int data;
    while(1)
    {
    data = writeCmd(0x0000);
    if ( (data&0x8000) )
    {
    data = writeCmd(0xB000);
    return (data&0x00FF);
    }
    }
    }

    void FIFOReset()
    {
    writeCmd(0xCA81);
    writeCmd(0xCA83);
    }

    That is most of my code for sending and receiving, and if you see anything that stands out as an obvious issue I would appreciate the help. Thanks so much for all the info so far!

    -Matt

  7. Hi Steve
    Great tutorial info. Just wondering if you can clarify some comments regarding nRST and FSK/DATA/nFFS. You mention that they should be tied high (directly and via 10k respectively) Reading the RF12B datasheet, nRST is a bidirectional pin with an internal pullup, and FSK/DATA/nFFS also has an internal pullup. I’m not worried about the couple of cents, but do they really need the external connections?
    Cheers
    Colin

  8. Hi Steve,

    Thanks for this tutorial, it was very handy in getting this radio module working.

    Just to point out that the RFM12B uses the Si4420 chip from Silicon Labs and is basically the Si4420 chip with the antenna circuitry shown in the Si4420 data sheet. This datsheet contains much more information than the Hoperf’s RF12B.pdf datasheet and actually explains for example how the transmission buffering works.

    From this you can see that it is not actually necessary to send preamble bytes. If the ET bit is off, the two stage transmission buffer pre-loads AA’s into this stage automatically. Once the ET bit gets set high these preamble bytes are sent as the first two bytes. If you want you can add more by pre-pending AAs to your data to tranmit. BTW you can override these two bytes if you write to the transmission register while ET is low (the datasheet shows this as a timing diagram).

    Mark.

  9. Proper Use of AFC:

    It seems to me that the AFC function is very useful to minimise the differece between the tranmitter and receiver frequencies, and hence to allow the minimum receiver bandwidth to be used.

    I’m a little unsure of exactly how the AFC function should be used though. Here is my basic understanding, maybe someone could shed some light on this and whether this is correct:

    When a receiver detects an incoming RF signal that is above it’s programmed VDI threshold the VDI signal goes active. This occurs during the preamble phase before any sync word. If the status word is read immediately VDI goes active (i.e. during the preamble stage), then the lower 3 bits show the frequency offset between the two frequencies, and this can then be programmed into the receiver frequency PLL register to match them. The sync word is then decoded with the receiver PLL now matched to the transmitter’s frequency, and subsequent data received (all further bytes received are not qualified with VDI, so the receiver will continue to receive even if the transmitter is turned off until either the receiver is disabled or the FIFO is reset).

    I’m also unsure about turnaround times between transmit to receive and back again. The datasheet gives a maximum time for these, but is this delay handled automatically by the hardware or does the micro have to add these times to allow it to settle? For example could the user immediately go into receive mode and the hardware prevent reception until the turnaround time has elapsed? Also could the user immediately try to transmit by setting ET after a reception and the hardware hold that transmission off until its internal turnaround time has elapsed?

    One last question: Does anyone know the ppm spec of the crystals used on the RFM12B? If AFC is not used this seems to be an important parameter when calculating the receiver bandwidth to be used.

    Thanks!

    Mark.

  10. I have seen a couple of comments about the RFM12B being based on the Si4420. It might be a minor point but from what I can see the RFM12B is actually based on the Si4421. My reason for thinking this is the 3.8V max supply, no support for 315MHz and flexible sync pattern (1 or 2 bytes) – this is what I have spotted so far. The fact that there are register differences between the Si4420 and RFM12B mean that it is not a good reference.
    Any comments welcome…

  11. i have tested the rfm12bp modules but the problem is with the range , it does not give good range . has anyone field tested it , i have the 915Mhz version . i don’t know if is a noise issue or something else. i have connected the module with a whip antenna . it should have enchanced range , hope rf says they have 800m range.

  12. @colinh

    Yes, I think you’re right. The RFM12 is based on the Si4420, the RFM12B is it seems is based on the Si4421 (the corresponding Hoperf documents for the chips are rf12.pdf and rf12b.pdf respectively). Thanks for pointing it out!

    Mark.

  13. @faizanbrohi

    Not sure what data rate you are using. There is a relationship between data rate and distance, basically for each doubling of the
    data rate the receiver sensitivity reduces by 3dB (roughly). Since power received reduces by 6dB for each doubling of distance this means the distance will reduce by 1/sqrt2, i.e. 0.707. Now you need to know what conditions the 800m is quoted for. You can bet this is at the lowest data rate the chip will handle, and at a releatively high Bit Error Rate (maybe 1E-3).

    Quick calculation: Assuming 800m is quoted at 600 bps, and you used 57600 bps in your app, this is (very roughly) 6 doublings, so your distance will reduce to 1/(6*sqrt2), i.e. again very roughly 1/10. You’ll get 80m, not 800m. And even that is at high BER rate.

    Here’s a useful link:
    http://www.ce-mag.com/archive/02/Spring/cutler2.html

    Mark.

  14. I am transmitting at 4800bps and it has reached 400m with only changing the board from Veroboard and a messy layout to a Well designed PCB one . i also changed the antenna. i am now looking forward to the 433Mhz module to increase the range as it low frequency so greater wavelength . will the low frequency module make a difference ?

  15. Dear All,

    Please help me out with this issue:
    I am reading the status register but getting only 0’s
    This is the init function:
    void RF12_INIT(void) //868MHz!!!
    {
    RFXX_WRT_CMD(0x80E7);//el,ef,868band,12.0pF

    //If both et and er bits are set the chip goes to receive mode.
    RFXX_WRT_CMD(0x8259);//!er,ebb,!et,es,ex,!eb,!ew,DC

    RFXX_WRT_CMD(0xA640);//868MHz
    RFXX_WRT_CMD(0xC647);//4.8kbps
    RFXX_WRT_CMD(0x90C0);//VDI,FAST,67kHz,0dBm,-103dBm
    RFXX_WRT_CMD(0xC2AF);//AL,!ml,DIG,DQD7
    RFXX_WRT_CMD(0xCA81);//FIFO8,SYNC,!ff,DR
    RFXX_WRT_CMD(0xCED4);//SYNC=2DD4
    RFXX_WRT_CMD(0xC483);//@PWR,NO RSTRIC,!st,!fi,OE,EN ??
    RFXX_WRT_CMD(0x9830);//!mp,45kHz,MAX OUT
    RFXX_WRT_CMD(0xCC77);//OB1COB0, LPX,!ddy,DDIT,BW0
    RFXX_WRT_CMD(0xE000);//NOT USE
    RFXX_WRT_CMD(0xC800);//NOT USE
    RFXX_WRT_CMD(0xC000);//1MHz,2.2V

    }//void RF12_INIT(void)
    the write command function:
    unsigned int RFXX_WRT_CMD(unsigned int aCmd)
    {
    unsigned char i;
    unsigned int temp=0;

    _delay_us(10);

    LOW_SCK();
    LOW_SEL();

    _delay_us(10);

    for(i=0;i<16;i++)
    {
    if(aCmd&0x8000)
    HI_SDI();
    else
    LOW_SDI();

    aCmd<<=1;

    _delay_us(40);
    HI_SCK();
    _delay_us(20);

    if(SDO_HI())
    temp|=0x0001;

    temp<<=1;

    _delay_us(20);

    LOW_SCK();
    }//for(i=0;i>8);
    USART_TransmitByte(tmp&0xFF);

    RFXX_WRT_CMD(0xB800+aByte);
    }//void RF12_SEND(unsigned char aByte)

    And a part of main():
    …. RFXX_WRT_CMD(0x8279);//!er,ebb,et,es,ex,!eb,!ew,DC

    //RFXX_WRT_CMD(0xCA81); //init fifo
    //RFXX_WRT_CMD(0xCA83); //enable fifo
    //RFXX_WRT_CMD(0x0000);//read status

    //_delay_ms(5);

    ChkSum=0;

    LEDR_ON();

    RF12_SEND(0xAA);//PREAMBLE

  16. Dear All,

    Please help me out with this issue:
    I am reading the status register but getting only 0’s
    This is the init function:
    void RF12_INIT(void) //868MHz!!!
    {
    RFXX_WRT_CMD(0x80E7);//el,ef,868band,12.0pF

    //If both et and er bits are set the chip goes to receive mode.
    RFXX_WRT_CMD(0x8259);//!er,ebb,!et,es,ex,!eb,!ew,DC

    RFXX_WRT_CMD(0xA640);//868MHz
    RFXX_WRT_CMD(0xC647);//4.8kbps
    RFXX_WRT_CMD(0x90C0);//VDI,FAST,67kHz,0dBm,-103dBm
    RFXX_WRT_CMD(0xC2AF);//AL,!ml,DIG,DQD7
    RFXX_WRT_CMD(0xCA81);//FIFO8,SYNC,!ff,DR
    RFXX_WRT_CMD(0xCED4);//SYNC=2DD4
    RFXX_WRT_CMD(0xC483);//@PWR,NO RSTRIC,!st,!fi,OE,EN ??
    RFXX_WRT_CMD(0x9830);//!mp,45kHz,MAX OUT
    RFXX_WRT_CMD(0xCC77);//OB1COB0, LPX,!ddy,DDIT,BW0
    RFXX_WRT_CMD(0xE000);//NOT USE
    RFXX_WRT_CMD(0xC800);//NOT USE
    RFXX_WRT_CMD(0xC000);//1MHz,2.2V

    }//void RF12_INIT(void)
    the write command function:
    unsigned int RFXX_WRT_CMD(unsigned int aCmd)
    {
    unsigned char i;
    unsigned int temp=0;

    _delay_us(10);

    LOW_SCK();
    LOW_SEL();

    _delay_us(10);

    for(i=0;i<16;i++)
    {
    if(aCmd&0x8000)
    HI_SDI();
    else
    LOW_SDI();

    aCmd<<=1;

    _delay_us(40);
    HI_SCK();
    _delay_us(20);

    if(SDO_HI())
    temp|=0x0001;

    temp<<=1;

    _delay_us(20);

    LOW_SCK();
    }//for(i=0;i<16;i++)

    LOW_SCK();
    HI_SEL();

    return temp;

    }//unsigned int RFXX_WRT_CMD(.. aCmd)

  17. The previous message got scrambled..
    Here is again in two parts
    Write command:
    unsigned int RFXX_WRT_CMD(unsigned int aCmd)
    {
    unsigned char i;
    unsigned int temp=0;

    _delay_us(10);

    LOW_SCK();
    LOW_SEL();

    _delay_us(10);

    for(i=0;i<16;i++)
    {
    if(aCmd&0x8000)
    HI_SDI();
    else
    LOW_SDI();

    aCmd<<=1;

    _delay_us(40);
    HI_SCK();
    _delay_us(20);

    if(SDO_HI())
    temp|=0x0001;

    temp<<=1;

    _delay_us(20);

    LOW_SCK();
    }//for(i=0;i>8);
    USART_TransmitByte(tmp&0xFF);

    RFXX_WRT_CMD(0xB800+aByte);
    }//void RF12_SEND(unsigned char aByte)

  18. I solved the problem, now my concern is that switching between tx/rx takes to long.
    As trying to implement some anti-collision I need to stop tx for a while and check for any rx. Anybody has some ideas ?

    When finished I will make the code public.

  19. @laci

    Great to hear you have it working.

    If you leave the crystal and synthesiser on then the turnaround time from Tx – Rx and visa-versa is 150usec. Initial crystal turn-on time is a couple of mSec so do that at initialisation toggle the et bit.

    You can also the ATS, DQD and RSSI status bits to determine if there is something else transmitting.

    Stephen…

  20. Hello , again , there is some problem with the module when i am using interrupt mode , i am using the following scenario ,

    There is one Gateway ,router, base station or what ever you want or call it , which polls different nodes which are listening. the base station broadcasts an address packet to every node and the corresponding node answers if it matches the address . i have three nodes currently connected to the system .

    Now the problem is that after some time the base station (when it is polling) receives zeroes at the end of every packet and it is consistent. when i introduced a watchdog and when it resets the system the zeroes are gone , but this does not solve the problem it can occur everytime , is it a timing issue , i am using my own interrupt based routine and check nirq for it to go in the external interrupt ISR and the ffit bit for receiving the valid data.

    i have 1 second polling time for each node @ 4800kbps ( which is done under timer ISR ) and about 10 ms switch over time for tx-rx switching , it has enough time.

    I mailed hoperf , they are saying add 10k pullup to the fsk data pin . however it did not solve the problem .

  21. @faizanbrohi

    With your interrupt routing are you checking or handling all status bits? as the interrupt might be generated by something else.

    It’s not safe to assume that when you receive an interrupt that it is from a Tx or Rx event.

    Regards,

    Stephen…

  22. @stephen

    Solved the problem , problem with node synchronization when handling two interrupts (timer and external), a programming bug not the rf issue. Thanks

  23. hi stephen, I just started to work with the RFM12b and the pic 16F87. is the first time I do program a device, so I would like to know wich compiler could i use.

  24. hi stephen, I just started to work with the RFM12b and the pic 16F873a. is the first time I do program a device, so I would like to know wich compiler could i use.

  25. @Stephen

    I “reloaded” the rfm project, and still struggling with the rx/tx mode switch.
    Before I issue the actual command
    RFXX_WriteCommand(0x8279);//!er,ebb,et,es,ex,!eb,!ew,DC
    or
    RFXX_WriteCommand(0x82D9);//er,ebb,!et,es,ex,!eb,!ew,DC

    I wait for the Status bit FFIT to be 1.
    The problem is that the device switches to RX mode very slow, do you have any idea why?

    Regards,
    Laci

  26. hi all, i use rfm12b to transmit data from a PC to another one by rs232. most of my code from hope rf.
    PC1–(1)–>MCU1–(2)–>RF1—(3)—>RF2–(2)–>MCU2–(1)–>PC2
    but i’m puzzling with the bitrate among these devices.
    as u see on the simple diagram above.
    (1) : bitrate between PC and MCU
    (2) : bitrate between MCU and RF
    (3) : bitrate between RF and RF

    acorrding hope code,
    writeCmd(0xC647); //4.8kbps
    data rate (3) is 4800bps.

    is it necessary to be the same among them?

    hearing from you soon!

  27. @ Stephen 89

    I’ve set up a system using two rfm12 to transfer data from one node to another but it’s still not worked at all. I also used a electromagnetic energy device to detect the magnetic field but maybe that device was not sensitive enogh!!!
    Would you mind telling me how to check if rf really sent out a frame?

    may a oscilloscope can kick this problem?

    thanks a lot!

  28. @laci,

    100mSec would seem long as a turn around time.

    make sure you’re not tuning off the whole power chain when you change from Tx-Rx and vis-versa. If you want a fast turn-around then you need to already have the crystal oscillator and synthesiser turned on (part of your wakeup?).

    Once initialised you should only need to toggle the er bit in the power control register(0x8208h) if both et and er are on then er takes precedence.

    check out the turnaround timing in the datasheet (bottom page 10 on my sheet), in theory you should be achieving 150uSec turnaround times if you already have the synthesiser and crystal on.

    Stephen…

  29. @realheaven

    AFAIK a spectrum analysers would be the only thing to see if you are transmitting on the wireless side of things. An oscilloscope would cause too much load on the circuit and then it won’t work, also the frequencies involved would be a high end oscilliscope.

    You need to confirm your SPI is talking to the RFM12 first. An easy test is to send the comand to change the Cystal output frequency and measure with an oscilloscope or frequency counter.

    If your having Tx Rx problems make sure you don’t have any debug printf etc in your transmit routines, just queue up your Tx buffer and then start the Tx sequence until your buffer is empty.

    If there are any delays in this Tx sequence then the receiver will loose sync and will not receive anything.

    Stephen…

  30. @Stephen,

    I am changing just the et/er bits in the power managment command

    this is my function:
    unsigned char RF12_SetMode(unsigned char SetMode)
    {
    static unsigned char timeout_cnt=0;
    unsigned char RFXX_Response;

    RFXX_Response=RFXX_WaitReady();

    if( (SetMode==TX_MODE)&&(mode==RX_MODE) )
    {
    //Fill the TX with 0xAAAA preamble key
    RFXX_WriteCommand(0x8279);//!er,ebb,et,es,ex,!eb,!ew,DC
    _delay_ms(1); //RX/TX switch time
    mode = TX_MODE; //switch to tx mode
    RFXX_WriteCommand(0xCA81); //reset fifo
    }
    else
    if( (SetMode==RX_MODE)&&(mode==TX_MODE) )
    {
    RFXX_WriteCommand(0x82D9);//er,ebb,!et,es,ex,!eb,!ew,DC
    _delay_ms(1); //RX/TX switch time
    mode = RX_MODE; //switch to rx mode
    RFXX_WriteCommand(0xCA81); //reset fifo
    }

    if(timeout_cnt == RFXX_SET_MODE_TIMEOUT) //prevent infinit blocking
    {
    RFXX_Response=RFXX_READY;
    timeout_cnt=0;
    }

    if(RFXX_Response != RFXX_READY)
    {
    timeout_cnt++;
    return RFXX_TIMEOUT_ERR;
    }
    else
    return mode;
    }//unsigned char RF12_SetMode(unsigned char SetMode)

  31. @ Stephen 93

    thanks so much for your support. I checked my SPI interace and there was no trouble with it.
    I gotta read the status register to comfirm that i can manage the rf completely.
    There is a simple code to read the status register is :
    writeCmd(0x0000) // form hope guide

    but i failed in this section

    is that enogh to read status register by a sigle command like that?

  32. here’s my complete code

    // rs232 Init
    void Tx(unsigned char data)
    {
    while(!(UCSRA & (1<<UDRE)));
    UDR=data;
    }
    // write command function
    unsigned int writeCmd(unsigned int cmd) {
    unsigned char i;
    unsigned int recv;
    recv = 0;
    LO(SCK);
    LO(CS);
    for(i=0; i<16; i++) {
    if(cmd&0x8000) HI(SDI); else LO(SDI);
    HI(SCK);
    recv<<=1;
    if( PINB&(1<<SDO) ) {
    recv|=0x0001;
    }
    LO(SCK);
    cmd<<=1;
    }
    HI(CS);
    return recv;
    }

    to be continued…

  33. void rfInit() {
    writeCmd(0x80F8); //EL,EF,915band,12.5pF
    writeCmd(0x8239); //!er,!ebb,ET,ES,EX,!eb,!ew,DC
    writeCmd(0xAA6B); //frequency select
    writeCmd(0xC647); //bit rate = 4.8kbps
    writeCmd(0x94C2); //VDI,FAST,BW=67kHz,0dBm,-91dBm
    writeCmd(0xC2AC); //AL,!ml,DIG,DQD4
    writeCmd(0xCA81); //FIFO8,SYNC,!ff,DR
    writeCmd(0xCED4); //SYNC=2DD4G
    writeCmd(0xC483); //@PWR,NO RSTRIC,!st,!fi,OE,EN
    writeCmd(0x9820); //!mp,deviation=45kHz,MAX OUT
    // writeCmd(0xCC17); //OB1COB0, LPX,IddyCDDITCBW0
    writeCmd(0xE000); //NOT USE
    writeCmd(0xC800); //NOT USE
    writeCmd(0xC040); //1.66MHz,2.2V
    }

    void main()
    {
    volatile unsigned int data;
    #asm(“cli”);
    delay_ms(1000);
    rsInt();
    portInit();
    rfInit();

    data=writeCmd(0x0000);
    Tx(data);
    }
    status register value form hyperterminal : 00 00 00 00…
    please help me in this case

  34. what funny!
    when rf in Tx mode, i got a static valaue form status register is A100. but when i toggled it into Rx mode i got more than one value!?! for ex : 0000, 0120, 0020 and several strange values : 0040, 0044, 0067!?!

    i note that there are two bits in status register having value changing are RSSI and ATGT.

    anybody can explain why in Rx mode there are lots of diffrent values when reading status register? expecially bit RSSI & ATGT

  35. at least my network works! i feel so happy! it’s worth to try hard rite! 😉
    but who can tell me why toggling between TX/RX & RX/TX take so so long time. I must to delay 500ms to guagrante receiving all packets whereas hoperf say that it takes 150us!?!
    thanks a lot!

  36. @realheaven

    Glad you got it all working, what ended up being your problem?

    One of the other members (laci) is also having problems with the turnaround time from Tx/RX as well, you might want to chat with him to see if a solution was found. Unfortunately I not currently in the position to do any testing for some time so I see why there is a delay.

Leave a Reply