nonNoise / PyMCP2221A

MCP2221 & MCP2221A work in Python.
MIT License
36 stars 21 forks source link

i2c / smbus write to slave issue (mcp2221, mcp9902) #18

Open manikandan19861 opened 2 years ago

manikandan19861 commented 2 years ago

Project background:

can you please provide api line snippet to read 0xFE register of slave 0x4C (mcp9902) and writing 0x05 register

I tried following these and ended up getting -1 in read

code (note: i2c slave detection is fine):

#############################################################

MIT License

Copyright (c) 2017 Yuta KItagami

############################################################# from PyMCP2221A import PyMCP2221A

import time print('-'50) print('MCP2221(A) i2cdetect ') print('-'50) mcp2221 = PyMCP2221A.PyMCP2221A() mcp2221.Reset() mcp2221 = PyMCP2221A.PyMCP2221A()

from PyMCP2221A import SMBus

bus = SMBus.SMBus()

mcp2221.I2C_Init()

print(" 0 1 2 3 4 5 6 7 8 9 A B C D E F ") for i in range(0x00,0x7F) : if(i%16==0 and i>0): print(" {:02X}".format(i-1))

if(mcp2221.I2C_Read(i,1) != -1):
    print('  {:02X}'.format(i), end='')
else:
    print('  --', end='')
#time.sleep(0.1)

print("")

rdata = mcp2221.I2C_Read(0xFE, 1) print("rdata is ...", rdata)

rdata = mcp2221.I2C_Read(0x05, 1) print("rdata is ...", rdata)

rdata = mcp2221._i2c_read(0xFE, 1, [0x0, 0x1]) print("rdata is ...", rdata)

rdata = mcp2221._i2c_read(0x05, 1, [0x0, 0x1]) print("rdata is ...", rdata)

rdata = mcp2221._i2c_read(0x4C, 1, [0xFE, 0x1]) print("rdata is ...", rdata)

Output:

C:\Inicio\tools\64\MinicondaInicio-1.0.0.1\python.exe C:/Users/IFXpowerteam/PycharmProjects/adm000615/mcp2221.py

MCP2221(A) i2cdetect

Reset 0 1 2 3 4 5 6 7 8 9 A B C D E F
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 0F -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1F -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2F -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3F -- -- -- -- -- -- -- -- -- -- -- -- 4C -- -- -- 4F -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 5F -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6F


rdata is ... -1 rdata is ... -1 [0x91:0xee,0x00,0x20] rdata is ... -1 [0x91:0xee,0x00,0x20] rdata is ... -1 [0x91:0xee,0x00,0x20] rdata is ... -1

Process finished with exit code 0

nonNoise commented 2 years ago

Thank you for your question. Also thank you for your email. I'm very sorry, but I don't know much about SM-Bus either. I think I2C and SM-Bus are the same thing. If there is a difference, it may not be supported. Also, looking at the evaluation board ADM00615, it seems that you are operating using GPIO.

So far, I can't give a good answer. I'm sorry. Thank you.