In the near future I'll have to control 2 MD03 motor controllers via I2C. Now, I don't get much about the i2c-commands integrated in PicAxe µC's so I'd like to ask how I should talk to them. Should I issue the i2cslave-command everytime I want to speak to one, or should I issue it twice (euch with another address) in the beginning of the program, or is there another way that I don't now about?
When you declare a i2c slave, all the i2c read/write commands that come after it will talk to that slave. If you need to talk to 2 slaves, you will need to be sure that the i2c slave comes before each one.
i2cslave number_one
writei2c make_your_motors-go
do other stuff
do other stuff
it2slave number_two
writei2c make_your_other_motors_go
There is also a hi2c command which includes a (new slave) part that allows you to switch between slaves “on the fly” which can be handy. I think the main issue is that both the motor controllers will come with the same address --You will need to change one to a new address (so you don’t try to talk to both of them at the same time) and this can be a real pain. Again, I am happy to give you a hand, just shoot me a skype message.
Great, I’ll look into that hi2c-command right away
About the addresses: the MD03 has a handy little 4-switch configuration module onboard which let’s you set different modes (I2C, RC, analog voltage divider, on/off) and up to 8 I2C addresses, so 8 modules can be connected to one controller.
I am not going to lie to you… changing an I2c address with software can be easy as pie or the most royal pain in the ass ever! It is a good thing you won’t have to do it.
Back to the point, declare what slave you are talking to before you talk to it and you will be all set.