eblot / pyftdi

FTDI device driver written in pure Python
Other
509 stars 212 forks source link

different behavior between i2cdetect and i2cwrite #282

Closed camelator closed 2 years ago

camelator commented 2 years ago

I have this FT232H board: https://www.aliexpress.com/item/1005001621826339.html?spm=a2g0o.productlist.0.0.14636d09LPnZsp&algo_pvid=7da13d7c-3b88-4b89-a75f-5a1efb4495c4&algo_exp_id=7da13d7c-3b88-4b89-a75f-5a1efb4495c4-0&pdp_ext_f=%7B%22sku_id%22%3A%2212000016846517254%22%7D&pdp_pi=-1%3B13.18%3B-1%3BEUR+2.17%40salePrice%3BEUR%3Bsearch-mainSearch

I am trying to link the FT232H to a STM32 board in an I2C way.

I understood I have to use AD0 as SCLK, AD1 & AD2 as SDA. I have 4.7K resistors on SDA and SCLK from the +3.3v of the STM32 grounds of course are joined together

I wrote a simple program for the STM32 to work as I2C slave and to send data as command is received from FT232H. I simply put a breakpoint just before the data sending.

Running the following commands i2cscan.py ftdi://ftdi:232h/1 perfectly works and return a 'W' at the adr location I defined in my STM32 code (I choose 0x21 as a lot of examples use it).

but running the following code results error:

from pyftdi import FtdiLogger from pyftdi.ftdi import Ftdi from pyftdi.i2c import I2cController, I2cNackError from pyftdi.misc import add_custom_devices

i2c = I2cController()

i2c.set_retry_count(1)

i2c.configure('ftdi://ftdi:232h/1')

slave = i2c.get_port(0x21)

slave.write([]) #same result with a value in brackets slave.terminate()

The breakpoint in my STM32 code is never reached. On the python side the error is the follonwing:

File "/home/christian/code/python/testmpu/test3.py", line 18, in slave.write([]) #same with a value in brackets File "/home/christian/.local/lib/python3.8/site-packages/pyftdi/i2c.py", line 114, in write return self._controller.write( File "/home/christian/.local/lib/python3.8/site-packages/pyftdi/i2c.py", line 734, in write self._do_prolog(i2caddress) File "/home/christian/.local/lib/python3.8/site-packages/pyftdi/i2c.py", line 1032, in _do_prolog self._send_check_ack(cmd) File "/home/christian/.local/lib/python3.8/site-packages/pyftdi/i2c.py", line 1064, in _send_check_ack raise I2cNackError('NACK from slave') pyftdi.i2c.I2cNackError: NACK from slave

But I think (maybe I am wrong) that I have the same steps in my code than the I2Cdetect code.

EDIT:

I don't know what does it means: I don't know what I tried, but the codes are the same, and now my program is working as the breakpoint on the STM32 side is reached but the I2cdetect command can not detect my board...

What is wrong?

Many thanks for help

EDIT:

Problem found ! Bad resistor value. Works fine indeed.