PWM stops working when I insert I2C code on Teensy 3

Status
Not open for further replies.

astroyam

Well-known member
I have working I2C code for the VCNL4010 light sensor and working code for PWM (that I test with an RC filter and look at the voltage output).
While both of these codes worked fine independently, when I insert the I2C code into the PWM code, the PWM no longer outputs.
In the attached code, if I comment lines 26-41 which are some I2C calls, then the PWM outputs, whereas if I leave them in, the PWM stops.

Any ideas?
 

Attachments

  • I2CvsPWM.ino
    2.3 KB · Views: 180
OK, never mind. The problem was that the VCNL 4010 was disconnected, so the code calls must have been hanging. Not sure how to remove the post...
 
Glad you got it resolved.

This is one of the unfortunate things about I2C... the slave device can hold the line low to make the master wait. But if the line is "stuck" low, the master waits forever.

I'm a bit reluctant to change the Wire library without the official Arduino adopting the changes, but maybe the Teensy version should have a way to specify a timeout, and functions like Wire.endTransmission() could return with an error code if the slave device holds the line low for too long?
 
I2c

OK, this issue has resurrected in the following way: The attached code fails when line 57 is not commented. We are connecting to the Teensy using rawhid_test.exe. So by fail, I mean that the rawhid_test.exe fails if the line is present, and works (it returns the received data) if not, but ... only on some computers.

Specifically, I have a laptop where rawhid_test does not fail, and a desktop where it does fail. On the desktop case, I did check that it works if I comment the line out.

So there seems to be a subtle variation, which made us look at timing. We varied the timeout on the PC side C code from 220 msec to 2000 msec which did not fix the issue.View attachment I2C_FailOn_readByte.ino

Thanks for any feedback!


Glad you got it resolved.

This is one of the unfortunate things about I2C... the slave device can hold the line low to make the master wait. But if the line is "stuck" low, the master waits forever.

I'm a bit reluctant to change the Wire library without the official Arduino adopting the changes, but maybe the Teensy version should have a way to specify a timeout, and functions like Wire.endTransmission() could return with an error code if the slave device holds the line low for too long?
 
Actually, yes, that would be very useful. Even just one code for all error states would still be a major improvement. It's a bit frustrating as is because the error source can be several things.


Glad you got it resolved.

This is one of the unfortunate things about I2C... the slave device can hold the line low to make the master wait. But if the line is "stuck" low, the master waits forever.

I'm a bit reluctant to change the Wire library without the official Arduino adopting the changes, but maybe the Teensy version should have a way to specify a timeout, and functions like Wire.endTransmission() could return with an error code if the slave device holds the line low for too long?
 
Status
Not open for further replies.
Back
Top