Hi,
The strangest thing. I'm tinkering with some i2c stuff on a PCF8574A, which is working, but only when I disconnect the USB.
I'm using a Pro Mini with a CP2102 USB programmer. I've hooked the PCF8574A i2c expander to the i2c ports, which are A4 and A5 on the pro mini with 1k8 pull up resistors. As far as I can tell there should be no conflicting ports here...
The symptom is that when the USB programmer is hooked up, it seems to 'hang' on the wire.begin() function. It will not exit the setup().
Anyone any idea's?
Thx.
Are you on a Mac? The CP2102 doesn't work correctly on a Mac, it is the reset line that is not toggled in the right way.
PC; Windows 10, to be exact. I am not experiencing any problems with this programmer. Using it for a while now for Arduino's and ATTinies..
Ok can you supply a schematic of how it is wired up and a link to the parts, along with a photograph of how you have wired it.
I've narrowed it down to "Wire.endTransmission()", and found a topic here on this forum that describes it. I'll try following the directions there to see if it is applicable to my case.
For reference, this is the topic:
https://forum.arduino.cc/index.php?topic=124286.0
I'll report back here to provide feedback on my findings...
Apparently the wire library is notorious for freezing here. There is a while loop in there somewhere that waits for an interrupt to happen (not clear to me which one or why)..
For me, using the WSWire library instead fixed it.
WSWire:
There is also an alternative i2c library, but I've not tried it. For references, it's this one:
Case closed.
Something about not selling the hide before the bear is shot....
Yes, the "freeze" has been fixed, but apparently, the underlying problem is still there.
The nice thing about the WSWire lib is that it gives back a status code.
With no USB connected, all is OK. With USB connected it's not working, and I get back "timed out while waiting for data to be sent", code 6.
My setup:
Pro Mini, top 6-pin FTDI connector to CP2102 programmer:
DTR TXD RXD VCC GND GND, but not connected
| | | | | |
Pin A4 to SDA on PCF8574A, with 1k8 pull up to 5V.
Pin A5 to SCL on PCF8574A, with 1k8 pull up to 5V.
No other pins are connected.
The PCF8674A is on one of those blue chinese breakout boards. The board too has proper pull ups on SDA and SCL.
My sketch:
#define DEVICE_ADDRESS 0x38
//include <Wire.h>
#include <WSWire.h>
void deviceWrite(byte txData)
{
int sentStatus = 0;
Serial.print("Transmitting... ");
Wire.beginTransmission(DEVICE_ADDRESS);
Wire.write(txData);
sentStatus = Wire.endTransmission();
Serial.print("DONE. Status Code ");
Serial.println(sentStatus);
/*
* Output 0 .. successU
* 1 .. length to long for buffer
* 2 .. address send, NACK received
* 3 .. data send, NACK received
* 4 .. other twi error (lost bus arbitration, bus error, ..)
* 5 .. timed out while trying to become Bus Master
* 6 .. timed out while waiting for data to be sent
*
*/
}
void setup()
{
Serial.begin(9600);
Serial.println("\nTEST PCF8574\n");
Wire.begin(); // Join I2C bus
deviceWrite(B11111111);
Serial.println("Setup finished");
}
void loop()
{
Serial.println("*");
deviceWrite(B11111001); // Turn on LEDs connected to P1 and P2
// Turn off LED connected to P0
delay(1000); // Delay 1 second
deviceWrite(B11111110); // Turn off LEDs connected to P1 and P2
// Turn on LED connected to P0
delay(1000); // Delay 1 second
}
Grumpy_Mike:
Ok can you supply a schematic of how it is wired up and a link to the parts, along with a photograph of how you have wired it.
In what way does your post address any of the things asked of you?