Author |
Message |
srnet Senior Member
 Joined: 08/08/2014 Location: United KingdomPosts: 164 |
Posted: 04:53am 01 Feb 2015 |
Copy link to clipboard |
 Print this post |
|
I have been porting my RFM98 LoRa routines from PICAXE to MMII.
I wrote a routine to print out the register contents of the RFM98 with SPI commands. This works and the output display is correct for a RFM98 after reset;
RFM98Print:
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
00 00 09 1A 0B 00 52 6C 80 00 4F 09 2B 20 08 02 0A
I next wanted to set the frequency registers by writing values to registers $06, $07, $08, the default values, after reset, are as above $6C, $80, $00
For 434.400Mhz the values are, $6C, $99, $99
So this is the basic routine;
GOSUB RFM98Print 'print values at reset
PIN(NSS) = 0
SPI WRITE 4, &H86, &H6C, &H99, &H99
PIN(NSS) = 1
GOSUB RFM98Print 'check frequency is programmed
However at the second RFM98Print all the registers report as $00, the RFM98 appears to be blank;
RFM98Print:
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
If the code is now changed to;
GOSUB RFM98Print 'print values at reset
PIN(NSS) = 0
SPI WRITE 4, &H86, &H6C, &H99, &H99
PIN(NSS) = 1
SPI CLOSE
SPI OPEN 1000000, 3, 8
GOSUB RFM98Print 'check frequency is programmed
The result is;
RFM98Print:
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
00 00 09 1A 0B 00 52 6C 99 99 4F 09 2B 20 08 02 0A
Which is as expected.
It appears to me that the SPI WRITE command is working correctly, but something is preventing subsequent reads from working, unless the SPI interface is closed and opened after the SPI WRITE.
Same symptoms with an RFM22B.
Edited by srnet 2015-02-02 $50SAT is Silent but probably still working. For information on LoRa visit http://www.loratracker.uk/
|
|
WhiteWizzard Guru
 Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Posted: 05:01am 01 Feb 2015 |
Copy link to clipboard |
 Print this post |
|
Could be a timing issue!
Please give the code for your RF98Print sub and this may provide more clues . . .
|
|
matherp Guru
 Joined: 11/12/2012 Location: United KingdomPosts: 10197 |
Posted: 05:14am 01 Feb 2015 |
Copy link to clipboard |
 Print this post |
|
I'm pretty certain this is because the SPI WRITE firmware isn't also reading bytes which means the SPI receive buffer is filling up. I had this problem when coding direct to the SPI registers in my Cfunctions.
Geoff, looking at the SPI read code, I think there needs to be a statement:
junk=SpiChnGetC(SPI_Channel);
inside the end of the "while(nbr--)" loop to stop the receive buffer overflowing.
As a workround, try using i=SPI() to write and read the bytes 1 at a time rather than closing and opening the port
Edited by matherp 2015-02-02 |
|
srnet Senior Member
 Joined: 08/08/2014 Location: United KingdomPosts: 164 |
Posted: 05:59am 01 Feb 2015 |
Copy link to clipboard |
 Print this post |
|
Here is the whole program, I would be amazed if its a timing issue, the print routine behaves properly if I use the WriteRFM SUB to write the registers one at a time;
'OPTION AUTORUN ON
DIM Integer LOOPV1
DIM Integer LOOPV2
DIM Integer Var1
DIM Integer RFMDATA
DIM Integer RFMREG
CONST NSS = 26
CONST RFM98RESET = 15
CONST trTXfrMSB = &H6C 'MSB of frequency setting for 434.400 Mhz, tracker TX
CONST trTXfrMid = &H99 'Mid of frequency setting for 434.400 Mhz, tracker TX
CONST trTXfrLSB = &H99 '(&99 or 153) LSB of frequency setting for 434.400 Mhz, , tracker TX
CONST RegFrMSB = &H06
CONST RegFrMid = &H07
CONST RegFrLSB = &H08
CONST WRegFrMSB = &H86
gosub startup
GOSUB RFM98Print
'WriteRFM &H86,trTXfrMSB
'WriteRFM &H87,trTXfrMid
'WriteRFM &H88,trTXfrLSB
PIN(NSS) = 0
SPI WRITE 4, &H86, &H6C, &H99, &H99
PIN(NSS) = 1
'SPI CLOSE
'SPI OPEN 1000000, 3, 8
GOSUB RFM98Print
PRINT "Finished"
END
RFM98Print:
'prints the contents of RFM98 registers to serial terminal
PRINT ""
PRINT "RFM98Print:"
PRINT "Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F"
RFMREG = 0 'point to first register of RFM98
for loopv1 = 0 to 7 '8 lines
PRINT hex$(loopv1,1);
PRINT "0 ";
for loopv2 = 0 to 15 '16 bytes per line
PRINT hex$(READREG(RFMREG),2);
PRINT " ";
RFMREG = RFMREG + 1
next loopv2
PRINT ""
next loopv1
PRINT ""
return
STARTUP:
PRINT "RFM98Print Test"
SPI OPEN 1000000, 3, 8
SETPIN NSS, DOUT
PIN(NSS) = 1
SETPIN RFM98RESET, DOUT
GOSUB RESETRFM98
return
FUNCTION READREG(RFMREG) 'uses rfmreg to get regdata
PIN(NSS) = 0
READREG = SPI(RFMREG) 'send register address for a read 0-&7F
READREG = SPI(0) 'and read it in
PIN(NSS) = 1
END FUNCTION
RESETRFM98:
PIN(RFM98RESET) = 1
PAUSE 5
PIN(RFM98RESET) = 0
return
SUB WriteRFM(RFMREG,RFMDATA)
RFMREG = RFMREG OR &H80
PRINT "Writing $";
PRINT hex$(RFMREG,2);
PRINT ",$";
PRINT hex$(RFMDATA,2)
PIN(NSS) = 0
VAR1 = SPI(RFMREG) 'send register address for a write $80 to $FF
VAR1 = SPI(RFMDATA) 'and write data out
PIN(NSS) = 1
END SUB $50SAT is Silent but probably still working. For information on LoRa visit http://www.loratracker.uk/
|
|
matherp Guru
 Joined: 11/12/2012 Location: United KingdomPosts: 10197 |
Posted: 09:36am 01 Feb 2015 |
Copy link to clipboard |
 Print this post |
|
We have confirmed that there is a bug in SPI WRITE which causes problems for subsequent SPI READs. I'll PM Geoff to get it on the list. |
|