Problem getting MAG data from Adafruit LSM303
-
I have an Adafruit LSM303 board connected to a PyCOM LoPY (ESP32 cpu) and I can communicate to the LSM303HDLC chip over I2C.
I am getting what appears to be reasonable data from the accelerometer.
I can read, write, modify and verify i2c changes to the 3 config magnetometer registers. For some reason (maybe I missed something in the LSM303 data sheet) the mag data registers, temperature registers and the status register always read 0x00.
My config registers currently contain:
CRA_REG_M = 0x98
CRB_REG_M = 0x20
MR_REG_M = 0x00Any ideas?
-
@rcolistete Maybe I misunderstood your question. The code I was referring to above is my own library that calls the 'built-in' machine.I2C micropython driver supplied in the LoPy firmware binary rev. 1.18.1.r1.
Example:def __init__(self): self.i2c = I2C(0, mode=I2C.MASTER, pins=(sda, scl), baudrate=100000); magEnable = [0x10, 0x20, 0x00] self.i2c.writeto_mem(MAG_DEV_ADDR, MAG_CONFIG_REG_A, bytearray(magEnable));
-
The code is my own, albeit copied in content and structure from what I believe is a working adafruit project. My modifications include such changes as...
adafruit project code:
self._mag.write8(LSM303_REGISTER_MAG_MR_REG_M, 0x00)
mag_raw = self._mag.readList(LSM303_REGISTER_MAG_OUT_X_H_M, 6)
vs.
my code:
self.i2c.writeto_mem(LSM303_ADDRESS_MAG,LSM303_REGISTER_MAG_CRA_REG_M, 0x98)
self.i2c.writeto_mem(LSM303_ADDRESS_MAG,LSM303_REGISTER_MAG_CRB_REG_M, 0x20)
self.i2c.writeto_mem(LSM303_ADDRESS_MAG,LSM303_REGISTER_MAG_MR_REG_M, 0x00)MAG=self.i2c.readfrom_mem(LSM303_ADDRESS_MAG,LSM303_REGISTER_MAG_OUT_X_H_M | 0x80, 6)
Please keep in mind the accelerometer part of the chip seems to be working fine.
-
Are you using your own code or a LSM303HDLC MicroPython driver ?