4

I saw this video from James Bruton. See the links to the GitHub repos in the video description.

I bought a few AS5048B boards from AMS, so I can measure the position of my stepper motors.

In the sosandroid repo, I ran program_address and was able to get one of them working, but they all have the same I2C address, and because I want to have 6 of them running simultaneously, it of course won't work. I know I could get an I2C multiplexer...

I also tried setting the A1 and A2 pins on the AS5048B to high and low, which change the I2C address (for a total of 4)... But I want to change the I2C address permanently for each board.

It looks to me like program_address is supposed to permanently program the I2C address, which the user can specify in the .ino file:

// Construct our AS5048B object with an I2C address of 0x40
AMS_AS5048B mysensor(0x40);

But no matter what I set it to (e.g. 0x40, 0x41, 0x42, 0x43, 0x44), the Arduino I2C scanner always finds 0x44, which is the default address, so the program_address must not be working.

EDIT: the default address is actually 0x40. I must have programmed it to 0x44 without knowing (I was playing around with this board trying to figure this all out).

I know that normally the I2C addresses cannot be changed, but it looks like this one can:

Here's a snippet from the link above. It says the OTP bits can be programmed/burned (only once!). My understanding is that the I2C address is saved in the OTP bits.

Program the OTP bits permanently:

  1. Write dec.253 into the OTP control register (dec.3) to enable the special programming mode
  2. Set the Burn bit (dec.8) in the OTP control register (dec.3) to enable automatic programming procedure
  3. Write dec.0 into the OTP control register (dec.3) to disable the special programming mode

I am using the Teensy 4.1 using PlatformIO in VS Code, and I also tried using an Arduino Uno in the Arduino IDE.

My wiring is as follows:

wiring

So how do I program the I2C address on the AS5048B boards?

EDIT:

  • I changed an image to text, and cleaned things up.

As @6v6gt requested, I used the I2C scanner and it is still showing 0x40 (on this particular board), so it must not have been programmed (unless it's possible to program it to 0x40 even though 0x40 is its default value). The only thing I changed from the program_address repo is this line in the .ino file:

// Construct our AS5048B object with an I2C address of 0x40
AMS_AS5048B mysensor(0x48);

I changed the 0x40 to 0x48. But now I am getting this in the serial monitor:

Angle degree : I2C error: 2
359.9780273437

Since I must have programmed the other board to 0x44 successfully, I am trying to think of what I did differently, but I don't remember.

There are hundreds of lines of code in program_address (and the .h and .cpp file), so I probably shouldn't post all of it here. But here's the GitHub repo.

dda
  • 1,595
  • 1
  • 12
  • 17
John Doe
  • 151
  • 5

2 Answers2

4

The device slave I2C address consists of the hardware setting on pins A1, A2 and upper MSBs programmable by the user. It is the setting of the MSBs, in addition to A1/A2 that I believe the OP is after.

The information provided by @Nick Gammon concerning A1 and A2 is correct, but does not consider the other 5 bits (the MSBs). It appears that you can, indeed, permanently set a new I2C slave address on the device.

You need to read the programming application note very carefully, but they explain how to burn those bits into the register....it seems straightforward and is really just four steps, but I suppose it can be a little daunting, e.g., "slave address consist of 5 programable bits (MSBs) and the hardware setting of Pins A1 and A2 I²C address <4> is by default not programmed and due to the inversion defined as '1'"

The application note gives an example of the 4 steps.... enter image description here

It may be the case that you already changed the I2C address default to 0x44 by following the instructions. [edited to add] Can you post the complete program [Arduino IDE code] that you used to try to change the I2C address?

DrG
  • 409
  • 3
  • 7
2

but they all have the same I2C address

No, they have 4 possible addresses, based on how you configure A1 and A2. So you can have 4 different addresses immediately.

But I want to change the I2C address permanently for each board.

For each board, set up A1 and A2 differently.

This only gives you 4 different addresses, not 6. You could conceivably connect 8 devices to two different Atmega328 chips, and have them do the readings and forward the results using a protocol you devise, to your "main" board. The Atmega328 chips only cost around $US 5 each so this isn't a big deal.

Another approach would be to run SDA and SCL through a multiplexer chip, so that you enable one batch of 4 chips and then the other batch. Without trying it out, it is hard to say if this would work satisfactorily.

Nick Gammon
  • 38,901
  • 13
  • 69
  • 125