Go Down

Topic: Clock stretching on Wire library (as a slave)? (Read 798 times) previous topic - next topic

bootsector

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: https://gitorious.org/wii-retropad-adapter

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 https://gitorious.org/wii-retropad-adapter/wii-retropad-adapter/blobs/master/src/wii-retropad-adapter/wra.cpp 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!

Thanks!

bootsector

PeterH

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.
I only provide help via the forum - please do not contact me for private consultancy.

bootsector

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


Go Up