energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
794 stars 672 forks source link

I2C reads bytes in random order & other issues while reading #403

Open reox opened 10 years ago

reox commented 10 years ago

I tried communicating with a SHT21 Sensor over I2C from the EK-TM4C1294XL. I ran in several problems with the Wire library: on the hardware side i see on the oscilloscope, that while reading it takes excatly 1ms until the next byte is read. i find this rather odd, because on my teensy it reads without any interruption. But the most curious part is that the bytes i read, are shuffeled around in some random way. on the oscilloscope i see the correct order of bytes. the code i use is very simple:

    // setup
    Wire.setModule(0);
    Wire.begin();
    Serial.begin(115200);

    // loop
    Wire.beginTransmission(0x40);  //begin
    Wire.write(0xE5);                    //send the pointer location
    Wire.endTransmission();                 //end

    Wire.requestFrom(0x40, 3); 
    while(Wire.available()) {
        Serial.print(Wire.read(), 16);
        Serial.print(" ");
    }   
    Serial.println();

The order of bytes is not even like endianess, on the bus is send 0xAA 0xBB 0xCC and i read 0xBB 0xCC 0xAA or 0xCC 0xBB 0xAA... sometimes i even "receive" bytes from the previous transmissions...

I tried with the latest lib from git, but no success.

rei-vilo commented 10 years ago

SHT21 page says Output: I²C digital, PWM, SDM/analog Volt interface

reox commented 10 years ago

hi, yes I'm using external pull ups (2k2 (also used 4k7)) which seems fine, because ramping of the signals is very low. the whole bus capacitance should be below the 400pF (it should be by about 250pF)

the SHT21 is I2C only. There are two other types SHT21S and SHT21P for SDM and PWM interface. I'm using the I2C Variant.

I also tried on module 0 and 1, both have the same behaviour.

By the way i attached an image of the actual bus (while the sensor is sending data), it looks fine to me. ds2_quickprint30 But if you take a closer look, the Tiva Board does not pull down the SCL really, you can see that while the clock is running, there is a ramp on the low side (which should not be there, because the line should be connected to ground). If the Sensors pulls down SCL, it is really on GND (and i can verify this with the oscilloscope) Someone told me that it seems like the Tiva is using software I²C and is not really an open collector port.