Problem with I2C

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Problem with I2C

Post by nikhiledutech » Thu Apr 26, 2018 5:36 am

Hello,

I am little confused about how I2c works in micropython.

Code: Select all

from machine import Pin, I2C

i2c = I2C(scl= ' PB8', sda = 'PB9')
buf_write = bytearray(5)	
buf_read  = bytearray(5)

for x in range(5):
	buf_write[x] = 1

#Writing buffer to memory address starting from 1 of slave at address 57
i2c.writeto_mem(57, 1,buf_write, addrsize=8)

#Reading into buffer from above slave from memory address starting at 1.
i2c.readfrom_mem_into(57,1,buf_read,addrsize =8)
		
So why my read data from the register is different from the written data into register ? Can anyone explain.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Problem with I2C

Post by pythoncoder » Thu Apr 26, 2018 6:26 am

What is your slave device?
Peter Hinch
Index to my micropython libraries.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: Problem with I2C

Post by nikhiledutech » Thu Apr 26, 2018 7:44 am

slave device is Color Sensor

Post Reply