Franck
Franck
Branch Unspecified
11 Sep 2012

Use a RFM70-D via PIC18F4610

Hi,
My name is Franck. I am trying to use the RFM70 -D via PIC18F4610 but my knowledge in this area is a bit weak. Basically I do not completely understand the code provided by Hoperf and do not know how can I observe the packet from the Transmitter to the receiver.
If someone can assist me that will be great.

Best regards,
Franck

PS: C18 compiler,MPLAB IDE, PICKIT2
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
are you using both master and slave code or using any one for master and slave. There is difference in address in both code. I'll post it tomorrow.
Franck

Franck

Branch Unspecified
6 years ago
godfather
are you using both master and slave code or using any one for master and slave. There is difference in address in both code. I'll post it tomorrow.
I am using any one for master and slave. I will send you the diagram of the inputs/outputs connection used on the two PIC18F4610.
Franck

Franck

Branch Unspecified
6 years ago
Here is the diagrams. I am using the PIC18F4610 as Master and the PIC18F452 as Slave.
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
First you have to check that your SPI is working properly or not so for that can you please do one thing. After initializing RFM70 code try to read any register say Config register of RFM70 and let me know if it works perfectly.
Let me know if still you have any confusion.
Franck

Franck

Branch Unspecified
6 years ago
Sorry godfather, I am re-soldering on pin of the RFM70-D. How can I do to read the config of the RFM70?
Can I do it from MPLAB?
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
Sorry godfather, I am re-soldering on pin of the RFM70-D. How can I do to read the config of the RFM70?
Can I do it from MPLAB?
Yes You have to write code to read register. can you please post your code here. make one zip folder and attach it i will tell you the function which is going to use as a read function.
Franck

Franck

Branch Unspecified
6 years ago
ok
Franck

Franck

Branch Unspecified
6 years ago
Here is my code.
Godfather you already know that I am not good for that work.So I will ask you to be patient with me and I will do my best to understand.😀
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Check there is a function SPI_Read_Reg it is used to read a SPI Register of RFM70.
Franck

Franck

Branch Unspecified
6 years ago
That one from the init.c ?

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
return(value); // return register value
}
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
One more thing I saw in your circuit diagram that you have given 5V to controller and you can see RFM70 works on 3.3 volt please reduce 5V to 3.3V for Microcontroller.
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
That one from the init.c ?

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
return(value); // return register value
}
Yes the same function.

write something like this
test = PI_Read_Reg(CONFIG);
You must get the CONFIG value you had set in initialization in test variable.
Franck

Franck

Branch Unspecified
6 years ago
godfather
Yes the same function.

write something like this
test = PI_Read_Reg(CONFIG);
You must get the CONFIG value you had set in initialization in test variable.
Sorry I am bit lost I have declared "char test" and added the test=SPI_Read_Reg(CONFIG); into the main body. but which test variable? . What I understand of program is that there are sending a set of numbers
from the const UINT8 tx_buf[17] ? Can you make it clear for me. By the way I changed the voltage of the microcontroller as well. Thanks
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
Sorry I am bit lost I have declared "char test" and added the test=SPI_Read_Reg(CONFIG); into the main body. but which test variable? . What I understand of program is that there are sending a set of numbers
from the const UINT8 tx_buf[17] ? Can you make it clear for me. By the way I changed the voltage of the microcontroller as well. Thanks
Well See what you have to do. If I am not wrong you have written code for RFM70 initialization right?
RFM70_Initialize(); This is the Function which initialize RFM70 and Right after that take any variable say. . .
unsigned char XYZ=0;
now write...
XYZ = SPI_Read_Reg(CONFIG);

now If you check RFM70.h file there is written. . . .
#define CONFIG 0x00 // 'Config' register address
It means 0 Number Register is CONFIG Register and while initialization you are writing 0x0F into that register You can check it in file RFm70_init.c

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,0x17},//air data rate-1M,out power 0dbm,setup LNA gain
{7,0x07},//
If you are using Debugger then you can set breakpoint after. . .
XYZ = SPI_Read_Reg(CONFIG);
and check XYZ should be updated with 0x0F Value.

I hope this things makes your doubt clear.
Franck

Franck

