Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

"write_i2c_block_data" not working: 16-Channel 12-bit PWM Dr

by Immobilizer on Wed Oct 09, 2013 5:03 pm

Hi Everybody,

Has anyone had luck with I2C block reading/writing commands with this device (http://www.adafruit.com/products/815)? Here's what happened when I executed the following commands:
Code: Select all
>>> from smbus import SMBus
>>> bus = SMBus(1)
>>> bus.read_i2c_block_data(0x40, 0, 10)
[17, 17, 17, 17, 17, 17, 17, 17, 17, 17]
>>> bus.read_byte_data(0x40, 0)
17
>>> bus.read_byte_data(0x40, 1)
4
>>> bus.read_i2c_block_data(0x40, 1, 10)
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
>>> bus.write_i2c_block_data(0x40, 6, [5,4,3,2,1,10,9,8,7,6])
>>> bus.read_i2c_block_data(0x40, 6, 10)
[6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
>>> bus.read_i2c_block_data(0x40, 5, 12)
[224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224]
>>> bus.read_i2c_block_data(0x40, 7, 12)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> bus.read_i2c_block_data(0x40, 6, 12)
[6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
>>> bus.read_i2c_block_data(0x40, 8, 12)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> bus.read_i2c_block_data(0x40, 8, 12)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]


The "read_i2c_block_data" method appears to be reading the first byte, then filling the rest of the list with that byte.
The "write_i2c_block_data" method appears to write the last byte in the list to the starting register, but will not write any more bytes.

What am I doing wrong? I'd rather not have to initiate a new I2C command for every byte with something like
Code: Select all
bus.write_byte_data


Thanks for your help!
Immobilizer
 
Posts: 2
Joined: Thu Apr 25, 2013 2:28 pm

Re: "write_i2c_block_data" not working: 16-Channel 12-bit PW

by adafruit_support_mike on Thu Oct 10, 2013 1:19 am

Take a look at page 32 of the PCA9685 datasheet: http://www.adafruit.com/datasheets/PCA9685.pdf

When you talk to the PCA9685, you start by setting the MODE1 and MODE2 bytes. Those tell the chip what to do. Then you trigger a restart event and send any extra data. To read/write all the registers in the chip, you need to set the 'autoincrement' bit in the MODE2 register.

The sequence is a bit more complicated than a simple continued read.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7041
Joined: Thu Feb 11, 2010 1:51 pm