1

Did someone ever used the Infineon Optiga Trust X module with Arduino using any I2C library ?

Here is the technical documentation of the Trust X module.

I'm trying to get the I2C_STATE register data but I don't receive anything after the Wire.requestFrom().

I also tried with the DSS Circuits I2C Master Library, same results.

Thanks

Full code :

#include <Wire.h>
#define PIN_RST 8
#define PIN_VDD 9

void setup() {
  pinMode(PIN_RST, OUTPUT);
  pinMode(PIN_VDD, OUTPUT);
  digitalWrite(PIN_RST,LOW);
  digitalWrite(PIN_VDD,LOW);

  Serial.begin(115200);
  delay(2000);
  Wire.begin(); // join i2c bus (address optional for master)

  digitalWrite(PIN_VDD,HIGH);  // sartup the Trust X module
  digitalWrite(PIN_RST,HIGH);

  delay(15);  // startup min delay
}

long val = 9999;

void loop() {
  Wire.beginTransmission(48); // transmit to device #48 (0x30)
  Wire.write(byte(0x82));            // sends instruction byte
  Wire.endTransmission();     // stop transmitting

  Wire.requestFrom(48, 4);
  while(Wire.available()==0){}

  val = Wire.read(); // Reads the data from the register
  Serial.print("val = ");
  Serial.println(val);

  delay(5000);

}
9
  • Testing a new sensor always starts with the i2c scanner playground.arduino.cc/Main/I2cScanner Use the address that the i2c scanner finds. Avoid that the sketch stops in the while statement. Test if 4 bytes are received, but don't use the while.
    – Jot
    Apr 13 '18 at 8:16
  • Hi and thank you for your answer. I have already tried the scanner and it did not found any device. The problem is I think at the startup of the Trust X module as specified in the documentation. But i can't see what I'm doing wrong.
    – zoptune
    Apr 13 '18 at 9:50
  • 1
    If the i2c scanner does not find it, then no other code will work. What was the result of the i2c scanner? it was not 48. Adapt the i2c scanner to set the pin levels in the setup(). You could make the time after the reset 1 second instead of 15ms and also add a long delay between setting the pins vdd and reset high. You could show a photo of the wiring. I trust Infineon that they use the standard i2c. The first thing to do is to make the i2c scanner work. After that you can start to write good code, for example removing the while and reading 4 bytes.
    – Jot
    Apr 13 '18 at 10:18
  • What value are the pull up resistors you are using on the two I2C lines? Apr 13 '18 at 11:14
  • @Jot The i2c scanner answered with "No device". I know I will receive 4 bytes by reading the 0x82 register but as it didn't worked I just wanted to receive at least 1 byte this is why I used the while loop. I'll try to add longer delays and if it still not work, I will share a photo of the wiring. Thank you for your answer.
    – zoptune
    Apr 16 '18 at 3:10
1

So I finally succeeded to read a register value. I don't really know where was the problem. Here is the code if it can help someone (the scanner still does not work btw) :

#include <Wire.h>

#define DEVICE_ADDRESS 0x30

#define PIN_RST 8
#define PIN_VDD 9

void printOutput(byte *out, int out_len){
   int y=0;
  Serial.print("out = ");
  for(;y<out_len;y++){
    Serial.print(out[y],HEX);
  }
  Serial.println("");
}

void coldReset(){
  pinMode(PIN_RST, OUTPUT);
  pinMode(PIN_VDD, OUTPUT);
  digitalWrite(PIN_VDD,LOW);
  digitalWrite(PIN_RST,LOW);
  delayMicroseconds(2000);
  digitalWrite(PIN_VDD,HIGH);  // sartup the Trust X module
  digitalWrite(PIN_RST,HIGH);
}

int I2C_get(byte reg, byte *out, int out_len){
  int i=0, nbSend=0, nbAvailable=0, ret=0;
  Wire.beginTransmission(DEVICE_ADDRESS); // transmit to device #48 (0x30)
  nbSend=Wire.write(reg);            // sends instruction byte
  Wire.endTransmission();     // stop transmitting
//  Serial.print("nb send = ");
//  Serial.println(nbSend);

  delayMicroseconds(50);
  Wire.requestFrom(DEVICE_ADDRESS, out_len);

//  nbAvailable=Wire.available();
//  Serial.print("nb available = ");
//  Serial.println(nbAvailable);

  if(Wire.available()==out_len){
    for(;i<out_len;i++){
      out[i]=Wire.read();
    }
  }
  else ret=-1;

  return ret;
}

void setup() {

  Serial.begin(115200);
//  Wire.begin(); // join i2c bus (address optional for master)
//  coldReset();
//  delayMicroseconds(15000); // Startup time
}


void loop() {
  int y=0, out_len, ret;
  byte res1[]={0x00,0x00,0x00,0x00};

  Wire.begin(); // join i2c bus (address optional for master)
  Wire.setClock(400000);
  coldReset();
  delayMicroseconds(15000); // Startup time

  out_len=4;
  ret=I2C_get(byte(0x84),res1,out_len);
  if(ret!=-1){
    printOutput(res1,out_len);
  }
  else{
    Serial.println("Error I2C_get");
  }

  Wire.end();
  Serial.println("");
  delay(5000);
}
1

It looks like the answer is a bit delayed, but if somebody else sees this issue once again.

It might not be directly visible in the documentation (Datasheet or Solution Reference Manual), but here what you can find in the Trust M Datasheet Annex B (Section 11): "The OPTIGA™ Trust M will not acknowledge the slave address sent by a host if it is either busy or in idle state. Hence the host must retry or repeat the transaction until it is successful or timed out for 100 milliseconds (extreme case). The specified guard time must be applied between each attempt of write / read operation by the Host I2C driver."

The chip always goes into an idle or sleep state if no command is issued in a defined time period, unless a Sleep Activation Delay isn't changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.