DIY :- Wireless Chat Using RFM70

DIY: - Do It Yourself

Wireless Data TransmissionWireless Chat using RFM70


RFM70 is a GFSK transceiver module operating in the world wide ISM frequency band at 2400 - 2483.5 MHz. Burst mode transmission and up to 2Mbps air data rate make them suitable for applications requiring ultra low power consumption.

The embedded packet processing engines enable their full operation with a very simple MCU as a radio system. Auto re-transmission and auto acknowledge give reliable link without any MCU interference.

Block Diagram:-

Block diagram
[FONT=&amp]
[/FONT]


This is the basic Block Diagram for the project in which you have to catch the data from any device or you can use Personal Computer or Laptop to send the data for that you need to interface the Computer with the project board and here it is Serial Communication as now a days serial port are not available on Laptop you can also use USB to Serial cable and that data is given to the Microcontroller.

For the communication between Microcontroller and RFM70 module you have to use SPI protocol many controller gives the Hardware SPI but in this project we are going to use Software SPI.

Data which is received by the Microcontroller is now transffered to the RFM70 and RFM70 transmit that data in RF.

This is all about the Transmitter and for the Receiver it will do the same procedure but in reverse order first RFM70 Module collects the Data from RF and then on the request from Microcontroller via SPI Command it gives the received data to Microcontroller and the same data now also available on the other Computer or Laptop.

Interfacing PC with Microcontroller
To interface PC with microcontroller you have to use the MAX232 or any equivalent IC have a look at #-Link-Snipped-# for the other details.

Here is the Circuit Diagram for the same.
max232

Microcontroller Section


[​IMG]
​This is the Circuit Section for Microcontroller Here I have used Freescale Microcontroller but you can use any Microcontroller. Now if you see that there is Name given to every Pin which shows that pin's Connection.
Now as we are going to interface controller with MAX232 and RFM70 there are CE,CSN,SCK,MOSI,MISO and IRQ signals are used to communicate with RF Module and RXD,TXD to communicate with Serial Port of PC.

Now Before we start SPI Communication with RF Module you must have knowledge of SPI. for that again refer #-Link-Snipped-# for Some basic Information about SPI.

Note:- Remember as the RF module is working on 3.3Volt you must have to choose MCU which is working on 3.3 Volt. Here MCU_SUP is 3.3Volt
RFM70 Connection

