2
\$\begingroup\$

I am trying to write data to a register on an I2C chip from the Raspberry Pi, when I use i2cdetect I get UU, which I understand is an error.

sudo i2cdetect -y 1

   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU 
70: -- -- -- -- -- -- -- --                         

When I try to use SMbus python module to write to the desired register I get the following error:

bus.write_byte_data(DEVICE_ADDRESS, CONTROL_REG, CON_VAL)
IOError: [Errno 16] Device or resource busy

Are there any usual reasons for this or things to try?

\$\endgroup\$
2
\$\begingroup\$

This typically means that you have already loaded a driver which is accessing this device.

Unload the driver using e.g. rmmod and you should be good to go.

Just to mention it: You can also use i2cset and i2cget to set and get values directly instead of altering via Python.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks that did the trick (used modprobe -r), i2cdetect and smbus now work. I would like to try write to the register when the module is started in a bash script here: modprobe i2c-dev modprobe i2c:mcp7941x echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-$i/device/new_device any ideas how to? \$\endgroup\$ – holmeswatson Jun 15 '14 at 17:09
  • \$\begingroup\$ would i2cset be the correct thing to use? \$\endgroup\$ – holmeswatson Jun 15 '14 at 17:22
  • \$\begingroup\$ That's probably the easiest thing to do, yes. Yet, you need to call i2cset BEFORE you load the module. Once the module is loaded, only the module may access the device. I don't know if it fits your design, but you could also modify the driver to perform that access during the driver init. \$\endgroup\$ – Tom L. Jun 15 '14 at 18:12
  • \$\begingroup\$ thanks for this clue, but still not quite getting it. what is the module you guys are referring to exactly? i.e. you say "unload the driver using rmmod <module here>" or "used mmodprobe -r <module here>". which driver or module? \$\endgroup\$ – user391339 Nov 23 '14 at 7:07
  • \$\begingroup\$ The module is "probably" named mcp7941x, there should be an appropriate driver for it named something like mcp7941x.ko in your file system at /etc/modules. Yet, this is just a guess. i2cdetect doesn't actually tell you which device uses a specific address, just that one does. \$\endgroup\$ – Tom L. Nov 23 '14 at 9:04
0
\$\begingroup\$

Though it is very late to answer this, recently I had similar issue with my 9$ chip's i2c module axp209 (power management IC).

By default i2-tools/py-smbus module does not provide an option to forcefully open a i2c-device-address( for safe reasons). But i2get command gives option '-y' to read/write.

So i forked i2c-tools/py-smbus in github to allow python code also to have similar option. I have changed 3 lines in python module code.

One can see example of my modified python module code at py-smbus github.

This modified py-smbus modules can be used for raspberry also

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.