sameh4
Posts: 47
Joined: Wed Nov 29, 2017 6:58 pm

Trouble Connecting an RF Module over SPI

Sun Jun 24, 2018 6:13 pm

I am trying to connect the HopeRF RFM95W module to an Rpi-3.

Please see the below diagram for the schematic I am using:
RFM95W-breadboard_schem.png
Delete
RFM95W-breadboard_schem.png (98.61 KiB) Viewed 859 times
I connected the above a bread board:

1) Supplied 3.3V to the module using the Pi header #1.
2) Connected the SPI on channel 0.
3) Connected the Reset pin to GPIO27 (BCM)
4) Connected the DIO pin to GPIO17
5) Used WiringPi to:
5.1) Enable the DIO0 pin as INPUT
5.2) Reset the board by putting reset pin to high, then low
5.3) attempted to read the value at the RegVersion register address 0x42

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>

#include <wiringPi.h>
#include <wiringPiSPI.h>

#define REG_VERSION                 0x42

uint8_t ReadRegister(uint8_t addr)
{
  uint8_t spibuf[2];
  spibuf[0] = addr & 0x7F;
  spibuf[1] = 0x00;

  // SelectReceiver();
  wiringPiSPIDataRW(0, spibuf, 2);
  // UnselectReceiver();

  return spibuf[1];
}

int main(int argc, void* argv[])
{
  int fd, result;
  unsigned char buffer[100];
  wiringPiSetup();
  
  pinMode(0, INPUT);
  pinMode(2, OUTPUT);

  fd = wiringPiSPISetup(0, 500000);

  printf("able to setup SPI with fd %d\n", fd);
   
  digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(2, LOW);
  delay(100);
  uint8_t version = ReadRegister(REG_VERSION);

  printf("version has value %d\n", version);
  sleep(60);
  return 0;
}

Below is an image of the breadboard. I also connected LED's so I can see what's happening. Since the SPI driver is enabled, the CE0 pin is pulled high and thus the Led is on.

As the trial code executes, the Led for the Reset pin lights up for the 100 delay, then turns off, but the output from the RegVersion register is 0, where as it should be 0x11 as per the datasheet.

Page 85 on the datasheet . http://www.hoperf.com/upload/rf/RFM95_96_97_98W.pdf
The attachment IMG_0008_use.JPG is no longer available

sameh4
Posts: 47
Joined: Wed Nov 29, 2017 6:58 pm

Re: Trouble Connecting an RF Module over SPI

Sun Jun 24, 2018 6:14 pm

The image of the bread board is
IMG_0008_use.JPG
IMG_0008_use.JPG (207.3 KiB) Viewed 856 times

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Trouble Connecting an RF Module over SPI

Sun Jun 24, 2018 6:24 pm

You need to solder some header pins into that small circuit board. The pushed in wires won't make a reliable connection.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

sameh4
Posts: 47
Joined: Wed Nov 29, 2017 6:58 pm

Re: Trouble Connecting an RF Module over SPI

Sun Jun 24, 2018 9:48 pm

Hi Dougie,

I did that before doing this actually. Please see here:
IMG_0012_use.JPG
IMG_0012_use.JPG (141.4 KiB) Viewed 816 times

sameh4
Posts: 47
Joined: Wed Nov 29, 2017 6:58 pm

Re: Trouble Connecting an RF Module over SPI

Sun Jun 24, 2018 9:48 pm

And here
IMG_0009_use.JPG
IMG_0009_use.JPG (152.03 KiB) Viewed 816 times

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Trouble Connecting an RF Module over SPI

Mon Jun 25, 2018 10:36 am

Have you tried using python to work with your RFM69?

http://rpi-rfm69.readthedocs.io/en/latest/
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

baantonia
Posts: 63
Joined: Fri Feb 06, 2015 2:19 pm

Re: Trouble Connecting an RF Module over SPI

Mon Jun 25, 2018 1:44 pm

I might be completely wrong but looking at the documentation on page 11, the column "Type" appears incorrect for the use for pins 2 and 3, are they round the wrong way?

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Trouble Connecting an RF Module over SPI

Mon Jun 25, 2018 2:05 pm

baantonia wrote:
Mon Jun 25, 2018 1:44 pm
I might be completely wrong but looking at the documentation on page 11, the column "Type" appears incorrect for the use for pins 2 and 3, are they round the wrong way?
I think that's just a typo in the docs.

Pin#2 is MISO which connects to RPi MISO pin#21 (BCM09)
Pin#3 is MOSI which connects to RPi MOSI pin#19 (BCM10)
Pin#4 is SCK which connects to RPi SCLK pin#23 (BCM11)
Pin#5 is NSS which connects to RPi CE0/SS0 pin#24 (BCM08)

That means the RF module should appear at /dev/spidev0.0
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

sameh4
Posts: 47
Joined: Wed Nov 29, 2017 6:58 pm

Re: Trouble Connecting an RF Module over SPI

Mon Jun 25, 2018 7:05 pm

Thanks Dougie! As I showed, I had soldered wires onto one module (it's RFM95W btw not 69 -- maybe the 69 has the same config, not sure yet).

Today I am going to solder breadboard pins onto the module, making sure to cut the excess in the back before soldering. Then retry the code. If that doesn't work, I'll take a look at the python library.

Btw I tested this same code against an Arduino sketch (as a SPI slave) and it works fine.

Code: Select all

#include <SPI.h>

//slave
#define  GPS_COORDINATES   0x42

uint8_t response = 0x11;

bool bGpsCoordinates = false;

void setup() {
  Serial.begin(115200);
  pinMode(MISO, OUTPUT);  //have to send on MISO, pin 12 on UNO
  SPCR |= _BV(SPE);  //Turn on SPI in slave mode
  SPI.attachInterrupt();  //turn on interrupt
}

// SPI interrupt routine
ISR (SPI_STC_vect) {
  byte c = SPDR;  //grab a byte from SPI data register
  switch(c) {
    case GPS_COORDINATES:
      SPDR = response; //THIS WORKS
      bGpsCoordinates = true;
      break;
  }
}

// wait for flag to set in interrupt routine
void loop() {
   if(bGpsCoordinates) {
//     charToSend = coordinatesArray[counter];
//     counter++;
     Serial.println(response);
     
     bGpsCoordinates = false;
   }
}

sameh4
Posts: 47
Joined: Wed Nov 29, 2017 6:58 pm

Re: Trouble Connecting an RF Module over SPI

Tue Jun 26, 2018 4:39 am

After soldering the breadboard jumpers onto the module, then using F-F jump cables to connect to the Pi, the sample code in the OP works just fine. It prints out the value 0x12, which the value for the SX1276 chip!

The code for a single channel gateway also works https://github.com/hallard/single_chan_ ... kt_fwd.cpp .. I still need to send it data from a sensor, but that cpp code executes fine, and prints out
Trying to detect module with NSS=10 DIO0=0 Reset=2 Led1=unused
SX1276 detected, starting.
Gateway ID: b8:27:eb:ff:ff:bd:5a:7c
Listening at SF7 on 868.100000 Mhz.
-----------------------------------
stat update: 2018-06-26 04:19:12 GMT no packet received yet

Return to “Interfacing (DSI, CSI, I2C, etc.)”