MCP4561 Digital Potentiometer and 9bit Registers #12478
-
Folks, |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 13 replies
-
The datasheet is rather confusing. Figure 7.3 suggests that the The figure is confusing because it appears to show 9-bit writes which is how the chip sees things, but the ACK bits reveal what is happening in terms of the interface behaviour. You could use a longer buffer to update multiple registers as shown in the figure, but as a starting point I would just update one. |
Beta Was this translation helpful? Give feedback.
-
It is an unusual chip, and I should issue a disclaimer here: though I've used several I2C devices they were all much simpler than this one. Reading seems particularly difficult. I think what you have to do to read a register is first prime the device with the address. This involves sending two bytes, the first being the chip address (the low order bits set by pins on the chip). The second byte is the device memory address and the command. Having set the register address, you then do a read using the chip address, which will return two data bytes. However I'm unsure about the bus state between the two transfers. To be honest I would expect to spend an hour or so with the chip and a logic analyser to get this right. I would concentrate on writing, which looks simpler. In general you can keep a record of what you've written, so reading is often unnecessary. Check the effectiveness of your writes by observing the behaviour of the pot. Writing seems to consist of sending three bytes, which should be simple. The first byte is the chip address, as described above. Then the write command made up of 4 bits of register address, three 0 bits, and the data MSB. Lastly the eight data LS bits. |
Beta Was this translation helpful? Give feedback.
-
It seems to me that your write is only updating 8 of the 9 bits. To write to arbitrary registers I would try: def set_wiper(self, value, reg):
value &= 0x1FF # Ensure only 9 bits
reg &= 0xF # Limit to 4 bits
vb = value.to_bytes(2, 'little')
self.i2c.writeto_mem(self.address, vb[1] | (reg << 4), vb[:1]) |
Beta Was this translation helpful? Give feedback.
-
The text describes A0 as having a weak pull up on POR. |
Beta Was this translation helpful? Give feedback.
-
The read_reg isnt quite working properly. It returns the incorrect value. A POR sets the wiper memory location 0x00 to hold 0x80. |
Beta Was this translation helpful? Give feedback.
-
OK..... A typo in your 'bytearray' word on line 3 (I didnt spot it until about the 10th read of my typing), def read_reg(self, reg): def set_wiper(self, value, reg): |
Beta Was this translation helpful? Give feedback.
Sorry, I don't know a suitable book. Perhaps someone else can advise?
I think your read bit manipulation should be
because
t[0]
holds the MSB andt[1]
holds B7...B0.However before performing a read, you need to write a single byte comprising the register address and read command as per fig 7.4. Something like