I2C Access to micro:bit internal devices

Issue #70 resolved
Turgut Guneysu created an issue

Hi John,

I am trying to access the micro:bit internal magnetometer at I2C address 0xE (14) using the comm pin blocks I2C read.

According to documentation, Reg address 0x7 of this device contains a constant value for device id of 0xC4 (196).

When I run my program, I am getting nothing but -2 for any of the reads:

Q1: Please advise what is wrong, or what am I doing wrong?

Q2: Are the I2C blocks implemented with protocol support in the background, or do we have to toggle SCL etc ourselves?

Reference:

Thanks, Turgut

Comments (6)

  1. John Maloney repo owner

    You’re not doing anything wrong, you just have a different magnetometer chip on your micro:bit due to a hardware change.

    Your test works as expected on an older micro:bit:

    However, they made a hardware change to the micro:bit about a year ago. They replaced the separate accelerometer and magnetometer chips with a single chip that does both. I happened to grab one of the older boards.

    With a newer board, I get -2 (which means there’s no I2C device with address 14 connected).

    How can you find out what i2c devices are available? This script will test addresses 1-127:

    On the new board, it reports that there are i2c devices with addresses 25 and 30. Those are both implemented by the LSM303AGR chip from STMicroelectronics. You’ll need to consult the datasheet for that part to find out the registers for the magnetometer (which is address 30, I believe).

    You can tell the difference between the older and new boards by looking at the back. The old boards have two tiny IC’s on to bottom right (marked “Compass” and “Accelerometer”. The new boards have only one chip in that area. (There are two larger chips near the top of the board – those are the processor and USB-serial chip.)

    Good luck!

  2. Log in to comment