Pages: [1]   Go Down
Author Topic: Clock stretching on Wire library (as a slave)?  (Read 456 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there!

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

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
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11179
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm testing this potential solution for my problem:

https://gitorious.org/wii-retropad-adapter/wii-retropad-adapter/commit/2f49e0964bdc2067c8f283123a9989180fb006cb

Let's see how it goes...

bootsector
Logged

Pages: [1]   Go Up
Jump to: