0

I have the following problem: I want to read out a motion sensor from Invensense (ICM-20602) through the spi interface with the FTDI USB Spi converter connected to a Debian linux system with a python3 program. I set up all the necessary libraries and drivers and I can set the CS line and also verified my MOSI, Clock and CS line outputs by an oscilloscope. There is also MISO input from the device but not what I would expect. I am sending the register address to the whois-register to get the device ID to verify that the read/write is working. I dont understand why the device is not responding properly. This is my code at the moment:

#pyspi - pyftdi

from pyftdi.spi import SpiController, SpiIOError
from struct import *



ctrl= SpiController()#spi
ctrl.configure('ftdi://ftdi:232h/1')  # Assuming there is only one FT232H.
spi = ctrl.get_port(cs=0, freq=1E6, mode=0)# Assuming D3 is used for chip select.


write_buf = b'\x75\0xdf'


spi.write(write_buf,True,False)

read_1= spi.read(2, start=False, stop=True).tobytes()

id = spi.exchange([0x75,0xff,],2).tobytes()
#ctrl.get_port(cs=1, freq=1E6, mode=1)
print(read_1)
print(id)

There is no code error - only the read buffer is 0x00 or sometimes 0x10 but not what I would expect: the device ID: 0xAF

Has someone an idea how to get the device to answer properly?

By the way: the device is working properly with the invensense evaluation board - so the device should work properly.

andikarl
  • 23
  • 1
  • 5
  • There is an entry that my device is only supporting spi mode 0 and 2 but still mode 0 is not working in my case: – andikarl Jun 25 '19 at 13:48
  • https://electronics.stackexchange.com/questions/360086/make-ftdi-2232d-do-spi-mode-1-properly-data-seems-1-2-clock-cycle-off It is very odd that with mode 1 I get the following output: 01\xf7\xfc\xf0 – andikarl Jun 25 '19 at 13:48
  • can you maybe add a capture of your scope readings? This would help to identify possible reason more easily. P.S. if I see it correctly the ICM-20602 SPI works in mode 3. Maybe using the I2C interface instead is an option for you? – Christian B. Jun 25 '19 at 17:45
  • Well actually mode 0 should work as well but one has to make sure to disable the I2C interface first according to the datasheet. – Christian B. Jun 25 '19 at 17:57

1 Answers1

0

Finally I tested the FTDI USB device with an Infineon pressure sensor with the device ID 0x10. I managed to read out the ID and then I also found out that the ICM-20602 has a different device-ID ( 0x12) as specified (0xAF) in the datasheet. I also managed to read out the gyro-data so I am very confident that the device ID is different than specified. To read out the ID for of both sensors I also adjusted my program to only send one byte during one exchange cycle. Mode 0 works for the ICM device withouth problems - 1,2 is not working - it is also not necessary to put the device in spi-mode only to be able to use mode 0. this is the adjusted programm:

from pyftdi.spi import SpiController, SpiIOError
from struct import *



ctrl= SpiController()#spi
ctrl.configure('ftdi://ftdi:232h/1')  # Assuming there is only one FT232H.
spi = ctrl.get_port(cs=0, freq=1E6, mode=0)# Assuming D3 is used for chip 
select.    
write_buf = b'\x75\'


spi.write(write_buf,True,False)

read_1= spi.read(2, start=False, stop=True).tobytes()

id = spi.exchange([0x75],2).tobytes()
print(read_1)
print(id)
andikarl
  • 23
  • 1
  • 5