I2C, robots and continuous tasks

Hello there fellow geeks,

I am working on a robot project at this moment, and I have a quick question:

I use I2C to send commands from my master to my 2 slaves who run the actual actuators, since I2C is interrupt based, is it possible to keep a signal on a pin (say a PWM on pin 10) while the master updates the commands to the slave?

The idea is the master sends a bit string to the slave, where 1 means task 1 go, and a 0 would mean no go. I am afraid however that when my robot is following its line in a jolly way, the master asks for a status update and the motors stop because of the interrupt, is this true? and is there a way to avoid this, while not leaving the slave in the interrupt function (since the bus is kept active for that time, and the motors should not stop :P)

If I'm making a huge misunderstanding, or someone knows the answer to my problem please let me know!

I use I2C to send commands from my master to my 2 slaves who run the actual actuators, since I2C is interrupt based, is it possible to keep a signal on a pin (say a PWM on pin 10) while the master updates the commands to the slave?

PWM is done by hardware so you don't need the interrupt feature of I2C for this but yes, it's possible.

and is there a way to avoid this, while not leaving the slave in the interrupt function

Interrupt handlers should be kept as short as possible and you may be limited in the options you have inside the handler (no serial communication for example). So the time you (or better your Arduino) spend in the interrupt handler should be very short (a few microseconds to perhaps about 0.1ms). I doubt your motor will react in this time even if the relevant pin would be controlled by software and not hardware.

Thank you for the quick reply!

The idea is that the 2 slaves run continuous tasks, while updating "status" bits to indicate what they are doing. Then the master asks for these bits, (by the onRequestEvent handler), runs trough its decision tree, and sends out updated commands to the slaves.
Interpenetrating your reply, i assume reading 3 bits at max into the slave memory should not take enough time for the engines ect. to stop working, even for a brief amount of time. However does the same goes for sending the bits back to the master? I would assume so but i'm rather safe then sorry.

However does the same goes for sending the bits back to the master?

You don't have to count in bits, you can send or receive several bytes without getting any problems. If you control the motors with PWM (I would expect that) one PWM cycle (on and off time) is about 1ms. Within this time the processor executes up to 16'000 commands. And don't forget: PWM is usually done in hardware so once you set the PWM value the hardware will keep sending the PWM signal no matter what the processor is doing else.

Thanks a lot!

At this moment we are putting the pieces together, once we finally have it working according to plan I will make sure to post the full code with some pictures :slight_smile: