TWI START/STOP/RESTART errored ?

Hi,

I've tested a sketch with Arduino UNO and Arduino DUE. The sketch fails with Arduino DUE. I've used an oscilloscope to study the i2c sequence and i've found an immediate difference on the START sequence.

The attached file NewFile1.bmp shows the good signal of Arduino UNO.
The attached file NewFile3.bmp shows the bad signal of Arduino DUE.

Here is the sketch (read the temperature with the Melexis MLX90614) :

/* Librairie Wire pour les communications I2C */
#include <Wire.h>
 
/* Adresse par défaut du capteur IR */
#define I2C_ADDR 0x5A
 
/** Fonction setup() */
void setup() {
   
  /* Initialisation du port série (pour debug) */
  Serial.begin(9600);
  Serial.println(F("BOOT"));
 
  /* Initialisation du bus I2C */
  Wire.begin();
//  Serial.println(WIRE_INTERFACE->TWI_CWGR, HEX); // DUE i2c speed
}

/** Fonction loop() */
void loop() {
 
  /* Données brute de température */
  uint16_t data;
 
  /* Commande de lecture de la RAM à l'adresse 0x07 */
  Wire.beginTransmission(I2C_ADDR);
  Wire.write(0x07);
  Wire.endTransmission(false);
//  Wire.endTransmission(true);
 
  /* Lecture des données : 1 mot sur 16 bits + octet de contrôle (PEC) */
//  Wire.requestFrom(I2C_ADDR, 3, false);
  Wire.requestFrom(I2C_ADDR, 3, true);
  while(Wire.available() < 3);
  data = Wire.read();
  data |= (Wire.read() & 0x7F) << 8;  // Le MSB est ignoré (bit de contrôle d'erreur)
  Wire.read(); // PEC
//  Wire.endTransmission();
 
  /* Calcul de la température */
  const float tempFactor = 0.02; // 0.02°C par LSB -> résolution du MLX90614
  float tempData = (tempFactor * data) - 0.01;
  float celsius = tempData - 273.15; // Conversion des degrés Kelvin en degrés Celsius
 
  /* Affichage de la température */
  Serial.print(F("Celsius: "));
  Serial.println(celsius);
 
  /* Temps d'attente */
  delay(200);
}

NewFile1.bmp (146 KB)

NewFile3.bmp (146 KB)

I just found your post and experience the same issue with the Due. How did you get around fixing this so it can work?

Hey guys,

i am currently investigating i2c problems too. When did your bus hang up? Only at beginn or later too?

One thing that made it better, just in my case, was a delay before Wire.begin();. Maybe you can give it a try.

If it hang up you can try this, right before Wire.begin();

  pinMode(21, OUTPUT);
  for (int i = 0; i < 8; i++) {
    digitalWrite(21, HIGH);
    delayMicroseconds(3);
    digitalWrite(21, LOW);
    delayMicroseconds(3);
  }
  pinMode(21, INPUT);
  Wire.begin();

It was part of a solution which was mentioned here in the forum.

Tobs