# WP7702 using SPI

**URL:** <https://mangoh.discourse.group/t/wp7702-using-spi/1188>\
**Category:** mangOH Red\
**Created:** [February 21, 2018, 7:09am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188 "2018-02-21T07:09:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![basti](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@basti](https://mangoh.discourse.group/u/basti)\
**Post date:** [February 21, 2018, 7:09am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/1 "2018-02-21T07:09:04Z")

</div>

Hi,

I am using a WP7702 module and I was wondering if anyone has gotten the spidev working on a similar module? Outcome of running spidev seen below. Related post on Legato forum:

> **[WP77 problems with SPI and i2c](https://forum.legato.io/t/wp77-problems-with-spi-and-i2c/3006/17)**
>
> Thank you @jyijyi very much! This solved the issue, now I can compile the drivers and find them under /sys/devices directory. I did not have to change anything in \\linux\_kernel\_modules\\mangoh\\board\_red\_dv3.c. or similar as you described. I...

> Jan 31 07:03:30 | supervisor[7972]/supervisor T=main | app.c GetDevID() 644 | Could not get file info for ‘/dev/spidev0.0’. No such file or directory.  
> Jan 31 07:03:30 | supervisor[7972]/supervisor T=main | app.c SetCfgDevicePermissions() 754 | Failed to set permissions (rw) for app ‘spiService’ on device ‘/dev/spidev0.0’.

Spisvc is installed, and lsmod gives this:

> root@swi-mdm9x28:~# lsmod  
> Tainted: G  
> spisvc 1069 0 - Live 0xbf000000 (O)

Modprobe:

> root@swi-mdm9x28:~# modprobe spidev  
> modprobe: module spidev not found in modules.dep

There is one spidev installed on the module, but it is not working:

> root@swi-mdm9x28:~# ls /dev/spi  
> /dev/spidev1.0

Is this just a firmware / kernel issue?

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [February 21, 2018, 5:18pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/2 "2018-02-21T17:18:53Z")

</div>

On the wp76xx and wp77xx, the primary i2c bus is 1 (instead of 0 on the wp85 and wp75). I think we just need to add a few `ifdefs` to make it work. I will try to do that now.

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [February 21, 2018, 7:33pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/3 "2018-02-21T19:33:10Z")

</div>

I have submitted a [pull request](https://github.com/legatoproject/legato-af/pull/24) to the legato-af repository. If you apply this change to your Legato source code and then add the `spisvc` kernel module to your SDEF, then it should be possible to use the spiService app on the wp77xx or wp76xx platforms.

---

<div class="post-metadata">

**Author:** ![basti](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@basti](https://mangoh.discourse.group/u/basti)\
**Post date:** [February 26, 2018, 9:53am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/4 "2018-02-26T09:53:19Z")

</div>

Hi @dfrey,

Left a comment on your pull request. You can now start spiService with those changes, but it does not read anything from the spi bus. I have a HX711 ADC converter (with a weight sensor) I have used with the WP8548 which works fine, but no readings when connected to WP7702.

> root@swi-mdm9x28:~# lsmod  
> Tainted: G  
> spisvc 1069 0 - Live 0xbf052000 (O)  
> 9\_mangoh\_red\_dv5 8893 0 - Live 0xbf04b000 (O)  
> 4\_bmi160\_i2c 1396 0 - Live 0xbf047000 (O)  
> 3\_bmp280\_i2c 2631 0 - Live 0xbf043000 (O)  
> 3\_bmi160 5472 1 4\_bmi160\_i2c, Live 0xbf03e000 (O)  
> 2\_bmp280 9493 1 3\_bmp280\_i2c, Live 0xbf033000 (O)  
> 0\_ltc294x 5575 0 - Live 0xbf02a000 (O)  
> 0\_iot\_slot 14701 0 - Live 0xbf022000 (O)  
> 0\_cp2130 20486 0 - Live 0xbf007000 (O)  
> 0\_bq24296 10844 0 - Live 0xbf000000 (O)

> root@swi-mdm9x28:~# ls /dev/_spi_  
> /dev/spidev1.0

And I did change my code to check for spidev1.0, not 0.0 as for WP8548. Is there some configuration I am missing? Are the parameters / SPI-pins different for WP7702 (MOSI, MISO, CLK)?

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [February 27, 2018, 4:08pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/5 "2018-02-27T16:08:33Z")

</div>

I’m going to look at the SPI pins on a logic analyzer and see if anything looks off. I will update later today.

---

<div class="post-metadata">

**Author:** ![basti](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@basti](https://mangoh.discourse.group/u/basti)\
**Post date:** [March 1, 2018, 10:23am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/6 "2018-03-01T10:23:01Z")

</div>

Did you find anything? Just something I forgot previously: changing the speed of the spi device did give different readings (`le_spi_Configure()`). But the readings were always static, there was no difference. I used 96000bps for WP8548, tried that and different speeds on WP7702 but nothing.

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [March 1, 2018, 2:27pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/7 "2018-03-01T14:27:16Z")

</div>

Some other stuff came up so I didn’t get to it. I haven’t forgotten about it though. Will update here when I have some new information.

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [March 1, 2018, 7:01pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/8 "2018-03-01T19:01:23Z")

</div>

I ran this code and observed the expected pattern on the CS, CLK and MOSI lines.

```
COMPONENT_INIT
{
    LE_INFO("===========> SPI application has started");

    le_result_t res;

    spi_DeviceHandleRef_t spiHandle;
    res = spi_Open("spidev1.0", &spiHandle);
    LE_FATAL_IF(res != LE_OK, "spi_Open failed with result=%d", res);

    LE_INFO("Configuring SPI");
    spi_Configure(spiHandle, 0, 8, 960000, 0);

    LE_INFO("Performing a SPI write of 16 bytes");
    {
        const uint8_t writeData[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
        LE_ASSERT_OK(spi_WriteHD(spiHandle, writeData, NUM_ARRAY_MEMBERS(writeData)));
    }
    LE_INFO("SPI write completed successfully");

    spi_Close(spiHandle);
}

```

I will try to connect a device now to test the read behavior.

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [March 1, 2018, 9:53pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/9 "2018-03-01T21:53:52Z")

</div>

I successfully performed a loopback test and also did a read of a register on the CAN IoT card and got a valid value back. One small detail is that I’m using a WP76 using release 8, not a WP77, but I don’t expect there to be a difference.

Can you try a loopback test?

---

<div class="post-metadata">

**Author:** ![basti](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@basti](https://mangoh.discourse.group/u/basti)\
**Post date:** [March 2, 2018, 9:42am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/10 "2018-03-02T09:42:35Z")

</div>

Hi @dfrey,

With loopback test you simply sent data master-\>slave-\>master and checked data was still the same? So using spiWriteReadFD / spiWriteReadHD function?

I can do some testing on Monday. There is only Release 7 available, maybe there were some changes to Release 8? Could you provide me with a beta version of the new release so I can try it out as well?  
Our contact person who provided us with the WP77xx module said he would look into it and see if we could try it out. Thanks, and have a great weekend!

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [March 2, 2018, 4:17pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/11 "2018-03-02T16:17:18Z")

</div>

The loopback test is achieved by wiring the MOSI and MISO lines together and then using `spiWriteReadFD`. The `spiWriteReadHD` function is useless in this case because there will be no data being driven on MOSI when MISO is being read. I think wp76 release 8 will show up in the next couple days on [source.sierrawireless.com](http://source.sierrawireless.com). I looked at the changes though and I don’t see anything relating to SPI so I doubt that will make a difference.

---

<div class="post-metadata">

**Author:** ![basti](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@basti](https://mangoh.discourse.group/u/basti)\
**Post date:** [March 5, 2018, 7:44am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/12 "2018-03-05T07:44:35Z")

</div>

Unfortunately looks like I will not have time right now to do further testing with the SPI. But I will get back to you if/when I have tried it out.

---

<div class="post-metadata">

**Author:** ![basti](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@basti](https://mangoh.discourse.group/u/basti)\
**Post date:** [May 3, 2018, 12:50pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/13 "2018-05-03T12:50:45Z")

</div>

Hi @dfrey,

Unfortunately it is a bit difficult for me to run the loopback test, but I have been testing the weight sensor again with WP77. For some reason I cannot get it reading properly. Have you, or someone else, tried with a WP77?

This is the function I am running (if you want I can give the whole code):

> int32\_t readWeightSensor(){  
> size\_t readBufferSize = NUM\_ARRAY\_MEMBERS(rxData);  
> res = le\_spi\_WriteReadFD(spiHandle, txData, NUM\_ARRAY\_MEMBERS(txData), rxData, &readBufferSize);  
> LE\_FATAL\_IF(res != LE\_OK, “le\_spi\_WriteReadFD failed with result=%s”, LE\_RESULT\_TXT(res));  
> int32\_t weight = transform\_to\_weight\_bits(rxData);  
> return (weight-683500)/2180; // Calibration  
> }

And the init:

> LE\_INFO(“Opening SPI file handle”);  
> res = le\_spi\_Open(“spidev1.0”, &spiHandle);  
> LE\_FATAL\_IF(res != LE\_OK, “le\_spi\_Open failed with result=%s”, LE\_RESULT\_TXT(res));  
> LE\_INFO(“Configuring SPI”);  
> le\_spi\_Configure(spiHandle, 3, 8, 960000, 0);

This same code is working on a WP8548 (except for the change to spidev 0.0). Any help here would be appreciated! Thanks.

---

<div class="post-metadata">

**Author:** ![mehdi.ALL](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mehdi.ALL](https://mangoh.discourse.group/u/mehdi.ALL)\
**Post date:** [June 25, 2018, 9:15am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/15 "2018-06-25T09:15:22Z")

</div>

Hi @basti,

you need to change your spiService.adef in legato AF to adapt it to your module. I’ll explain :

As it is described in [legato.io](http://legato.io), Services APIs allows to access the APIs the associated services must be running on the Legato System before you can use the API.

In your case SpiService App allows to :

using LEGATO SPI API.  
using /dev/spidev (bus. device)  
by default, it uses /dev/spidev0.0 bus, but for wp77xx is different, because this module uses the /dev/spidev1.0 bus  
TO CHANGE THE SPISERVICE :

Do: vi ~/legato\_framework/legato-18.01.0/apps/platformServices/spiService.adef  
and change the spidev.

> version: 0.1.0  
> sandboxed: true  
> start: auto  
> executables:  
> {  
> spiService = ( $LEGATO\_ROOT/components/spiService )  
> }  
> processes:  
> {  
> envVars:  
> {  
> LE\_LOG\_LEVEL = INFO  
> }  
> run:  
> {  
> (spiService)  
> }  
> faultAction: restart  
> #if ${LEGATO\_SERVICES\_WDOG\_DISABLE} = 1  
> watchdogTimeout: never  
> #else  
> watchdogTimeout: 120000  
> #endif  
> }  
> requires:  
> {  
> device:  
> {  
> [rw] /dev/spidev1.0/dev/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*HERE  
> }  
> extern:  
> {  
> spiService.spiService.le\_spi  
> }  
> bindings:  
> {  
> spiService.watchdogChain.le\_wdog → .le\_wdog  
> }

1. go to : ~/legato\_framework/legato-18.01.0 and do make wp77xx ( to compile legato AF for new changes )
2. go to ~/legato\_framework/legato-18.01.0/build/wp77xx/system/app/spiService  
o you find spiService.wp77xx.update (check the build date)

> drwxrwxr-x 5 mangoh mangoh 4096 Jun 21 16:36 ./  
> drwxrwxr-x 25 mangoh mangoh 4096 Jun 21 16:34 …/  
> drwxrwxr-x 3 mangoh mangoh 4096 Jun 21 16:34 obj/  
> -rw-rw-r-- 1 mangoh mangoh 20848 Jun 21 16:40 spiService.wp77xx  
> -rw-rw-r-- 1 mangoh mangoh 20969 **Jun 21 16:40 spiService.wp77xx.update**  
> drwxrwxr-x 3 mangoh mangoh 4096 Jun 21 16:34 src/  
> drwxrwxr-x 3 mangoh mangoh 4096 Jun 21 16:40 staging/

you do : update spiService.wp77xx.update 192.168.2.2 (to flash your target with a new spiService app)

- In your target \*

> root@swi-mdm9x28:~# app status  
> [running] atAirVantage  
> [running] atQmiLinker  
> [running] atService  
> [running] audioService  
> [running] avcService  
> [running] cellNetService  
> [running] dataConnectionService  
> [running] fwupdateService  
> [running] gpioService  
> [running] modemService  
> [running] portService  
> [running] positioningService  
> [running] powerMgr  
> [running] secStore  
> [stopped] smsInboxService  
> [stopped] tools  
> [stopped] voiceCallService  
> [stopped] wifi  
> [stopped] wifiApTest  
> [stopped] wifiClientTest  
> [running] wifiService  
> [stopped] wifiWebAp  
> **[stopped] spiService**  
> [stopped] spiFORspi  
> root@swi-mdm9x28:~# ls /dev/spidev\*  
> ls: /dev/spidev\*: No such file or directory  
> root@swi-mdm9x28:~# insmod spisvc.ko  
> root@swi-mdm9x28:~# ls /dev/spidev\*  
> /dev/spidev1.0  
> In the scope we can see the signal of the clock that corresponds to mode 0  
> root@swi-mdm9x28:~# app start spiService  
> root@swi-mdm9x28:~# app status  
> [running] atAirVantage  
> [running] atQmiLinker  
> [running] atService  
> [running] audioService  
> [running] avcService  
> [running] cellNetService  
> [running] dataConnectionService  
> [running] fwupdateService  
> [running] gpioService  
> [running] modemService  
> [running] portService  
> [running] positioningService  
> [running] powerMgr  
> [running] secStore  
> [stopped] smsInboxService  
> [stopped] tools  
> [stopped] voiceCallService  
> [stopped] wifi  
> [stopped] wifiApTest  
> [stopped] wifiClientTest  
> [running] wifiService  
> [stopped] wifiWebAp  
> **[running] spiService**  
> [stopped] spiFORspi

---

<div class="post-metadata">

**Author:** ![Madan](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Madan](https://mangoh.discourse.group/u/Madan)\
**Post date:** [September 6, 2018, 2:10pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/16 "2018-09-06T14:10:24Z")

</div>

Hi @dfrey

I am trying to use spiService for an external device. I had connected device to RPi connector (SPI0).

I tried to run the spiService, but it wont return/exit.

Jan 6 04:04:26 swi-mdm9x28 user.info Legato: INFO | supervisor[655]/supervisor T=main | app.c app\_Start() 2926 | Starting app ‘spiService’  
Jan 6 04:04:26 swi-mdm9x28 user.info Legato: INFO | supervisor[655]/supervisor T=main | kernelModules.c ExecuteCommand() 190 | Execute ‘/legato/systems/current/modules/files/spisvc/scripts/install.sh /legato/systems/current/modules/spisvc.ko’

I checked the install.sh…there is a forever loop running. probably, it is not finding /dev/spisvc. I dont see that either in /dev.

KO\_PATH="$1"  
insmod “$KO\_PATH”

while [-z “$(find -name “/dev/spisvc\*”)”]  
do  
sleep 1  
done

I dont see the /dev/spisvc. but lsmod shows that spisvc exist.

root@swi-mdm9x28:/dev# lsmod  
Tainted: G  
spisvc 1069 0 - Live 0xbf003000 (O)

I do see that spidev1.0 available in /dev.

my application will not run because execution of spiService is stuck in the loop.

Any hack to jump out of this?

Thanks  
Madan

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [September 6, 2018, 3:30pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/17 "2018-09-06T15:30:43Z")

</div>

The Legato 18.07.0 release was a bit screwed up. A commit snuck in which broke SPI. I have updated the [Legato\_patches](https://github.com/mangOH/Legato_patches) repository for 18.07.0 to include a patch which corrects the SPI issue.

---

<div class="post-metadata">

**Author:** ![Madan](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Madan](https://mangoh.discourse.group/u/Madan)\
**Post date:** [September 7, 2018, 9:25am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/18 "2018-09-07T09:25:53Z")

</div>

@dfrey, Thank you for the quick update.

It got me going. However, I got into a small issue. Maybe you know why.  
I am getting only zeros. I am using a MAX6675 breakout board.

SO -\> pin 21  
CS -\> pin 24  
SCLK -\> Pin 23

Config -  
le\_spi\_Configure(spiHandle, 0, 8, 4300000, 0);  
I tried different values for mode and frequency.

Any ideas where the issue might be?

Regards

---

<div class="post-metadata">

**Author:** ![Madan](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Madan](https://mangoh.discourse.group/u/Madan)\
**Post date:** [September 7, 2018, 1:19pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/19 "2018-09-07T13:19:11Z")

</div>

Hi @dfrey,

I tried the loopback suggestion.  
Connected MISO, MOSI pins together.

Here is the test code. But I get zeros in the read buffer.  
Appreciate your suggestions on this.

```
le_spi_Configure(spiHandle, 0, 8, 960000, 0);
LE_INFO("Performing a SPI write of 16 bytes");
{
    const uint8_t writeData[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
    uint8_t readBuffer[20] = {0,};
    uint32_t readBufferSize = NUM_ARRAY_MEMBERS(writeData);
    //LE_ASSERT_OK(le_spi_WriteHD(spiHandle, writeData, NUM_ARRAY_MEMBERS(writeData)));
    res = le_spi_WriteReadFD(spiHandle,writeData, NUM_ARRAY_MEMBERS(writeData), readBuffer,&readBufferSize );
    if (res == LE_OK){
        int i; 
        for (i = 0; i < readBufferSize; i++)
            LE_INFO("0x%X ",readBuffer[i]);
    }
    else{
        LE_FATAL_IF(res != LE_OK, "le_spi_WriteReadFD failed with result=%s", LE_RESULT_TXT(res));
    }

}
LE_INFO("SPI write completed successfully");
```

---

<div class="post-metadata">

**Author:** ![Madan](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Madan](https://mangoh.discourse.group/u/Madan)\
**Post date:** [September 10, 2018, 12:06pm UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/20 "2018-09-10T12:06:51Z")

</div>

I tried to ensure that the TC module functionality with Arduino and RPi. It is working on both setups using SPI.  
Please advise if I am missing something here on mangOH.

Thanks for your support.

---

<div class="post-metadata">

**Author:** ![Madan](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Madan](https://mangoh.discourse.group/u/Madan)\
**Post date:** [September 11, 2018, 11:58am UTC](https://mangoh.discourse.group/t/wp7702-using-spi/1188/21 "2018-09-11T11:58:02Z")

</div>

A quick update on the SPI on mangOH Red 18.07.0…  
I tried to capture the CLK and CS0 on an oscilloscope. Unfortunately, CS0 is stuck at HIGH and CLK at LOW. No change in them, even at different frequencies (modified through spi\_config).

Looks like something broken with SPI on RPI connector. Or Something not configured properly.  
@dfrey, @asyal need some help here to get SPI working on RPI connector.

Thanks for your support.

[Next page](https://mangoh.discourse.group/t/wp7702-using-spi/1188.md?page=2)
