How do you know what the address of the I2C device register is when using the writeRegister function?

7 vues (au cours des 30 derniers jours)
Hello,
I have the following setup code. This connects an arduino and an I2C device (MCP23008).
a = arduino('/dev/tty.usbmodem1421','uno','Libraries','I2C');
dev = i2cdev(a,'0x20');
Now I am trying to figure out how to write data to control the device. I am trying the following:
writeRegister(dev, 32, uint8(bin2dec('10101010')))
I thought the register (32 above) would be the address property I get from dev.Address but nothing is happening on the board. Any ideas on how do I know what address I need to target or is the data that I am trying to send actually incorrect?

Réponses (1)

Walter Roberson
Walter Roberson le 7 Mar 2019
The 23008 is an 8 bit I2C interface.
The 0x20 is the port number on the arduino. dev.Address is returning that in decimal form (32). However when you write a register you need to send the register number. Which register number you should send depends what you are trying to do.
See http://ww1.microchip.com/downloads/en/AppNotes/01043a.pdf for a list of register names and addresses, and note that you need to use the left half (8 bit) of that diagram only.

Catégories

En savoir plus sur Arduino Hardware dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by