i2c truncated bytearray reads

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
rmartineau
Posts: 1
Joined: Tue May 19, 2020 5:43 am

i2c truncated bytearray reads

Post by rmartineau » Tue May 19, 2020 6:08 am

Hi,

I am attempting to communicate with a Sensirion flowmeter (SLF3S-1300F SL). I have tried using hardware i2c and software i2c, no matter how I do it I get truncated reads. I'm supposed to be able to read 9 bytes after sending a start command. The reads fail entirely if I don't send the start commands (and I get the correct number of acks corresponding with the number of sent bytes when I do.) Likewise I can do i2c.scan and get an address back, so it seems I'm connecting just fine but when I ask for 9 bytes back I get the first 5 or so reliably, but the later ones are garbled and such. I have tried changing pullup resistor values over a very wide range but that doesn't seem to help, nor does changing the bus frequency. I've also tried on a Feather STM32405F board and powering the sensor off both the board and an external supply. Any ideas? My code is below:

(excuse my indents....)

class SLF3S():

def __init__(self):
self._i2c = machine.I2C(scl=machine.Pin('A4'), sda=machine.Pin('A5'))
self._i2c.init(scl=machine.Pin('A4'), sda=machine.Pin('A5'), freq=168000)
pyb.delay(250)
self._i2c.writeto(SLF3S.RESETADDRESS, SLF3S.RESET)
print('Soft reset cycled.')
pyb.delay(500)

def start (self):
self._i2c.start()
u=self._i2c.write(b'\x10\x36\x08') #address is 0x08
self._i2c.stop()
print(u)
print('Entered into continuous measurement mode.')
pyb.delay(150)

def read (self):
self.bytes_in=bytearray(9)
self._i2c.start()
self._i2c.write(b'\x11')
self._i2c.readinto(self.bytes_in)
self._i2c.stop()

FlowSensor=SLF3S()
print(FlowSensor._i2c.scan())
pyb.delay(50)
FlowSensor.start()
pyb.delay(50)
FlowSensor.read()
print(FlowSensor.bytes_in)

OUTPUT:
Soft reset cycled.
[8]
3
Entered into continuous measurement mode.
bytearray(b'\x00\x00\x81\x13)\xcc\x00!6')

Thanks anyone for any help! I'm out of things to try...

Post Reply