Branch Unspecified
6 years ago
Sorry I had a problem with my Internet connection. I read your last message. It is clear.Thanks. I have not written the RFM70 initialization.All comes from the Hoperf website. I have just modified the main to be suitable for the PIC18F4610. I think I understand. I try it now and I come back to you
Franck

Franck

Branch Unspecified
6 years ago
void RFM70_Initialize()
{
UINT8 i,j,temp;
UINT8 WriteArr[12];
unsigned char XYZ=0;
XYZ = SPI_Read_Reg(CONFIG);
//DelayMs(100);//delay more than 50ms.
delay_200ms();
SwitchCFG(0);


I have obtained XYZ=0x00 in the Watch window instead of 0x0F
Is it the right place?
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
void RFM70_Initialize()
{
UINT8 i,j,temp;
UINT8 WriteArr[12];
unsigned char XYZ=0;
XYZ = SPI_Read_Reg(CONFIG);
//DelayMs(100);//delay more than 50ms.
delay_200ms();
SwitchCFG(0);

I have obtained XYZ=0x00 in the Watch window instead of 0x0F
Is it the right place?
Are you sure that you are receiving 0x00 ? then there must be problem with SPI Coding. You have to check the connection for SDI and SDO pin or you can say MOSI MISO Pin. Try to interchange the PIN.

There are Four possibilities to get the connection.

Or I would like to say that First check that MOSI Pin of RF Module connected to Port Pin should be initialize as Output and MISO as a Input. Can you please check that and let me know the connection.

Once SPI is working we can start Transmission and Reception Routine checking.
Franck

Franck

Branch Unspecified
6 years ago
Thanks Godfather.If you do not mind I will just read the main.c, the RFM70_init.c and the RFM70.h with the datasheet again. Because I think I am starting to understand the process bit per bit and that will avoid me to ask you stupid questions on the simple task you ask me to do.

I think I am not doing correctly the task to get the XYZ=0x0F. Here is how I have literally proceeded. I have declared XYZ and written the instruction XYZ= SPI_Read_Reg into void RFM70_Initialize()I built up on MPLAB then opened the watch window and selected the variable XYZ and finally I ran the program. That is how I get XYZ=0x00. So I have not use the PIC18F4610 itself but Just the coding on MPLAB.

I might be wrong on that process so do I have to upload the coding into the pic18f4610 before to observe the result on XYZ on MPLAB? Or there is nothing to do with the hardware right now?

I'll check the pins connection like you said. By the way I have initially connected the two PIC's with the Green light on the master and the Red light on the slave with the coding I have modified suggested by Hoperf example but nothing happen. I need to check it all clearly because I might have connected some pin at the wrong place.
I am going to make those things clear this evening then I message you again.
Thanks a lot for helping me
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
What I have asked to check XYZ that you have to write after RFM70_Initialize(); Function you have called in your main routine and of course you must have to load the code into PIC Microcontroller and after that start debugging If you Don't have debugger then you have to blink some LED on the correct reading so you can know that your reading is correct or not. Okey give a try by yourself by that you can more clear idea of RFM70. and if you have problem post it here. Fell Free !
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
void RFM70_Initialize()
{
UINT8 i,j,temp;
UINT8 WriteArr[12];
unsigned char XYZ=0;
XYZ = SPI_Read_Reg(CONFIG);
//DelayMs(100);//delay more than 50ms.
delay_200ms();
SwitchCFG(0);

I have obtained XYZ=0x00 in the Watch window instead of 0x0F
Is it the right place?
Oh Sorry i too didn't notice that you have written thin in the Function itself you have to write
XYZ = SPI_Read_Reg(CONFIG);
after calling this function in main(); hope you got my point. and unsigned char XYZ=0; Should be global variable.
Franck

Franck

Branch Unspecified
6 years ago
Thanks godfather.I have rectified the code.Strangely, I have never used the pickit2 as debugger straight to the PIC. I debug on the software then I upload to the pic via the PICKIT2. I think the PICKIT2 I am using can debug on hardware. I am just looking at the datasheet PICKIT2 now.I come back to you very soon. Thanks
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
There is no issue if it is not working as a debugger we can check SPI communication without that too. Althoug give it a try if is going to allow debugging then it becomes easy for you. Or I'll let you know how to check it without that.
Franck

Franck

Branch Unspecified
6 years ago
ok
Franck

Franck

Branch Unspecified
6 years ago
Hi godfather,
I have revised the whole codes and the connections for the two pic18f4610. One of them is the master and the other the slave.I found out numerous mistake on hardware connections between the RFM70-D and the PIC but also on the coding part. Now it should be ok but I have got another problem. I cannot upload the master program to my pic.The "build up" shows no error and the connection from the PICKIT2 to the PIC18F4610 is correct since I have no problem to upload the slave program. I am still searching where that comes from. If you have a subjection that will be great.

On top of that can you tell me the other way of testing the SPI. I did not found out yet how to use the in-built debugger on PIC18F4610 via PICKIT2 (I have got a DebugDemo but it is for the PIC16F887).
I put in attachment the update code for the master and the slave part.
Thanks
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Ok i'll look at your code. And also i'll check whether your microcontroller supports debug or not.
I'm afraid there might be damage in your controller or any loose connection.
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Ok i'll look at your code. And also i'll check whether your microcontroller supports debug or not.
I'm afraid there might be damage in your controller or any loose connection.
Franck

Franck

Branch Unspecified
6 years ago
godfather
Ok i'll look at your code. And also i'll check whether your microcontroller supports debug or not.
I'm afraid there might be damage in your controller or any loose connection.
Thanks godfather. I'm gonna check the connection again and swap with the other Pic18f4610 to see if master program can be upload on that one.
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
Thanks godfather. I'm gonna check the connection again and swap with the other Pic18f4610 to see if master program can be upload on that one.
If you have spare microcontroller then use it also Rfm70 but only if you're sure that this time connections are fine.
Franck

Franck

Branch Unspecified
6 years ago
Hi godfather, I finally upload the master into the pic. I just re-create the project. but still not working.
Unfornately I do not have any spare of RFM70-D. I have ordered some.


The maching between PORT and TRIS in the header below was incorrect:
Correction
43#define CE PORTCbits.RC1
44#define CSN PORTCbits.RC0
45#define SCK PORTAbits.RA4
46#define MISO PORTCbits.RC2
47#define MOSI PORTAbits.RA6
48#define IRQ PORTAbits.RA7
49
50#define CE_OUT() TRISCbits.TRISC1=0// TRISA0 = 0
51#define CSN_OUT() TRISCbits.TRISC0=0// TRISA1 = 0
52#define SCK_OUT() TRISAbits.TRISA4=0// TRISA2 = 0
53#define MISO_IN() TRISCbits.TRISC2=1// TRISA3 = 1
54#define MOSI_OUT() TRISAbits.TRISA6=0// TRISA4 = 0
55#define IRQ_IN() TRISAbits.TRISA7=1// TRISA5 = 1

Normally I can choose whatever pins on my PIC,right?

In the RFM70_init.c they ask to implement this function but I do not what to put in there?

Function: DelayMs();
Description:
delay ms,please implement this function according to your MCU.
/**************************************************/
void DelayMs(UINT16 ms)
{

}
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
Hi godfather, I finally upload the master into the pic. I just re-create the project. but still not working.
Unfornately I do not have any spare of RFM70-D. I have ordered some.


The maching between PORT and TRIS in the header below was incorrect:
Correction
43#define CE PORTCbits.RC1
44#define CSN PORTCbits.RC0
45#define SCK PORTAbits.RA4
46#define MISO PORTCbits.RC2
47#define MOSI PORTAbits.RA6
48#define IRQ PORTAbits.RA7
49
50#define CE_OUT() TRISCbits.TRISC1=0// TRISA0 = 0
51#define CSN_OUT() TRISCbits.TRISC0=0// TRISA1 = 0
52#define SCK_OUT() TRISAbits.TRISA4=0// TRISA2 = 0
53#define MISO_IN() TRISCbits.TRISC2=1// TRISA3 = 1
54#define MOSI_OUT() TRISAbits.TRISA6=0// TRISA4 = 0
55#define IRQ_IN() TRISAbits.TRISA7=1// TRISA5 = 1

Normally I can choose whatever pins on my PIC,right?

In the RFM70_init.c they ask to implement this function but I do not what to put in there?

Function: DelayMs();
Description:
delay ms,please implement this function according to your MCU.
/**************************************************/
void DelayMs(UINT16 ms)
{

}
These are error in the definition of your Port PIN can you check with some reference code please.
Franck

Franck

Branch Unspecified
6 years ago
Hi godfather, I have already changed the correct definition. the original code is TRIS(A0,A1,A2,A3,A4,A5) are in comment (in red colour). But the connections have made on my pic18f4610 are the following. I have noticed that the manufacturer have not choosen particular pins on PIC16f960. The one they have chosen are simple inputs/outputs pins from RAO to RA5. Correct me if I am wrong.

I started having some improvement yesterday night using the Mplab debug. It looks like the TMR2IF does not flag when there is a match between PR2 and TRM2. But TRM2 does reset at 156 (PR2=156).


I compiled the original code from the manufacturer on the debug and I saw that TRM2 was working correctly.

I need found out what I did wrong in the setting of this timer? What do you think?

By the way what is your time zone compare to UK? I can adapt myself to your time zone to communicate at suitable times.

Did you find some information about the debugger?I wish I could have the debugger on circuit. I have a quick search again.




Correction
43#define CE PORTCbits.RC1
44#define CSN PORTCbits.RC0
45#define SCK PORTAbits.RA4
46#define MISO PORTCbits.RC2
47#define MOSI PORTAbits.RA6
48#define IRQ PORTAbits.RA7
49
50#define CE_OUT() TRISCbits.TRISC1=0//TRISA0 = 0
51#define CSN_OUT() TRISCbits.TRISC0=0//TRISA1 = 0
52#define SCK_OUT() TRISAbits.TRISA4=0// TRISA2 = 0
53#define MISO_IN() TRISCbits.TRISC2=1// TRISA3 = 1
54#define MOSI_OUT() TRISAbits.TRISA6=0//TRISA4 = 0
55#define IRQ_IN() TRISAbits.TRISA7=1//TRISA5 = 1

Normally I can choose whatever pins on my PIC,right?

In the RFM70_init.c they ask to implement this function but I do not what to put in there?

Function: DelayMs();
Description:
delay ms,please implement this function according to your MCU.
/**************************************************/
void DelayMs(UINT16 ms)
{

}[/CODE]
Franck

Franck

Branch Unspecified
6 years ago
Hello godfather,
Just to let you know that I have got the SPI working. I get the XYZ=0x0F from the XYZ=SPI_Read_Reg(CONFIG); The RED LED from the master is blinking each second. But I haven't yet the green LED flashing on the Slave(receiver). I let you know.
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Great. Superb work. Now i'll let you know about the address. And one more thing have you checked the proper SPI on slave side also?
Franck

Franck

Branch Unspecified
6 years ago
Yes the SPI works perfectly on the other side too. The transmission and reception is working from both side now. The green and red light are blinking alternatively on the Master and the Slave.I have learnt a lot with your guidance. Thanks. Unfortunately I am getting short of time because I am writting my dissertation at the moment but I will be please to know more about address to get a better understanding and to advance the work. Thanks again
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
Yes the SPI works perfectly on the other side too. The transmission and reception is working from both side now. The green and red light are blinking alternatively on the Master and the Slave.I have learnt a lot with your guidance. Thanks. Unfortunately I am getting short of time because I am writting my dissertation at the moment but I will be please to know more about address to get a better understanding and to advance the work. Thanks again
You're most welcome Frank. Looking forward to see your project video here if possible. 😀
Franck

Franck

Branch Unspecified
6 years ago
No problem godfather, I will post the project video.👍
Franck

Franck

Branch Unspecified
6 years ago
Hi godfather,
I've tried to modify the RFM70 code to send any value let's say 1 from the Master to the Slave but the Slave part is not receiving the number "1". It looks like the code is not going through the condition
if((STATUS_RX_DR&sta) == 0x40) 
Here is what have done to send the number one from the master part:

Unsigned int ADC=1; //Simulation of the variable representing the output of the ADC
READING=&ADC; // The reading is 1
 
Unsigned int* READING;
Unsigned int TX_buf[1],*READING; // I put 1 in the transmitter table
I do not if I am correct on the process? Is there another way to send a data?

Regards,
Franck
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
When you've set this code your transmission LED blinks perfectly? I'll post a very simple example also. And yeah there is checksum or Crc checking at receiver side if you don't want then remove that part or you've to add checksum or Crc generator at transmitter side too.
Franck

Franck

Branch Unspecified
6 years ago
Yes the transmission LED blinks perfectly.I will removed the the checksum from the receiver and see what happen.
Franck

Franck

Branch Unspecified
6 years ago
Hi godfather, which register enable me to see the data received instead of the using the LED because I am receiving a data but not sure if it is the "1".
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
If you're putting 1 into txbuf[0] then you'll get that into rxbuf[0] so check it. And you know how to check it right.
Franck

Franck

Branch Unspecified
6 years ago
Yes. I modified a bit the code to get the 1 in the tx_buf because I was getting 44 with the following code
tx_buf[1],*READING;
.
Now the transmitter is not blinking anymore(the light is slightly on) and on the other side I am receiving nothing in rx_buf[1]. I am trying to figure out what I did wrong.
Franck

Franck

Branch Unspecified
6 years ago
I have got the blinking back (connection pb). But I am still receiving 0 in tx_buf[0].
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
You've put data in txbuf[1] so check rxbuf[1].
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
In the Receive_Packet Function there is something like this ...

        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 
        } 
Instead of checking chksum you can use like this...
       
if(rx_buf[0]==1)
        {
            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 
        } 
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
In the Receive_Packet Function there is something like this ...

        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 
        } 
Instead of checking chksum you can use like this...
       
if(rx_buf[0]==1)
        {
            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 
        } 
Franck

Franck

Branch Unspecified
6 years ago
Hi godfather, At the moment I cannot submit yet my project on your website because the process of my university but i will be please to share it just after my dissertation includings schematics and videos.
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
Hi godfather, At the moment I cannot submit yet my project on your website because the process of my university but i will be please to share it just after my dissertation includings schematics and videos.
No problem. 😀
Franck

Franck

Branch Unspecified
6 years ago
Hi godfather, I can send any value now. I found out last week.But still I have to implement it to my project using the SPI communication from one pic to another before transmitting the data. I need to have a look to that now. I let you know how is going.
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
Franck
Hi godfather, I can send any value now. I found out last week.But still I have to implement it to my project using the SPI communication from one pic to another before transmitting the data. I need to have a look to that now. I let you know how is going.
Ok. Franck Take Your Time. 👍
kld_555

kld_555

Branch Unspecified
6 years ago
Franck
Hi godfather, I can send any value now. I found out last week.But still I have to implement it to my project using the SPI communication from one pic to another before transmitting the data. I need to have a look to that now. I let you know how is going.
Hi all 😀,

I am having troubles working the RFM70 as well, I have read through your previous messages, but couldn't locate my problem, I am using the old big 16f877, I configured the output & input pins to portB:

#define RFM70_SCK( x )  PORTB.F0 = x
#define RFM70_MOSI( x )  PORTB.F1 = x
#define RFM70_MISO      PORTB.F2
#define RFM70_CSN( x )  PORTB.F3 = x
#define RFM70_CE( x )    PORTB.F4 = x
 
#define RFM70_PIN_DIRECTION { \
  TRISB.F0 = 0; \
  TRISB.F1 = 0; \
  TRISB.F2 = 1; \
  TRISB.F3 = 0; \
  TRISB.F4 = 0; \
}
Although the PIC has an SPI module, but I am using the library which uses bit banging instead. I am also using mikroC.

I doubt that my SPI is working as I tried reading the CONFIG and STATUS registers, and they came out not as defined in the rfm70_init() function. instead i got the value (0x08)

Config(0x00) value: 0x08
Status(0x07) value: 0x08

Would you be so kind and share your code? I can see you already reached a state where you can send single values. I will be sending packets of data and I am still stuck at getting it working!
Harshad Italiya

Harshad Italiya

Electronics and Communication
6 years ago
code is same as sample given. Check your connection properly focus on SDO and SDI pin.

Share this content on your social channels -

Only logged in users can reply.