SPI access on Raspberry Pi Connector


#1

How do I reference the SPI port on the Raspberry Pi connector? I want to access an SPI sensor that I have connected to the Raspberry Pi connector.


#2

Are you using a kernel module to access the sensor or are you writing user space code? Those two chip selects on the Raspberry Pi connector are from the CP2130 USB to SPI chip. Which sensor are you trying to talk to?


#3

I’m writing user space code and I’m trying to talk to an ADS1256 ADC. I also have an external BMP280 sensor that I’m using for troubleshooting the SPI interface.


#4

It’s a little bit complicated

  1. You have to configure the channel of the cp2130 by doing something like this: echo -n 1,2,-1,0,0,1,0,0,0,0,0,spidev > /sys/devices/platform/msm_hsic_host/usb1/1-1/1-1.1/1-1.1:1.0/channel_config. Please look at the switch statement in channel_config_store() in the cp2130 driver to understand the meaning of each value in that string. Specifically, you might want to modify the phase, polarity, speed and chip select (aka channel) depending on which CS you are connected to on the rpi header.
  2. In the previous step, we provided “spidev” as the last parameter. That is the modalias of the SPI device to associate with that chip select. spidev is the device that will create /dev/spidevN.N files. In the wp85 kernel, spidev is built as a module. Do modprobe spidev to load it. After doing that you should have a new /dev/spidevN.N file.
  3. I’m not sure if you’re using the Legato SpiService, but if you are, then there’s another issue. The problem is that right now, SpiService is a sandboxed app and it only does “requires device” on spidev0.0. You will have to modify the app to bring in the spidev device that is created above. Also I would suggest changing the start attribute to manual so that the app doesn’t fail to start due to your spidev entry not existing at the time legato starts.

#5

Thanks for getting back to me so quickly. I tried to run the first command and it failed with Permission denied.

root@swi-mdm9x15:/# echo -n 1,2,-1,0,0,1,0,0,0,0,0,spidev > /sys/devices/platform/msm_hsic_host/usb1/1-1/1-1.1/1-1.1:1.0/channel_config
-sh: can’t create /sys/devices/platform/msm_hsic_host/usb1/1-1/1-1.1/1-1.1:1.0/channel_config: Permission denied


#6

Are you using the mangOH_Red.sdef to build your system? Is the cp2130 module loaded? Do lsmod | grep cp2130 to check.


#7

I believe I am using mangOH_Red.sdef, but the cp2130 module is not loaded.


#8

In my mangOH_Red.sdef, cp2130 has been disabled because of some lockup issue. Is it safe to uncomment that line?


#9

I think your mangOH repository is a bit out of date. Try running:

git pull && git submodule init && git submodule update in the mangOH folder.


#10

I have updated my mangOH repository and the command now runs and modprobe finds the new SPI port.

I needed to slow down the clock frequency a little so I modified the command as follows:
echo -n 1,2,-1,0,0,1,3,0,0,0,0,spidev > /sys/devices/platform/msm_hsic_host/usb1/1-1/1-1.1/1-1.1:1.0/channel_config

I’ve been using a logic analyzer to track down my current SPI problem, which is that MISO pin 21 on the Raspberry Pi connector doesn’t return any data when I send the command on the MOSI pin 19. If i disconnect the wire that is connected to the MISO pin, the output data shows up on the logic analyzer. So I’m thinking there is another configuration setting I’m missing.

Any ideas?


#11

Hello,

I still need help with the configuration of the SPI port on the Raspberry Pi Connector. I would greatly appreciate any guidance on fixing the issue I outlined in my previous post.

Thanks.


#12

I don’t understand. Are you saying that you only see MOSI data on the logic analyzer if the logic analyzer is not also connected to MISO? Does the logic analyzer have ground wires and are they connected? Do you have the clock connected to the logic analyzer and can you see that?


#13

I know it sounds unusual and I will try to explain in more detail. I will start with what works correctly. When I connect the SPI pins of the ADC to the IOT card pins 16,17,18,19 and power to pins 29,30, the ADC chip works perfectly with the logic analyzer connected to the SPI pins. The ground pins of the logic analyzer are not connected. I have attached screen capture of the logic analyzer output and this is what I am expecting.

Now I connect the SPI pins on ADC to the Raspberry Pi connector as follows:
SPI_CLK -> Pin 23
SPI_MISO -> Pin 21
SPI_MOSI -> Pin 19
SPI_SS/MRDY -> 24
3.3V -> Pin 17
GND -> Pin 20

The following is the output from the logic analyzer:


You can see that no data is being returned on the MISO pin.

With logic analyser still connected, I disconnect the wire on Pin 21 of the Raspberry Pi connector and get the following result:


You can see the data on the MISO return.

If I reconnect pin 21 and disconnect the logic analyser from the circuit, I still don’t get a result from the ADC which tells me that no data is being transmitted on the the MISO pin.

So it seems to me that pin 21 is not configured correctly. Let me know if you need any more info.


#14

Thanks for the details. I will try to look into this a bit more tomorrow. Nothing immediately jumps out at me as an obvious problem though.


#15

So the ADC I having this difficultly with is the MCP3004. I have been trying other SPI sensor boards and I can get the BMP280 to work, meaning data is returned on MISO pin. I’m currently troubleshooting a ADS1256 and I am getting register data. So it does look like pin 21 is configured correctly. I just can’t understand why the MCP3004 works correctly with the IOT SPI and not with the Raspberry Pi Connector SPI. I’ve tried adding a pull-up resistor on pin 21, but that didn’t fix it. Thanks for looking into this.