[​IMG]
​This is the connection detail for RFM70. Now we have to make a software which communicate with RFM70 using microcontroller. For More information about RFM70 and its internal register please refer datasheet.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Harshad Italiya

    @harshad-ukH5ww Mar 25, 2011

    Re: DIY :- Wireless Chat Using

    Important Link for your Study

    1) #-Link-Snipped-#
    2) #-Link-Snipped-# or IB4 or Any Other Controller or #-Link-Snipped-#
    3) RF Module #-Link-Snipped-# from HopeRF or #-Link-Snipped-#
    4) <a href="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus" target="_blank" rel="nofollow noopener noreferrer">Serial Peripheral Interface Bus</a> --
    Must Read this one its very important for Communication between Controller and RF Module
    5) #-Link-Snipped-#

  • Harshad Italiya

    @harshad-ukH5ww Mar 25, 2011

    Re: DIY :- Wireless Chat Using

    Reserved.............

  • Harshad Italiya

    @harshad-ukH5ww Mar 25, 2011

    Guys if you have any doubt in this Block diagram then please shoot your questions.

  • narayana murthy

    @narayana-z4W16q Mar 26, 2011

    nice project buddy

  • Harshad Italiya

    @harshad-ukH5ww Mar 26, 2011

    narayana murthynice project buddy

    Thanks NM.

  • Harshad Italiya

    @harshad-ukH5ww Mar 29, 2011

    Should i go ahead? I think people are not interested in RF project.
    Ok lets See. 😔

  • Harshad Italiya

    @harshad-ukH5ww Mar 31, 2011

    Updated the Serial Communication circuit. please have a look.

  • yanivx

    @yanivx-gvxfxa Apr 1, 2011

    ok lets start godfather...... but let me sum up my final year project bro its an awesome project go ahead and if u are determined you will surely succeed All the best!!! God bless us all
    Regards Yanivx
    <a href="https://yanivx.wordpress.com/" target="_blank" rel="nofollow noopener noreferrer">Gyani | Do not go where the path may lead; go instead where there is no path and leave a trail.</a>

  • Harshad Italiya

    @harshad-ukH5ww Apr 1, 2011

    yanivxok lets start godfather...... but let me sum up my final year project bro its an awesome project go ahead and if u are determined you will surely succeed All the best!!! God bless us all
    Regards Yanivx
    <a href="https://yanivx.wordpress.com/" target="_blank" rel="nofollow noopener noreferrer">Gyani | Do not go where the path may lead; go instead where there is no path and leave a trail.</a>

    I have already developed this project this is for the Ceans who want to do something by themselves.

  • narayana murthy

    @narayana-z4W16q Apr 2, 2011

    godfatherI have already developed this project this is for the Ceans who want to do something by themselves.

    hey gf i had a doubt
    how much distance is it working
    i mean how much distance we can use it

  • Harshad Italiya

    @harshad-ukH5ww Apr 2, 2011

    narayana murthyhey gf i had a doubt
    how much distance is it working
    i mean how much distance we can use it

    It will give 30 Meter but mostly depends on the environment you use. but you can easily cover a HOME with this.

  • narayana murthy

    @narayana-z4W16q Apr 2, 2011

    godfatherIt will give 30 Meter but mostly depends on the environment you use. but you can easily cover a HOME with this.

    thanks brother i think this may useful to me

  • Harshad Italiya

    @harshad-ukH5ww Apr 2, 2011

    narayana murthythanks brother i think this may useful to me

    Sure you can use it. 😀

  • narayana murthy

    @narayana-z4W16q Apr 2, 2011

    godfatherSure you can use it. 😀

    but i think this is very useful for the sending only personal information because for just 30m we can use mikes lol
    just kidding anyway good project but is it in compact size

  • Harshad Italiya

    @harshad-ukH5ww Apr 2, 2011

    narayana murthybut i think this is very useful for the sending only personal information because for just 30m we can use mikes lol
    just kidding anyway good project but is it in compact size

    This is not only application i choose this because this will make interest in people there are lot of other application based on the same.

    yes you can compact it use the SMD component. 😉

  • Harshad Italiya

    @harshad-ukH5ww Apr 6, 2011

    One of my friend is also working on small GUI for this Chat. 😁

  • prathap07

    @prathap07-JOn6Hu May 5, 2011

    hi,
    it's really glad to see this project....it's too nice...hey and even we too are working on rfm70 for our project...we got few doubts...
    1. Some where i read that using RFM70 in wi-fi zone will hinder the performance..is it so?
    2. How to access the data in Rx FIFO register.

  • Harshad Italiya

    @harshad-ukH5ww May 6, 2011

    @Prathap~

    Its my pleasure if you really want to do this project by yourself i am sure you will get good knowledge too.

    Well For your Answer:-

    1) I think it will not effect the functionality of RFM70 as the address for the WIFI and RF devices are different i have tested it in company and at time we are using WIFI MODEM but it was working good so i don't think it might cause problem.
    2) To access RX FIFO from RFM70 module, If you have reference code of that Module then you will find a function Receive_packate after that function the data is available in RX_FIFO and via SPI you can read it. 😀

    PS:- Guys i am not sure much about the first thing if anyone knows please pour your knowledge.

  • yanivx

    @yanivx-gvxfxa Jul 20, 2011

    ok am here will be soon woking on this project have written down the components and will bring it by the coming week....

  • Harshad Italiya

    @harshad-ukH5ww Jul 27, 2011

    yanivxok am here will be soon woking on this project have written down the components and will bring it by the coming week....

    Good Yanivx,
    Let me know if you have any difficulty in finding Components. I will make your process fast. 😀

  • Harshad Italiya

    @harshad-ukH5ww Sep 7, 2011

    I have updated the First Post. Controller section is added and also the connection which will be useful for RF module connectivity.

  • Harshad Italiya

    @harshad-ukH5ww Sep 12, 2011

    Post is updated with RFM70 Connector next step will be of writing software. please refer datasheet before you go through software section.

  • tai86

    @tai86-HfSf2K Sep 14, 2011

    I am trying to use RFM70 module but the software interface is gone me crazy...😕

  • Harshad Italiya

    @harshad-ukH5ww Sep 15, 2011

    tai86I am trying to use RFM70 module but the software interface is gone me crazy...😕

    So do you have ready Hardware? Can you post it here?

  • tai86

    @tai86-HfSf2K Sep 15, 2011

    godfatherSo do you have ready Hardware? Can you post it here?

    Sorry, but I have only breadboard minimal hardware setting for testing the RFM70 capabilities...I'm woking with PIC18F, implementing the sample software provided by RFM70's manufacturer...

    Unforntunately this not working fine as it should : the packets are transmitted but never received! 😔

  • Harshad Italiya

    @harshad-ukH5ww Sep 16, 2011

    tai86Sorry, but I have only breadboard minimal hardware setting for testing the RFM70 capabilities...I'm woking with PIC18F, implementing the sample software provided by RFM70's manufacturer...

    Unforntunately this not working fine as it should : the packets are transmitted but never received! 😔

    You are using same code, It should be work please check your hardware again.

  • tai86

    @tai86-HfSf2K Sep 16, 2011

    Could you post your code? I have modified the orignal code (for PIC16) to run on PIC18...
    Which uC are you using?

  • Harshad Italiya

    @harshad-ukH5ww Sep 16, 2011

    tai86Could you post your code? I have modified the orignal code (for PIC16) to run on PIC18...
    Which uC are you using?

    I have used ATMEL and Freescale. You can try with the code given on site.

  • tai86

    @tai86-HfSf2K Sep 16, 2011

    I have try #-Link-Snipped-# and #-Link-Snipped-#
    but only RED_LED on tx blink at 1Hz...GREEN_LED on rx/tx (receive packets) never blink! I don't know what to do to understand what is the main issue...

  • Harshad Italiya

    @harshad-ukH5ww Sep 16, 2011

    tai86I have try #-Link-Snipped-# and #-Link-Snipped-#
    but only RED_LED on tx blink at 1Hz...GREEN_LED on rx/tx (receive packets) never blink! I don't know what to do to understand what is the main issue...

    If you have used that code without any changes then it should work. as i too tested same code. even you can check your SPI first by reading any register. if it works then you can debug.

    Do you have Debugger for PIC?

  • tai86

    @tai86-HfSf2K Sep 16, 2011

    godfatherIf you have used that code without any changes then it should work. as i too tested same code. even you can check your SPI first by reading any register. if it works then you can debug.

    Do you have Debugger for PIC?

    I use the original code with minimal correction for running it on PIC18F...I have ICD2 Clone prog/debug setup : RFM70 run at 3.3v and is not possible to debug at this voltage supply...damn it!

    Now, I'm trying to read a generic register...

  • tai86

    @tai86-HfSf2K Sep 16, 2011

    guptssumeet482Good project pal.
    I saw some good pictures and its working onthis site...

    #-Link-Snipped-#

    Unfortunately there are only prototype board photos about Wireless Data Transmission using RFM70...no schematic, no code...😕

  • Harshad Italiya

    @harshad-ukH5ww Sep 17, 2011

    tai86I use the original code with minimal correction for running it on PIC18F...I have ICD2 Clone prog/debug setup : RFM70 run at 3.3v and is not possible to debug at this voltage supply...damn it!

    Now, I'm trying to read a generic register...

    Try to read some register and blink LED according to that. so you come to know that your SPI is working or not. Let me know if still you have any doubt.

  • tai86

    @tai86-HfSf2K Sep 19, 2011

    godfatherTry to read some register and blink LED according to that. so you come to know that your SPI is working or not. Let me know if still you have any doubt.

    I read the 01 register and I find 0x3F agreed with RFM70's datasheet...So SPI_Read_Reg() is working!! 😁

    Then I try to display the variable "sta=SPI_Read_Reg(STATUS);" in function "Receive_Packet()" and the returned value is 0x0E (not depending on tx module on/off)...what is meaning of STATUS = 0x0E? 😕

  • Harshad Italiya

    @harshad-ukH5ww Sep 19, 2011

    tai86I read the 01 register and I find 0x3F agreed with RFM70's datasheet...So SPI_Read_Reg() is working!! 😁

    Then I try to display the variable "sta=SPI_Read_Reg(STATUS);" in function "Receive_Packet()" and the returned value is 0x0E (not depending on tx module on/off)...what is meaning of STATUS = 0x0E? 😕

    That is status register and in that one bit is set and reset according to reception.

    now try and check this condition

    if((STATUS_RX_DR&sta) == 0x40) // if receive data ready (RX_DR) interrupt

    becomes TRUE or not? If this condition becomes true when you receive perfect data then you can read length of the bytes received.

    Yes one more important thing. Have you Swapped address RX0_Address and Tx_address ?

  • tai86

    @tai86-HfSf2K Sep 19, 2011

    godfathernow try and check this condition becomes TRUE or not? If this condition becomes true when you receive perfect data then you can read length of the bytes received.

    The condition never becomes true because sta = 0x0E and STATUS_RX_DR&sta = 0x40 & 0x0E = 0

    godfatherYes one more important thing. Have you Swapped address RX0_Address and Tx_address ?

    ??? Swapping address...what do you mean? 😀 Maybe could it be THE problem!

  • Harshad Italiya

    @harshad-ukH5ww Sep 19, 2011

    tai86The condition never becomes true because sta = 0x0E and STATUS_RX_DR&sta = 0x40 & 0x0E = 0



    ??? Swapping address...what do you mean? 😀 Maybe could it be THE problem!

    Yes that is the problem.
    Here is small example

    for Transmitter
    Tx_Address = 0x01;
    RX0_address = 0x02;

    then for Receiver you have to swap these two
    Tx_Address = 0x02;
    RX0_address = 0x01;

    Please give it a try and let me know.

  • tai86

    @tai86-HfSf2K Sep 20, 2011

    godfatherfor Transmitter
    Tx_Address = 0x01;
    RX0_address = 0x02;

    then for Receiver you have to swap these two
    Tx_Address = 0x02;
    RX0_address = 0x01;

    You may be right BUT in the RFM70's example codes Tx_Address = RX0_Address = {0x34,0x43,0x10,0x10,0x01} and RX1_Address = {0x39,0x38,0x37,0x36,0xc2} for both receiver and transmitter...why? 😐

    Could you send me or publish your code? Thank you

  • Harshad Italiya

    @harshad-ukH5ww Sep 20, 2011

    //Bank1 register initialization value

    //In the array RegArrFSKAnalog,all the register value is the byte reversed!!!!!!!!!!!!!!!!!!!!!
    const unsigned long Bank1_Reg0_13[]={ //latest config txt
    0xE2014B40,
    0x00004BC0,
    0x028CFCD0,
    0x41390099,
    0x0B869Ef9,
    0xA67F0624,
    0x00000000,
    0x00000000,
    0x00000000,
    0x00000000,
    0x00000000,
    0x00000000,
    0x00127300,
    0x36B48000,
    };

    const UINT8 Bank1_Reg14[]=
    {
    0x41,0x20,0x08,0x04,0x81,0x20,0xCF,0xF7,0xFE,0xFF,0xFF
    };

    //Bank0 register initialization value
    const UINT8 Bank0_Reg[][2]={
    {0,0x0F},//reflect RX_DR\TX_DS\MAX_RT,Enable CRC ,2byte,POWER UP,PRX
    {1,0x3F},//Enable auto acknowledgement data pipe5\4\3\2\1\0
    {2,0x3F},//Enable RX Addresses pipe5\4\3\2\1\0
    {3,0x03},//RX/TX address field width 5byte
    {4,0xff},//auto retransmission dalay (4000us),auto retransmission count(15)
    {5,0x17},//23 channel
    {6,0x1f/*0x17*/},//air data rate-1M,out power 5dbm,setup LNA gain
    {7,0x07},//
    {8,0x00},//
    {9,0x00},
    {12,0xc3},//only LSB Receive address data pipe 2, MSB bytes is equal to RX_ADDR_P1[39:8]
    {13,0xc4},//only LSB Receive address data pipe 3, MSB bytes is equal to RX_ADDR_P1[39:8]
    {14,0xc5},//only LSB Receive address data pipe 4, MSB bytes is equal to RX_ADDR_P1[39:8]
    {15,0xc6},//only LSB Receive address data pipe 5, MSB bytes is equal to RX_ADDR_P1[39:8]
    {17,0x20},//Number of bytes in RX payload in data pipe0(32 byte)
    {18,0x20},//Number of bytes in RX payload in data pipe1(32 byte)
    {19,0x20},//Number of bytes in RX payload in data pipe2(32 byte)
    {20,0x20},//Number of bytes in RX payload in data pipe3(32 byte)
    {21,0x20},//Number of bytes in RX payload in data pipe4(32 byte)
    {22,0x20},//Number of bytes in RX payload in data pipe5(32 byte)
    {23,0x00},//fifo status
    {28,0x3F},//Enable dynamic payload length data pipe5\4\3\2\1\0
    {29,0x07}//Enables Dynamic Payload Length,Enables Payload with ACK,Enables the W_TX_PAYLOAD_NOACK command
    };


    const UINT8 RX0_Address[]={0x00,0x00,0x00,0x00,0x02};//Receive address data pipe 0
    const UINT8 RX1_Address[]={0x00,0x00,0x00,0x00,0xc2};////Receive address data pipe 1

    UINT8 Tx_address[] ={0x00,0x00,0x00,0x00,0x01}; // Transmitter Address.

    extern UINT8 test_data;
    extern UINT8 channel;
    extern UINT8 power;
    extern UINT8 data_rate;
    extern UINT8 rx_buf[MAX_PACKET_LEN];


    extern void delay_200ms(void);
    extern void delay_50ms(void);
    ///////////////////////////////////////////////////////////////////////////////
    // SPI access //
    ///////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////
    // Function: SPI_RW();
    //
    //Description:
    // Writes one UINT8 to RFM70, and return the UINT8 read
    //////////////////////////////////////////////////////////

    UINT8 SPI_RW(UINT8 value)
    {
    UINT8 bit_ctr;
    for(bit_ctr=0;bit_ctr<8;bit_ctr++) // output 8-bit
    {
    if(value & 0x80)
    {
    MOSI = 1;
    }
    else
    {
    MOSI=0;
    }
    value = (value << 1); // shift next bit into MSB..
    SCK = 1; // Set SCK high..
    // asm(nop);
    value |= MISO; // capture current MISO bit
    SCK = 0; // ..then set SCK low again
    }
    return(value); // return read UINT8
    }

    //**************************************************
    //Function: SPI_Write_Reg();
    //
    //Description:
    // Writes value 'value' to register 'reg'
    //**************************************************/
    void SPI_Write_Reg(UINT8 reg, UINT8 value) //--unsigned int UINT8
    {
    CSN = 0; // CSN low, init SPI transaction
    op_status = SPI_RW(reg); // select register
    op_status = SPI_RW(value); // ..and write value to it..
    CSN = 1; // CSN high again
    }


    //**************************************************/

    //**************************************************
    //Function: SPI_Read_Reg();
    //
    //Description:
    // Read one UINT8 from BK2421 register, 'reg'
    //**************************************************/
    UINT8 SPI_Read_Reg(UINT8 reg)
    {

    UINT8 value;
    CSN = 0; // CSN low, initialize SPI communication...
    op_status=SPI_RW(reg); // Select register to read from..
    value = SPI_RW(0); // ..then read register value
    CSN = 1; // CSN high, terminate SPI communication
    asm(NOP);
    return(value); // return register value
    }
    //**************************************************/

    //**************************************************
    //Function: SPI_Read_Buf();
    //
    //Description:
    // Reads 'length' #of length from register 'reg'
    //**************************************************/
    void SPI_Read_Buf(UINT8 reg, UINT8 *pBuf, UINT8 length)
    {
    UINT8 status,byte_ctr;

    CSN = 0; // Set CSN l
    status = SPI_RW(reg); // Select register to write, and read status UINT8

    for(byte_ctr=0;byte_ctr<length;byte_ctr++)
    pBuf[byte_ctr] = SPI_RW(0); // Perform SPI_RW to read UINT8 from RFM70

    CSN = 1; // Set CSN high again

    }
    //**************************************************/

    //**************************************************
    //Function: SPI_Write_Buf();
    //
    //Description:
    // Writes contents of buffer '*pBuf' to RFM70
    //**************************************************/
    void SPI_Write_Buf(UINT8 reg, UINT8 *pBuf, UINT8 length)
    {
    UINT8 byte_ctr;

    CSN = 0; // Set CSN low, init SPI tranaction
    op_status = SPI_RW(reg); // Select register to write to and read status UINT8
    for(byte_ctr=0; byte_ctr<length; byte_ctr++) // then write all UINT8 in buffer(*pBuf)
    SPI_RW(*pBuf++);
    CSN = 1; // Set CSN high again

    }
    //**************************************************
    //Function: SwitchToRxMode();
    //Description:
    // switch to Rx mode
    //**************************************************/
    void SwitchToRxMode()
    {
    UINT8 value;

    SPI_Write_Reg(FLUSH_RX,0);//flush Rx

    value=SPI_Read_Reg(STATUS); // read register STATUS's value
    SPI_Write_Reg(WRITE_REG|STATUS,value);// clear RX_DR or TX_DS or MAX_RT interrupt flag

    CE=0;

    value=SPI_Read_Reg(CONFIG); // read register CONFIG's value
    test = value;

    //PRX
    value=value|0x01;//set bit 1
    SPI_Write_Reg(WRITE_REG | CONFIG, value); // Set PWR_UP bit, enable CRC(2 length) & Prim:RX. RX_DR enabled..
    CE=1;
    }

    //**************************************************
    //Function: SwitchToTxMode();
    //Description:
    // switch to Tx mode
    ///**************************************************/
    void SwitchToTxMode()
    {
    UINT8 value;
    SPI_Write_Reg(FLUSH_TX,0);//flush Tx

    CE=0;
    value=SPI_Read_Reg(CONFIG); // read register CONFIG's value
    //PTX
    value=value&0xfe; //set bit 0
    SPI_Write_Reg(WRITE_REG | CONFIG, value); // Set PWR_UP bit, enable CRC(2 length) & Prim:RX. RX_DR enabled.

    CE=1;
    }

    //**************************************************
    //Function: SwitchCFG();
    //
    //Description:
    // access switch between Bank1 and Bank0

    ///Parameter:
    // _cfg 1:register bank1
    // 0:register bank0
    //Return:
    // None
    //**************************************************/
    void SwitchCFG(char _cfg)//1:Bank1 0:Bank0
    {
    UINT8 Tmp;

    Tmp=SPI_Read_Reg(7);
    Tmp=Tmp&0x80;

    if( ( (Tmp)&&(_cfg==0) )
    ||( ((Tmp)==0)&&(_cfg) ) )
    {
    SPI_Write_Reg(ACTIVATE_CMD,0x53);
    }
    }

    ///**************************************************
    //Function: SetChannelNum();
    //Description:
    // set channel number
    //
    //**************************************************/
    void SetChannelNum(UINT8 ch)
    {
    SPI_Write_Reg((UINT8)(WRITE_REG|5),(UINT8)(ch));
    }



    ///////////////////////////////////////////////////////////////////////////////
    // RFM70 initialization //
    ///////////////////////////////////////////////////////////////////////////////
    //**************************************************
    //Function: RFM70_Initialize();
    ///
    //Description:
    // register initialization
    //**************************************************/
    void RFM70_Initialize()
    {
    UINT8 i,j;
    // UINT8 temp;
    UINT8 WriteArr[12];

    //DelayMs(100);//delay more than 50ms.
    delay_200ms();

    SwitchCFG(0);

    for(i=0;i<20;i++)
    {
    SPI_Write_Reg((WRITE_REG|Bank0_Reg[0]),Bank0_Reg[1]);
    }

    for(j=0;j<5;j++)
    {
    WriteArr[j]=RX0_Address[j];
    }
    SPI_Write_Buf((WRITE_REG|10),&(WriteArr[0]),5);

    //REG 11 - Rx1 addr
    for(j=0;j<5;j++)
    {
    WriteArr[j]=RX1_Address[j];
    }
    SPI_Write_Buf((WRITE_REG|11),&(WriteArr[0]),5);

    //REG 16 - TX addr
    for(j=0;j<5;j++)
    {
    WriteArr[j]=Tx_address[j];
    }
    SPI_Write_Buf((WRITE_REG|16),&(WriteArr[0]),5);

    // printf("\nEnd Load Reg");

    i=SPI_Read_Reg(29);//read Feature Register Èç¹ûÒªÖ§³Ö¶¯Ì¬³¤¶È»òÕß Payload With ACK£¬ÐèÒªÏȸøÐ¾Æ¬·¢ËÍ ACTIVATEÃüÁÊý¾ÝΪ0x73),È»ºóʹÄܶ¯Ì¬³¤¶È»òÕß Payload With ACK (REG28,REG29).

    if(i==0) // i!=0 showed that chip has been actived.so do not active again.
    SPI_Write_Reg(ACTIVATE_CMD,0x73);// Active

    for(i=22;i>=21;i--)
    {
    SPI_Write_Reg((WRITE_REG|Bank0_Reg[0]),Bank0_Reg[1]);
    //SPI_Write_Reg_Bank0(Bank0_Reg[0],Bank0_Reg[1]);
    }

    //********************Write Bank1 register******************
    SwitchCFG(1);

    for(i=0;i<=8;i++)//reverse
    {
    for(j=0;j<4;j++)
    WriteArr[j]=(Bank1_Reg0_13>>(8*(j) ) )&0xff;

    SPI_Write_Buf((WRITE_REG|i),&(WriteArr[0]),4);
    }

    for(i=9;i<=13;i++)
    {
    for(j=0;j<4;j++)
    WriteArr[j]=(Bank1_Reg0_13>>(8*(3-j) ) )&0xff;

    SPI_Write_Buf((WRITE_REG|i),&(WriteArr[0]),4);
    }

    //SPI_Write_Buf((WRITE_REG|14),&(Bank1_Reg14[0]),11);
    for(j=0;j<11;j++)
    {
    WriteArr[j]=Bank1_Reg14[j];
    }
    SPI_Write_Buf((WRITE_REG|14),&(WriteArr[0]),11);

    //toggle REG4<25,26>
    for(j=0;j<4;j++)
    //WriteArr[j]=(RegArrFSKAnalog[4]>>(8*(j) ) )&0xff;
    WriteArr[j]=(Bank1_Reg0_13[4]>>(8*(j) ) )&0xff;

    WriteArr[0]=WriteArr[0]|0x06;
    SPI_Write_Buf((WRITE_REG|4),&(WriteArr[0]),4);

    WriteArr[0]=WriteArr[0]&0xf9;
    SPI_Write_Buf((WRITE_REG|4),&(WriteArr[0]),4);

    //**************************Test spi*****************************//
    //SPI_Write_Reg((WRITE_REG|Bank0_Reg[2][0]),0x0f);
    //test_data = SPI_Read_Reg(0x02);


    //DelayMs(10);
    delay_50ms();

    //********************switch back to Bank0 register access******************
    SwitchCFG(0);
    SwitchToRxMode();//switch to RX mode

    //------------------------- Code to check SPI--------------------------------
    test = SPI_Read_Reg(EN_AA);
    delay_50ms();
    if(test != 0x3f)
    {
    serialsend("Communication Error!!",21);
    serialsend("\r\n",1);

    while(1)
    {
    LED0 = ~ LED0;
    delay_50ms();
    delay_5ms();
    delay_5ms();
    }
    }
    //---------------------------------------------------------------------------
    }



    You have to swap address of RED marked Address only.

  • tai86

    @tai86-HfSf2K Sep 21, 2011

    Finally I find the issue!!! 😁
    The MISO pin of RFM70 module on tx was fault...changed the module and ALL WORKS GREAT!
    Thank you godfather! 😁

  • Harshad Italiya

    @harshad-ukH5ww Sep 23, 2011

    tai86Finally I find the issue!!! 😁
    The MISO pin of RFM70 module on tx was fault...changed the module and ALL WORKS GREAT!
    Thank you godfather! 😁

    You are most welcome.
    Do share Project video if possible. 😀

  • parth 127

    @parth-127-0dTXVz Sep 24, 2011

    nice project buddy

  • nakres

    @nakres-TRdnmE Oct 22, 2011

    I edit RFM70 code for MSP430. But i have the same error like tai86.
    I read 0x0e as status register. I write something to bank0 registers
    and when i read back from the same register i can not have the same
    value that i wrote (I think i can not reach the registers). I check
    the hardware several times. The code is in the attachment. Iwill be
    please to discuss about...

    PS : When i debug i can stop on line 547 with a breakpoint



    Source Code :

    #include "msp430x26x.h" // Line 1
    // Line 2
    /********************** Preprocessor Definitions ******************/
    #define TRUE 1
    #define FALSE 0

    #define INT8 char
    #define INT16 int
    #define UINT8 unsigned char
    #define UINT16 unsigned int
    #define UINT32 unsigned long

    #define CE_Out SetBit(P3DIR,4)
    #define Clr_CE ClrBit(P3OUT,4)
    #define Set_CE SetBit(P3OUT,4)

    #define CSN_Out SetBit(P3DIR,0)
    #define Clr_CSN ClrBit(P3OUT,0)
    #define Set_CSN SetBit(P3OUT,0)

    #define IRQ_In SetBit(P3DIR,5)
    #define IRQ (P3IN&0x20)

    #define MAX_PACKET_LEN 32// max value is 32

    #define ClrBit(Reg,Bit) (Reg&=((1<<Bit)^0xFF))
    #define SetBit(Reg,Bit) (Reg|=(1<<Bit))
    #define TogBit(Reg,Bit) (Reg = Reg^1<<Bit)

    //************************FSK COMMAND and REGISTER****************************************//
    // SPI(RFM70) commands
    #define READ_REG 0x00 // Define read command to register
    #define WRITE_REG 0x20 // Define write command to register
    #define RD_RX_PLOAD 0x61 // Define RX payload register address
    #define WR_TX_PLOAD 0xA0 // Define TX payload register address
    #define FLUSH_TX 0xE1 // Define flush TX register command
    #define FLUSH_RX 0xE2 // Define flush RX register command
    #define REUSE_TX_PL 0xE3 // Define reuse TX payload register command
    #define W_TX_PAYLOAD_NOACK_CMD 0xb0
    #define W_ACK_PAYLOAD_CMD 0xa8
    #define ACTIVATE_CMD 0x50
    #define R_RX_PL_WID_CMD 0x60
    #define NOP_NOP 0xFF // Define No Operation, might be used to read status register

    // SPI(RFM70) registers(addresses)
    #define CONFIG 0x00 // 'Config' register address
    #define EN_AA 0x01 // 'Enable Auto Acknowledgment' register address
    #define EN_RXADDR 0x02 // 'Enabled RX addresses' register address
    #define SETUP_AW 0x03 // 'Setup address width' register address
    #define SETUP_RETR 0x04 // 'Setup Auto. Retrans' register address
    #define RF_CH 0x05 // 'RF channel' register address
    #define RF_SETUP 0x06 // 'RF setup' register address
    #define STATUS 0x07 // 'Status' register address
    #define OBSERVE_TX 0x08 // 'Observe TX' register address
    #define CD 0x09 // 'Carrier Detect' register address
    #define RX_ADDR_P0 0x0A // 'RX address pipe0' register address
    #define RX_ADDR_P1 0x0B // 'RX address pipe1' register address
    #define RX_ADDR_P2 0x0C // 'RX address pipe2' register address
    #define RX_ADDR_P3 0x0D // 'RX address pipe3' register address
    #define RX_ADDR_P4 0x0E // 'RX address pipe4' register address
    #define RX_ADDR_P5 0x0F // 'RX address pipe5' register address
    #define TX_ADDR 0x10 // 'TX address' register address
    #define RX_PW_P0 0x11 // 'RX payload width, pipe0' register address
    #define RX_PW_P1 0x12 // 'RX payload width, pipe1' register address
    #define RX_PW_P2 0x13 // 'RX payload width, pipe2' register address
    #define RX_PW_P3 0x14 // 'RX payload width, pipe3' register address
    #define RX_PW_P4 0x15 // 'RX payload width, pipe4' register address
    #define RX_PW_P5 0x16 // 'RX payload width, pipe5' register address
    #define FIFO_STATUS 0x17 // 'FIFO Status Register' register address
    #define PAYLOAD_WIDTH 0x1f // 'payload length of 256 bytes modes register address

    //interrupt status
    #define STATUS_RX_DR 0x40
    #define STATUS_TX_DS 0x20
    #define STATUS_MAX_RT 0x10

    #define STATUS_TX_FULL 0x01

    //FIFO_STATUS
    #define FIFO_STATUS_TX_REUSE 0x40
    #define FIFO_STATUS_TX_FULL 0x20
    #define FIFO_STATUS_TX_EMPTY 0x10

    #define FIFO_STATUS_RX_FULL 0x02
    #define FIFO_STATUS_RX_EMPTY 0x01


    typedef struct {
    unsigned char reach_1s : 1;
    unsigned char reach_5hz : 1;
    } FlagType;

    unsigned long us_counter; // for delay functions
    UINT8 op_status;

    //Bank1 register initialization value

    //In the array RegArrFSKAnalog,all the register value is the byte reversed!!!!!!!!!!!!!!!!!!!!!
    const unsigned long Bank1_Reg0_13[]={ //latest config txt
    0xE2014B40,
    0x00004BC0,
    0x028CFCD0,
    0x41390099,
    0x0B869Ef9,
    0xA67F0624,
    0x00000000,
    0x00000000,
    0x00000000,
    0x00000000,
    0x00000000,
    0x00000000,
    0x00127300,
    0x36B48000,
    };

    const UINT8 Bank1_Reg14[]=
    {
    0x41,0x20,0x08,0x04,0x81,0x20,0xCF,0xF7,0xFE,0xFF,0xFF
    };

    //Bank0 register initialization value
    const UINT8 Bank0_Reg[][2]={
    {0,0x0F},
    {1,0x3F},
    {2,0x3F},
    {3,0x03},
    {4,0xff},
    {5,0x17},
    {6,0x17},
    {7,0x07},
    {8,0x00},
    {9,0x00},
    {12,0xc3},
    {13,0xc4},
    {14,0xc5},
    {15,0xc6},
    {17,0x20},
    {18,0x20},
    {19,0x20},
    {20,0x20},
    {21,0x20},
    {22,0x20},
    {23,0x00},
    {28,0x3F},
    {29,0x07}
    };

    //const UINT8 TX_Address[]={0x34,0x43,0x10,0x10,0x01};//For device PRX
    //const UINT8 RX0_Address[]={0x34,0x43,0x10,0x10,0x02};//For device PRX
    //const UINT8 TX_Address[]={0x34,0x43,0x10,0x10,0x02};//For device PTX
    //const UINT8 RX0_Address[]={0x34,0x43,0x10,0x10,0x01};//For device PTX

    const UINT8 RX0_Address[]={0x34,0x43,0x10,0x10,0x01};//Receive address data pipe 0
    const UINT8 RX1_Address[]={0x39,0x38,0x37,0x36,0xc2};////Receive address data pipe 1
    const UINT8 tx_buf[17]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x78};
    UINT8 rx_buf[MAX_PACKET_LEN];
    UINT8 count_50hz;
    FlagType Flag;

    void BoardInit(void);

    /************************ Timer Functions **********************/
    void TimerAInit();
    void TimerBInit(const unsigned periodPulse);

    /********************** SPI Functions *************************/
    void spi_init(void);
    void spi_write(UINT8 spi_data);
    UINT8 spi_read(void);

    /************************* RF Functions ************************/
    UINT8 SPI_RW(UINT8 value);
    void SPI_Write_Reg(UINT8 reg, UINT8 value);
    UINT8 SPI_Read_Reg(UINT8 reg);
    void SPI_Read_Buf(UINT8 reg, UINT8 *pBuf, UINT8 length);
    void SPI_Write_Buf(UINT8 reg, UINT8 *pBuf, UINT8 length);
    void SwitchToRxMode(void);
    void SwitchToTxMode(void);
    void SwitchCFG(char _cfg); //1:Bank1 0:Bank0
    void SetChannelNum(UINT8 ch);
    void RFM70_Initialize(void);
    void sub_program_1hz(void);
    void Send_Packet(UINT8 type,UINT8* pbuf,UINT8 len);
    void Receive_Packet(void);

    /******************** Delay Functions *************************/
    void delay_200ms(void);
    void delay_50ms(void);
    void delay_5ms(void);
    void delay_20us(void);
    void delay_1ms(void);
    void DelayMs(unsigned ms);

    void main(void)
    {
    BoardInit();

    while(1)
    {
    sub_program_1hz();
    Receive_Packet();
    }
    }

    void BoardInit(void)
    {
    WDTCTL = WDTTMSEL + WDTPW + WDTHOLD;

    if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
    {
    while(1); // If calibration constants erased // do not load, trap CPU!!
    }

    BCSCTL1 = CALBC1_8MHZ; // Set DCO
    DCOCTL = CALDCO_8MHZ; // Set DCO to 8MHz

    SetBit(P3DIR,7); // Led
    SetBit(P3OUT,7); // Turn off the led

    spi_init();
    TimerAInit(); // For delay functions
    TimerBInit(20000); // ~20ms for 50 Hz

    __bis_SR_register(GIE);

    count_50hz = 0;
    Flag.reach_1s = 0;

    RFM70_Initialize();
    }

    /************************ Timer Functions **********************/

    void TimerAInit()
    {
    TACTL |= TACLR; /* Set the TACLR - Reset the timer */


    TACTL = 0x0; /* Clear all settings */

    TACCR0 = 20; // ~20us
    TACTL = TASSEL_2 + MC_1 + ID_3 + TAIE; // SMCLK, /8
    }

    void TimerBInit(const unsigned periodPulse)
    {
    TBCTL |= TBCLR; /* Set the TACLR - Reset the timer */


    TBCTL = 0x0; /* Clear all settings */

    TBCCR0 = periodPulse; //
    TBCTL = TBSSEL_2 + MC_1 + ID_3 + TBIE; // SMCLK, /8

    }

    #pragma vector=TIMERA1_VECTOR
    __interrupt void TimerA_ISR(void) // interrupt service routine for time functions
    {
    TAIV;

    us_counter++;
    }

    #pragma vector=TIMERB1_VECTOR
    __interrupt void TimerB_ISR(void)
    {
    TBIV;

    count_50hz++;

    if(count_50hz==50) // REACH 1S
    {
    count_50hz=0;
    Flag.reach_1s = 1;
    }
    else if(count_50hz == 5)
    {
    Flag.reach_5hz = 1;
    }
    }

    /********************** SPI Functions *************************/

    void spi_init(void)
    {
    IRQ_In;
    CE_Out;
    CSN_Out;

    Set_CE;
    Set_CSN;

    P3SEL |= 0x0E; // P3.3,2,1 option select
    UCB0CTL0 |= UCMST+UCSYNC+UCMSB; //3-pin, 8-bit SPI master
    UCB0CTL1 |= UCSSEL_2; // SMCLK
    UCB0BR0 = 0x08; // /8
    UCB0BR1 = 0;
    UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    }

    void spi_write(unsigned char spi_data)
    {
    while (!(IFG2 & UCB0TXIFG)||UCB0STAT&UCBUSY); // USCI_B0 TX buffer ready?
    UCB0TXBUF = spi_data; // Send next value; "TX/RX of master happens here"
    while (!(IFG2 & UCB0TXIFG)||UCB0STAT&UCBUSY); // USCI_B0 TX buffer ready?
    }

    unsigned char spi_read(void)
    {
    while(!(IFG2 & UCB0RXIFG)||UCB0STAT&UCBUSY||UCB0STAT&UCOE);
    return UCB0RXBUF;
    }

    /************************* RF Functions ************************/

    unsigned char SPI_RW(unsigned char value)
    {
    spi_write(value);

    return spi_read();
    }

    void SPI_Write_Reg(UINT8 reg, UINT8 value)
    {
    Clr_CSN;
    op_status = SPI_RW(reg); // select register
    SPI_RW(value); // ..and write value to it..
    Set_CSN;
    }

    UINT8 SPI_Read_Reg(UINT8 reg)
    {
    UINT8 value;
    Clr_CSN;
    op_status=SPI_RW(reg); // Select register to read from..

    value = SPI_RW(0); // ..then read register value
    Set_CSN;

    return(value); // return register value
    }

    void SPI_Read_Buf(UINT8 reg, UINT8 *pBuf, UINT8 length)
    {
    UINT8 /*status,*/byte_ctr;

    Clr_CSN; // Set CSN l
    /*status = */SPI_RW(reg); // Select register to write, and read status UINT8

    for(byte_ctr=0;byte_ctr<length;byte_ctr++)
    pBuf[byte_ctr] = SPI_RW(0); // Perform SPI_RW to read UINT8 from RFM70

    Set_CSN; // Set CSN high again

    }

    void SPI_Write_Buf(UINT8 reg, UINT8 *pBuf, UINT8 length)
    {
    UINT8 byte_ctr;

    Clr_CSN; // Set CSN low, init SPI tranaction
    op_status = SPI_RW(reg); // Select register to write to and read status UINT8
    for(byte_ctr=0; byte_ctr<length; byte_ctr++) // then write all UINT8 in buffer(*pBuf)
    SPI_RW(*pBuf++);
    Set_CSN; // Set CSN high again

    }

    void SwitchToRxMode()
    {
    UINT8 value;

    SPI_Write_Reg(FLUSH_RX,0);//flush Rx

    value=SPI_Read_Reg(STATUS); // read register STATUS's value
    SPI_Write_Reg(WRITE_REG|STATUS,value);// clear RX_DR or TX_DS or MAX_RT interrupt flag

    Clr_CE;

    value=SPI_Read_Reg(CONFIG); // read register CONFIG's value

    //PRX
    value=value|0x01;//set bit 1
    SPI_Write_Reg(WRITE_REG | CONFIG, value); // Set PWR_UP bit, enable CRC(2 length) & Prim:RX. RX_DR enabled..
    Set_CE;
    }

    void SwitchToTxMode()
    {
    UINT8 value;
    SPI_Write_Reg(FLUSH_TX,0);//flush Tx

    Clr_CE;
    value=SPI_Read_Reg(CONFIG); // read register CONFIG's value
    //PTX
    value=value&0xfe;//set bit 0
    SPI_Write_Reg(WRITE_REG | CONFIG, value); // Set PWR_UP bit, enable CRC(2 length) & Prim:RX. RX_DR enabled.

    Set_CE;
    }

    void SwitchCFG(char _cfg)//1:Bank1 0:Bank0
    {
    UINT8 Tmp;

    Tmp=SPI_Read_Reg(7);
    Tmp=Tmp&0x80;

    if( ( (Tmp)&&(_cfg==0) )
    ||( ((Tmp)==0)&&(_cfg) ) )
    {
    SPI_Write_Reg(ACTIVATE_CMD,0x53);
    }
    }

    void SetChannelNum(UINT8 ch)
    {
    SPI_Write_Reg((UINT8)(WRITE_REG|5),(UINT8)(ch));
    }

    void RFM70_Initialize()
    {
    UINT8 i,j/*,temp*/;
    UINT8 WriteArr[12];

    delay_200ms();

    SwitchCFG(0);

    for(i=0;i<20;i++)
    {
    SPI_Write_Reg((WRITE_REG|Bank0_Reg[0]),Bank0_Reg[1]);
    }

    //reg 10 - Rx0 addr
    for(j=0;j<5;j++)
    {
    WriteArr[j]=RX0_Address[j];
    }
    SPI_Write_Buf((WRITE_REG|10),&(WriteArr[0]),5);

    //REG 11 - Rx1 addr
    for(j=0;j<5;j++)
    {
    WriteArr[j]=RX1_Address[j];
    }
    SPI_Write_Buf((WRITE_REG|11),&(WriteArr[0]),5);
    //REG 16 - TX addr
    for(j=0;j<5;j++)
    {
    WriteArr[j]=RX0_Address[j];
    }
    SPI_Write_Buf((WRITE_REG|16),&(WriteArr[0]),5);

    // printf("\nEnd Load Reg");

    i=SPI_Read_Reg(29);//read Feature Register Èç¹ûÒªÖ§³Ö¶¯Ì¬³¤¶È»òÕß Payload With ACK£¬ĞèÒªÏȸøĞ¾Æ¬·¢ËÍ ACTIVATEÃüÁÊı¾İΪ0x73),È»ºóʹÄܶ¯Ì¬³¤¶È»òÕß Payload With ACK (REG28,REG29).
    if(i==0) // i!=0 showed that chip has been actived.so do not active again.
    SPI_Write_Reg(ACTIVATE_CMD,0x73);// Active
    for(i=22;i>=21;i--)
    {
    SPI_Write_Reg((WRITE_REG|Bank0_Reg[0]),Bank0_Reg[1]);
    //SPI_Write_Reg_Bank0(Bank0_Reg[0],Bank0_Reg[1]);
    }

    //********************Write Bank1 register******************
    SwitchCFG(1);

    for(i=0;i<=8;i++)//reverse
    {
    for(j=0;j<4;j++)
    WriteArr[j]=(Bank1_Reg0_13>>(8*(j) ) )&0xff;

    SPI_Write_Buf((WRITE_REG|i),&(WriteArr[0]),4);
    }

    for(i=9;i<=13;i++)
    {
    for(j=0;j<4;j++)
    WriteArr[j]=(Bank1_Reg0_13>>(8*(3-j) ) )&0xff;

    SPI_Write_Buf((WRITE_REG|i),&(WriteArr[0]),4);
    }

    //SPI_Write_Buf((WRITE_REG|14),&(Bank1_Reg14[0]),11);
    for(j=0;j<11;j++)
    {
    WriteArr[j]=Bank1_Reg14[j];
    }
    SPI_Write_Buf((WRITE_REG|14),&(WriteArr[0]),11);

    //toggle REG4<25,26>
    for(j=0;j<4;j++)
    //WriteArr[j]=(RegArrFSKAnalog[4]>>(8*(j) ) )&0xff;
    WriteArr[j]=(Bank1_Reg0_13[4]>>(8*(j) ) )&0xff;

    WriteArr[0]=WriteArr[0]|0x06;
    SPI_Write_Buf((WRITE_REG|4),&(WriteArr[0]),4);

    WriteArr[0]=WriteArr[0]&0xf9;
    SPI_Write_Buf((WRITE_REG|4),&(WriteArr[0]),4);

    //**************************Test spi*****************************//
    //SPI_Write_Reg((WRITE_REG|Bank0_Reg[2][0]),0x0f);
    //test_data = SPI_Read_Reg(0x02);


    //DelayMs(10);
    delay_50ms();

    //********************switch back to Bank0 register access******************
    SwitchCFG(0);
    SwitchToRxMode();//switch to RX mode
    }

    void sub_program_1hz(void)
    {
    UINT8 i;
    UINT8 temp_buf[32];

    if(Flag.reach_1s)
    {
    Flag.reach_1s = 0;

    for(i=0;i<17;i++)
    {
    temp_buf=tx_buf;
    }

    Send_Packet(W_TX_PAYLOAD_NOACK_CMD,temp_buf,17);
    SwitchToRxMode(); //switch to Rx mode
    }
    }

    void Send_Packet(UINT8 type,UINT8* pbuf,UINT8 len)
    {
    UINT8 fifo_sta;

    SwitchToTxMode(); //switch to tx mode

    fifo_sta=SPI_Read_Reg(FIFO_STATUS); // read register FIFO_STATUS's value
    if((fifo_sta&FIFO_STATUS_TX_FULL)==0)//if not full, send data (write buff)
    {
    SPI_Write_Buf(type, pbuf, len); // Writes data to buffer

    delay_50ms(); // Line 547
    delay_50ms();
    }
    }

    void Receive_Packet(void)
    {
    UINT8 len,i,sta,fifo_sta/*,value*/,chksum/*,aa*/;
    UINT8 rx_buf[MAX_PACKET_LEN];

    sta=SPI_Read_Reg(STATUS); // read register STATUS's value

    if((STATUS_RX_DR&sta) == 0x40) // if receive data ready (RX_DR) interrupt
    {
    TogBit(P3DIR,7);

    do
    {
    len=SPI_Read_Reg(R_RX_PL_WID_CMD); // read len

    if(len<=MAX_PACKET_LEN)
    {
    SPI_Read_Buf(RD_RX_PLOAD,rx_buf,len);// read receive payload from RX_FIFO buffer
    }
    else
    {
    SPI_Write_Reg(FLUSH_RX,0);//flush Rx
    }

    fifo_sta=SPI_Read_Reg(FIFO_STATUS); // read register FIFO_STATUS's value

    }while((fifo_sta&FIFO_STATUS_RX_EMPTY)==0); //while not empty

    chksum = 0;
    for(i=0;i<16;i++)
    {
    chksum +=rx_buf;
    }
    if(chksum==rx_buf[16]&&rx_buf[0]==0x30)
    {
    //GREEN_LED = 1;
    delay_50ms();
    delay_50ms();
    //GREEN_LED = 0;

    //Send_Packet(W_TX_PAYLOAD_NOACK_CMD,rx_buf,17);
    //SwitchToRxMode();//switch to RX mode
    }
    }
    SPI_Write_Reg(WRITE_REG|STATUS,sta);// clear RX_DR or TX_DS or MAX_RT interrupt flag
    }

    /******************** Delay Functions *************************/

    void delay_200ms(void)
    {
    us_counter = 0;
    while(us_counter<10000);
    }

    void delay_50ms(void)
    {
    us_counter = 0;
    while(us_counter<2500);
    }

    void delay_5ms(void)
    {
    us_counter = 0;
    while(us_counter<250);
    }

    void delay_20us(void)
    {
    us_counter = 0;
    while(us_counter<1);
    }

    void delay_1ms(void)
    {
    us_counter = 0;
    while(us_counter<50);
    }

    void DelayMs(unsigned ms)
    {
    unsigned long wait_time;
    wait_time = 50*ms;
    us_counter = 0;
    while(us_counter<wait_time);
    }

  • Harshad Italiya

    @harshad-ukH5ww Nov 5, 2011

    First check your SPI whether its working proper or not.

  • fantomas2002ro

    @fantomas2002ro-hDTzQ8 Jan 7, 2012

    Hello,
    I edit RFM70 code for lpcxpresso(lpc1343).
    But i have the same error like nakres . I sniffer the spi protocol with an logicport and it seems that the SPI communication is working.
    I modify the SPI_RW function in 2 different ways:

    1).
    uint32_t SSPSend( uint8_t *buf, uint32_t Length )
    {
      uint32_t i;
      uint8_t Dummy = Dummy;
     
      for ( i = 0; i < Length; i++ )
      {
        /* Move on only if NOT busy and TX FIFO not full. */
        while ( (LPC_SSP->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
        LPC_SSP->DR = *buf;
        //printf("reg: %d, val(0): %d\n ", LPC_SSP->DR, *buf);
        buf++;
    #if !LOOPBACK_MODE
        while ( (LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
        /* Whenever a byte is written, MISO FIFO counter increments, Clear FIFO
        on MISO. Otherwise, when SSP0Receive() is called, previous data byte
        is left in the FIFO. */
        //Dummy = LPC_SSP->DR;//commented this line
    #else
        /* Wait until the Busy bit is cleared. */
        while ( LPC_SSP->SR & SSPSR_BSY );
    #endif
      }
      return LPC_SSP->DR;/added this one
    }
     
    UINT8 SPI_RW(UINT8 value)
    {
      return(SSPSend(&value, 1));                    // return read UINT8
    }
     
    2).
    void SSPSend( uint8_t *buf, uint32_t Length )
    {
      uint32_t i;
      uint8_t Dummy = Dummy;
     
      for ( i = 0; i < Length; i++ )
      {
        /* Move on only if NOT busy and TX FIFO not full. */
        while ( (LPC_SSP->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
        LPC_SSP->DR = *buf;
        //printf("reg: %d, val(0): %d\n ", LPC_SSP->DR, *buf);
        buf++;
    #if !LOOPBACK_MODE
        while ( (LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
        /* Whenever a byte is written, MISO FIFO counter increments, Clear FIFO
        on MISO. Otherwise, when SSP0Receive() is called, previous data byte
        is left in the FIFO. */
        Dummy = LPC_SSP->DR;
    #else
        /* Wait until the Busy bit is cleared. */
        while ( LPC_SSP->SR & SSPSR_BSY );
    #endif
      }
      //return LPC_SSP->DR;
    }
     
    UINT8 SPI_RW(UINT8 value)
    {
        SSPSend(&value, 1);//will not modify the value
        SSPReceive(&value, 1);//it will modify the value
      return(value);                    // return read UINT8
    }
    

    I get the same results: 0x00 or 0x0E. I don't know what to do. If is anybody that can help me(knowswith lpcxpresso, or not), please do 😁 😀.
    I attached the hole project.

    Best regards.😁

  • Harshad Italiya

    @harshad-ukH5ww Jan 7, 2012

    @Fantomas : please give me some time to review your code i'll get back to you soon. Have you checked that your SPI is working fine? Whatever you're writing to Config register are you able to read that content back?

  • fantomas2002ro

    @fantomas2002ro-hDTzQ8 Jan 8, 2012

    Hello.

    I think the SPI comunication is running well because I tested it with logicport.

    I set a breakpoint at this line of code to see the values.

    At some point theese values ​​have been received.

       
        SPI_Write_Reg((WRITE_REG|Bank0_Reg[2][0]),0x0f);
        test_data1[0] =  SPI_Read_Reg(0x02);//don't remember
    
        for(j=0;j<0x17;j++)
            test_data1[j] = SPI_Read_Reg(Bank0_Reg[j][0]);
       
        The results are:
        //aprox the same as Bank0_Reg
        test_data1[0]    0xf
        test_data1[1]    0x3f
        test_data1[2]    0x3f
        test_data1[3]    0x3
        test_data1[4]    0xff
        test_data1[5]    0x17
        test_data1[6]    0x17
        test_data1[7]    0xe
        test_data1[8]    0x0
        test_data1[9]    0x0
        test_data1[10]    0xc3
        test_data1[11]    0xc4
        test_data1[12]    0xc5
        test_data1[13]    0xc6
        test_data1[14]    0x20
        test_data1[15]    0x20
        test_data1[16]    0x20
        test_data1[17]    0x20
        test_data1[18]    0x20
        test_data1[19]    0x20
        test_data1[20]    0x1
        test_data1[21]    0x3f
        test_data1[22]    0x7    

    After a while I receives another values

        SPI_Write_Reg((WRITE_REG|Bank0_Reg[2][0]),0x0f);
        test_data1[0] = SPI_Read_Reg(0x02);//received 0x03
    
        for(j=0;j<0x17;j++)
            test_data1[j] = SPI_Read_Reg(Bank0_Reg[j][0]);
       
        The results are:
        // not all
        test_data1[0]    0x8
        test_data1[1]    0x3f
        test_data1[2]    0x3
        test_data1[3]    0x3
        test_data1[4]    0x3
        test_data1[5]    0x2
        test_data1[6]    0x3f
        test_data1[7]    0xe
        test_data1[8]    0x0
        test_data1[9]    0x0
        test_data1[10]    0xc3
        test_data1[11]    0xc4
        test_data1[12]    0xc5
        test_data1[13]    0xc6
        test_data1[14]    0x0
        test_data1[15]    0x0
        test_data1[16]    0x0
        test_data1[17]    0x0
        test_data1[18]    0x0
        test_data1[19]    0x0
        test_data1[20]    0x11
        test_data1[21]    0x0
        test_data1[22]    0x0

    I do not know what happened, because it seems to work.

    Thank you for thisquick response.👍

    P.S. : I added this line of code into the main, and modify the functions: SSPSend and SPI_RW.

    CE_OUT();
    CE(0);

    I attached the new project.

  • Harshad Italiya

    @harshad-ukH5ww Jan 8, 2012

    May i know which microcontroller you are using and why there is need to change the read write function if you've used the reference code given with module then it should work properly with freescale, ti, atmel microcontrollers. I've tested same code without any change in software. To check SPI my first step is write any one register and read it back if it's perfect then it should work. And main thing is swapping of addresss between transmitter and receiver is most important.

  • fantomas2002ro

    @fantomas2002ro-hDTzQ8 Jan 8, 2012

    As I said in my first post. I am using the board lpcxpresso(with lpc1343) and the CodeRed IDE . I modified the reference code to fit lpc1343, but it did not work. So I modify the software SPI read/write function with the SPI functions provided with the IDE. I still don't know if my read/write function it's working properly.
    My current read/write function is this:

    UINT8 SPI_RW(UINT8 value) {
    SSPSend(&value, 1);//provided with CodeRed
    SSPReceive(&value, 1);//provided with CodeRed
    return(value); // return read UINT8
    }

    .
    As I said at the second post I think I was writing and reading well from the registers, then after I modify something I don't remember then the values changed. I looked closely at the code and it seems that everything is as before(I undo the changes ). But still It's not OK. So I don't know what I did.
    When it was reading well from the register this line of code:

    i=SPI_Read_Reg(29);//read Feature Register

    returns 0x07. Now it returns 0x00(so it's not configured).
    Thank you for your respons

  • Kaustubh Katdare

    @thebigk Jan 8, 2012

    Tip: Always wrap your 'code' in [ code] --- [ /code] tags.[/code]