Hallo
I use
pyboard V1.1
MicroPython v1.9.4-140-g8fb95d65 on 2018-06-12; PYBv1.1 with STM32F405RG
ADS1100 16 Bit ADC with Adress 73
>>> import pyb
>>> import machine
>>> from machine import I2C
>>> i2c = machine.I2C(-1, machine.Pin('X9'), machine.Pin('X10'))
...
>>> result = i2c.readfrom(73, 3)
>>> print(result)
b'?\xd6\x18'
>>> result = i2c.readfrom_mem(73,0, 3)
>>> print(result)
b'?\xd6\x80'
>>> result = i2c.readfrom(73, 3)
>>> print(result)
b'\x03\xfd\x80'
>>>
why are the answers different?
Pyboard I2C different answers
Re: Pyboard I2C different answers
See the datasheet on the content of the read:
In this example the device is set to single mode/16 bit. This means, that the next conversion has to be started manually.
The only thing that puzzles me is, that according to the data sheet the device is in continous mode by default, and your sample log does not show any writes to the device, setting it to single mode.
The first two bytes contain the data, the last byte is the config/status register, with bit 7 being the busy bit. At the first read the busy bit is 0, meaning that the data is valid, the next two reads have the busy bit = 1, meaning that the data is not valid.You can read the output register and the contents of the
configuration register from the ADS1100. To do this, address
the ADS1100 for reading, and read three bytes from the
device. The first two bytes are the output register’s contents;
the third byte is the configuration register’s contents.
In this example the device is set to single mode/16 bit. This means, that the next conversion has to be started manually.
The only thing that puzzles me is, that according to the data sheet the device is in continous mode by default, and your sample log does not show any writes to the device, setting it to single mode.
Re: Pyboard I2C different answers
Thank you very mach for help
This works
import time
import array
import machine
from machine import I2C
# INIT I2C
i2c = machine.I2C(-1, machine.Pin('X9'), machine.Pin('X10'))
def adc_write(addr, buf):
i2c.writeto(addr, buf) # write: Address, Data
return
def adc_read(addr): # must be 72 to 79
result = i2c.readfrom(addr, 3) # read 3 Byte from Address, 2 Bytes Data
print(result)
while True:
# ADC's write
adc_write(73, b'\x8c')
# ADC's read
result = i2c.readfrom(73, 3) # read 3 Byte from Address, 2 Bytes Data + Reg
print(result)
# sleep
time.sleep(1)
I have taste with I2C Analyser
Thank you
This works
import time
import array
import machine
from machine import I2C
# INIT I2C
i2c = machine.I2C(-1, machine.Pin('X9'), machine.Pin('X10'))
def adc_write(addr, buf):
i2c.writeto(addr, buf) # write: Address, Data
return
def adc_read(addr): # must be 72 to 79
result = i2c.readfrom(addr, 3) # read 3 Byte from Address, 2 Bytes Data
print(result)
while True:
# ADC's write
adc_write(73, b'\x8c')
# ADC's read
result = i2c.readfrom(73, 3) # read 3 Byte from Address, 2 Bytes Data + Reg
print(result)
# sleep
time.sleep(1)
I have taste with I2C Analyser
Thank you