Clock stretching on Wire library (as a slave)?

Hi there!

I'm using the Wire library for all my I2C slave needs, and it's doing a great work! :)

Now I need some functionality that I'm not sure Wire provides out-of-the box, so any tips on how I could implement it would be very welcome.

I have created an I2C slave device that talks to the Nintendo Wiimote (the I2C master). This is the project I'm talking about:

The thing is, there's a part in the code where I need to completely disable interrupts because I'm executing a very time sensitive routine. It doesn't take too much time (I think around 350us), but it gets repeated several times a second (it's inside a loop). This is on file line #301. However, this brief interrupts disabling, several times a second, is being enough to get random garbage data sent to the I2C master.

My idea around this is to put Wire into "clock stretch" mode (as a slave, not a master) before calling GCPad_read. So my questions are:

1 - Is this a feasible thing? Any tips on modifying Wire library to allow that?

2 - Does clock strecth work with interrupts disabled?

Any help would be very welcome!



A dumb and simple solution would be to split the two time-critical functions into two separate devices and have them communicate as necessary to coordinate their activities. Each of them would do the time-critical parts in real time and the application processing and comms as a background activity.

Thanks! But using two uC would be my last resort only if that couldn't be done via software.

I'm testing this potential solution for my problem:

Let's see how it goes...