# WP7702 i2C smbus kernel crash

**URL:** <https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714>\
**Category:** Legato Application Framework\
**Created:** [March 11, 2024, 9:33pm UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714 "2024-03-11T21:33:05Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://forum.legato.io/u/dan)\
**Post date:** [March 11, 2024, 9:33pm UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/1 "2024-03-11T21:33:05Z")

</div>

Hi All,  
I’m at a complete loss here. I’m trying to read from an I2C sensor using smbus with the i2c-dev library I’ve included

#include \<linux/i2c-dev.h\>  
#include \<sys/ioctl.h\>

but at the point of reading from the sensor the kernel crashes and the WP7702 restarts.  
I’ve attached my error log and how I read from the i2c bus.

[error](https://forum.legato.io/uploads/short-url/ilewdL1mJ5BHCLSWDptgYcOtYmq) (6.2 KB)  
[i2c read](https://forum.legato.io/uploads/short-url/r70ofW6oydj7xZJ2TKzHojq231n) (852 Bytes)

any ideas would be greatly appreciated.

Best regards Dan

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [March 12, 2024, 1:22am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/2 "2024-03-12T01:22:26Z")

</div>

how about using these existing i2c read command?

```auto
root@swi-mdm9x28-wp:~# i2c
i2cdetect i2cget i2cset.i2c-tools
i2cdetect.i2c-tools i2cget.i2c-tools i2ctransfer
i2cdump i2cgpioctl
i2cdump.i2c-tools i2cset

```

How about running this application in mangoh green board which is also using i2c?

> <https://github.com/mangOH/mangOH/tree/master/samples/tutorials/mangOH_Green/i2c/BatteryChargerReading>
>
> //github.com/mangOH/mangOH/tree/master/samples/tutorials/mangOH\_Green/i2c/BatteryChargerReading

---

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://forum.legato.io/u/dan)\
**Post date:** [March 12, 2024, 9:10am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/3 "2024-03-12T09:10:40Z")

</div>

None of those tools seem to support the smbus block read mode. I tried:  
i2cdump -y 4 -r 0x12-0x12 0x60 s to read from address 0x12 32 bits on device address 0x60. Says it’s not supported the device I’m trying to read from is an ACS37800 which has 32bit wide registers.

I’ll look into the github example later but that’s where my original code came from anyway.

Thanks for you help.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [March 12, 2024, 9:36am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/4 "2024-03-12T09:36:04Z")

</div>

can you read a word first?  
This can isolate if your application has problem (if the command has no problem)

---

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://forum.legato.io/u/dan)\
**Post date:** [March 12, 2024, 9:52am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/5 "2024-03-12T09:52:30Z")

</div>

I’m able to read a word without issue.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [March 12, 2024, 10:03am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/6 "2024-03-12T10:03:19Z")

</div>

here says you can read block data by i2cget:  
[https://manpages.debian.org/unstable/i2c-tools/i2cget.8.en.html](https://manpages.debian.org/unstable/i2c-tools/i2cget.8.en.html)

---

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://forum.legato.io/u/dan)\
**Post date:** [March 12, 2024, 10:36am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/7 "2024-03-12T10:36:26Z")

</div>

How would I use i2cget within a legato app?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [March 12, 2024, 10:37am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/8 "2024-03-12T10:37:29Z")

</div>

no, i mean if you confirm i2cget has no problem, then this points to your application problem

Then the next step is to port the source code of i2cget in yocto source to your application

---

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://forum.legato.io/u/dan)\
**Post date:** [March 13, 2024, 6:08pm UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/9 "2024-03-13T18:08:41Z")

</div>

Hi Sorry about the late reply I got tied up with other business.  
So copied like for like the batterychargerreading example. I get exactly the same kernel crash as previously provided.

I either can understand the command structure of i2cget or it just doesn’t work see below where I try and do an smbus read of 32 bits followed by reading a word.

```auto
root@swi-mdm9x28-wp:~# i2cget -y 4 0x60 0x12 c 32
BusyBox v1.31.1 () multi-call binary.

Usage: i2cget [-fy] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
root@swi-mdm9x28-wp:~# i2cget -y 4 0x60 0x12 w
0x0000

```

as you can see the word works just fine the response for the smbus seems like a malformed command has happened the link you provided does not give an example for smbus cmd c mode.

thanks for the help.

---

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://forum.legato.io/u/dan)\
**Post date:** [March 13, 2024, 6:10pm UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/10 "2024-03-13T18:10:16Z")

</div>

I seem to just get one byte back if I don’t provide a length for smbus read.

```auto
Usage: i2cget [-fy] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
root@swi-mdm9x28-wp:~# i2cget -y 4 0x60 0x12 c
0x00

```

---

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://forum.legato.io/u/dan)\
**Post date:** [March 13, 2024, 9:13pm UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/11 "2024-03-13T21:13:38Z")

</div>

Hi Also I’ve just found out after connecting logic analyser i2c\_smbus\_read\_block\_data only reads 2 bytes not 4.  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/2X/d/d19e81f0de5bd76ef5163d12817e365470053a4a.png)  
and i2c\_smbus\_read\_block\_data returns 0

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [March 14, 2024, 1:52am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/12 "2024-03-14T01:52:07Z")

</div>

how about using i2cdump?

```auto

root@fx30:~# i2cdump -y 4 0x68 i
     0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: d1 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?!..............
10: 00 00 00 00 00 00 00 00 e8 4f 07 10 00 00 00 00 ........?O??....
20: 00 80 00 00 80 80 80 80 80 80 80 80 80 80 80 80 .?..????????????
30: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ????????????????
40: 28 03 28 00 0b 88 80 10 00 00 00 20 80 42 4c 00 (?(.????... ?BL.
50: 00 00 00 00 00 00 00 00 00 00 07 30 81 0b c0 00 ..........?0???.
60: 14 14 24 04 0a 18 48 08 11 00 00 00 00 00 00 00 ??$???H??.......
70: 00 00 00 00 40 85 2b 00 00 00 15 03 00 00 00 00 ....@?+...??....
80: d1 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?!..............
90: 00 00 00 00 00 00 00 00 76 51 07 10 00 00 00 00 ........vQ??....
a0: 00 80 00 00 80 80 80 80 80 80 80 80 80 80 80 80 .?..????????????
b0: 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ????????????????
c0: 28 03 28 00 0b 88 80 10 00 00 00 20 80 42 4c 00 (?(.????... ?BL.
d0: 00 00 00 00 00 00 00 00 00 00 07 30 81 0b c0 00 ..........?0???.
e0: 14 14 24 04 0a 18 48 08 11 00 00 00 00 00 00 00 ??$???H??.......
f0: 00 00 00 00 40 85 2b 00 00 00 15 03 00 00 00 00 ....@?+...??....
root@fx30:~#

```

---

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://forum.legato.io/u/dan)\
**Post date:** [March 14, 2024, 9:29am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/13 "2024-03-14T09:29:41Z")

</div>

Well this method is usable but very cumbersome.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/2X/7/7aa697c0aeac1f8892657eae446a2bc4b199c3db.png)  
Thats what I get from a logic analyser and the response on the terminal is similar to yours however with my expected register values.

I can send this command via the system command to a file then parse the data out of the file to finally get my specific reading from the address. I would have thought there was a better way. Obviously the only issue is i2cdump is expecting each address to be 8bit but they are 32bit so the numbering that the terminal returns is incorrect.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [March 14, 2024, 9:46am UTC](https://forum.legato.io/t/wp7702-i2c-smbus-kernel-crash/6714/14 "2024-03-14T09:46:03Z")

</div>

> Obviously the only issue is i2cdump is expecting each address to be 8bit but they are 32bit so the numbering that the terminal returns is incorrect.

you might need to use i2ctransfer

e.g.

```auto
root@fx30:~# i2ctransfer -y 4 w1@0x68 0x00 r4
0xd1 0x21 0x00 0x00

```
