pbugalski / wemos_motor_shield

Alternative firmware for Wemos Motor Shield
36 stars 19 forks source link

I2C address 0x30 is unchangeable #3

Closed cax closed 6 years ago

cax commented 6 years ago

By hardware design, the motor shield allows selecting one of four i2c addresses (0x2d, 0x2e, 0x2f , 0x30) by soldering connection between relevant pads (AD0, AD1) on the shield.

At the moment, the alternative firmware has 0x30 as a hard-coded address, which does not allow using of more then one shield in the project.

There are 2 possible solutions I can think of:

1) re-implement the pad-soldering address selection feature

2) compile and publish 4 different firmware binaries, each for different hard-coded i2c address from the 0x2d-0x30 range. Shield users will choose the address and flash the relevant firmware bin file.

It should be easy for you, as you already have the compilation toolchain installed. Thank you in advance!

cax commented 6 years ago

Here are the lines from the original firmware source code that may be helpful:

define AD0_Pin GPIO_PIN_0

define AD0_GPIO_Port GPIOF

define AD1_Pin GPIO_PIN_1

define AD1_GPIO_Port GPIOF

uint8_t i2c_base_add=0x2d; uint8_t ad0_val,ad1_val;

MX_GPIO_Init();

ad0_val=HAL_GPIO_ReadPin(AD0_GPIO_Port,AD0_Pin); ad1_val=HAL_GPIO_ReadPin(AD1_GPIO_Port,AD1_Pin);

i2c_base_add+=((ad1_val)<<1)|ad0_val;

hi2c1.Init.OwnAddress1 = i2c_base_add<<1;

cax commented 6 years ago

I had no patience, so I installed the toolchain, patched the value of 0x60 (2 * 0x30) in main.c to suit addresses 0x2d, 0x2e, 0x2f , 0x30, compiled firmware for each address, flashed and tested with motor shield.

Now it's possible to use more than one motor shield at once.

Attached is the zip with firmware files for 4 different addresses.

motor_shield_XX_bin.zip

ashishgururani commented 6 years ago

I was looking for this so bad and had no idea how to "install the toolchain". Thank you so much for this.. testing it now!

NathanJPhillips commented 6 years ago

I have a branch to fix the firmware to use the solder pads on the back here: https://github.com/NathanJPhillips/wemos_motor_shield/commits/feature/address-select I will test it when I get time, which should be by the weekend. It builds on https://github.com/pbugalski/wemos_motor_shield/pull/6 so if we can get that one reviewed first then it will speed up incorporation of the next PR once I've done the testing.

sprat commented 6 years ago

I'm interested by the firmware fix, but I see that the merge request upon which it builds has been closed. What is the status of this branch? Has it been tested?

danielfmo commented 6 years ago

Please check this PR to address this issue https://github.com/pbugalski/wemos_motor_shield/pull/8

pbugalski commented 6 years ago

Solved, thank you danielfmo for your help.