This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TPS65981: Using I2C with TPS65981

Part Number: TPS65981
Other Parts Discussed in Thread: ENERGIA,

Hi,

I'm trying to to read TPS65981-EVM i2c using Energia IDE and LauchPad TM4C123G, but it's not working.

The code I'm using is below:

#include <Wire.h>
String leituraReg;
String inByte;
void setup() {
  Serial.begin(9600);     //inicia comunicação serial
  delay(100);
  Wire.setModule(0);      //SCL0 e SDA0
  Wire.begin();           // inicia comunicação i2c
  delay(100);
  indice();
}
void loop() {
  inByte = leStringSerial();
  if(inByte == "0"){
    Serial.print("\n\r(0) Lido\n\n\r");
    inByte = "";
    indice();
  }
  else if(inByte == "1"){   //Leitura do Registrador System Power State
    Serial.print("\n\r(1) Leitura i2c - Reg 0x20 = System Power State\n\n\r");
    leituraReg = lerRegistro(0x27, 0x20, 1); //CTL2=0 e CTL1=0
    delay(100);
    leituraReg = lerRegistro(0x37, 0x20, 1); //CTL2=1 e CTL1=0
    delay(100);
    leituraReg = lerRegistro(0x3F, 0x20, 1); //CTL2=1 e CTL1=1
    delay(100);
    leituraReg = lerRegistro(0x2F, 0x20, 1); //CTL2=0 e CTL1=1
    //Serial.print(leituraReg);
    inByte = "";
    indice();
  }
}
void indice (){
  Serial.print("(0) Lido\n\r");
  Serial.print("(1) Leitura i2c - Reg 0x20 = System Power State\n\r");
}
/*  
 *  int lerRegistro (int address, byte reg, int numBytes)
 *  descrição:
 *    - Escreve um dado em um determinado registro
 *  
 *  variáveis:
 *    - address: endereço de i2c do módulo
 *    - reg: registro a ser lido
 *    - numBytes: número de bytes a serem lidos
 *  
 *  retorno:
 *    - reading: leitura do registrador lido
 *    
 *  aplicação: lerRegistro(45, 0x01, 1);
 */
String lerRegistro (int address, byte reg, int numBytes){
  Wire.beginTransmission(address);      // transmit to device #45(0x2D)
  Wire.write(reg);                      // send reg addr to read
  Wire.endTransmission();               // stop transmitting
  Wire.requestFrom(address, numBytes);  // receive from device #45(0x2D) numBytes bytes
  String reading = (String) Wire.read();// save receive
  delay(100);
  return reading;
}
/*  
 *  String leStringSerial()
 *  descrição:
 *    - Lê uma string recebida via terminal.
 *  
 *  variáveis:
 *    - nenhuma.
 *  
 *  retorno:
 *    - conteudo: String recebida via terminal.
 */
String leStringSerial(){
  String conteudo = "";
  char caractere;
  while(Serial.available() > 0) {   // Enquanto receber algo pela serial
    caractere = Serial.read();      // Lê byte da serial
    if (caractere != '\n')          // Ignora caractere de quebra de linha
      conteudo.concat(caractere);   // Concatena valores
    delay(1000);                    // Aguarda buffer serial ler os caracteres
  }
  return conteudo;                  // Retorna o que foi lido
}

The configuration is that one:

I'm using a Logic Analyzer to see what is happening and here are the images for the four reads:

CTL2=0 and CTL1=0:

CTL2=1 and CTL1=0:

CTL2=1 and CTL1=1:

CTL2=0 and CTL1=1

Summary:

I'm only receiving NAKs.

Am I doing something wrong? How can I control this module by i2c bus?

#include <Wire.h>
String leituraReg;
String inByte;
void setup() {
  Serial.begin(9600);     //inicia comunicação serial
  delay(100);
  Wire.setModule(0);      //SCL0 e SDA0
  Wire.begin();           // inicia comunicação i2c
  delay(100);
  indice();
}
void loop() {
  inByte = leStringSerial();
  if(inByte == "0"){
    Serial.print("\n\r(0) Lido\n\n\r");
    inByte = "";
    indice();
  }
  else if(inByte == "1"){   //Leitura do Registrador System Power State
    Serial.print("\n\r(1) Leitura i2c - Reg 0x20 = System Power State\n\n\r");
    leituraReg = lerRegistro(0x27, 0x20, 1); //CTL2=0 e CTL1=0
    delay(100);
    leituraReg = lerRegistro(0x37, 0x20, 1); //CTL2=1 e CTL1=0
    delay(100);
    leituraReg = lerRegistro(0x3F, 0x20, 1); //CTL2=1 e CTL1=1
    delay(100);
    leituraReg = lerRegistro(0x2F, 0x20, 1); //CTL2=0 e CTL1=1
    //Serial.print(leituraReg);
    inByte = "";
    indice();
  }
}
void indice (){
  Serial.print("(0) Lido\n\r");
  Serial.print("(1) Leitura i2c - Reg 0x20 = System Power State\n\r");
}
/* 
 *  int lerRegistro (int address, byte reg, int numBytes)
 *  descrição:
 *    - Escreve um dado em um determinado registro
 * 
 *  variáveis:
 *    - address: endereço de i2c do módulo
 *    - reg: registro a ser lido
 *    - numBytes: número de bytes a serem lidos
 * 
 *  retorno:
 *    - reading: leitura do registrador lido
 *   
 *  aplicação: lerRegistro(45, 0x01, 1);
 */
String lerRegistro (int address, byte reg, int numBytes){
  Wire.beginTransmission(address);      // transmit to device #45(0x2D)
  Wire.write(reg);                      // send reg addr to read
  Wire.endTransmission();               // stop transmitting
  Wire.requestFrom(address, numBytes);  // receive from device #45(0x2D) numBytes bytes
  String reading = (String) Wire.read();// save receive
  delay(100);
  return reading;
}
/* 
 *  String leStringSerial()
 *  descrição:
 *    - Lê uma string recebida via terminal.
 * 
 *  variáveis:
 *    - nenhuma.
 * 
 *  retorno:
 *    - conteudo: String recebida via terminal.
 */
String leStringSerial(){
  String conteudo = "";
  char caractere;
  while(Serial.available() > 0) {   // Enquanto receber algo pela serial
    caractere = Serial.read();      // Lê byte da serial
    if (caractere != '\n')          // Ignora caractere de quebra de linha
      conteudo.concat(caractere);   // Concatena valores
    delay(1000);                    // Aguarda buffer serial ler os caracteres
  }
  return conteudo;                  // Retorna o que foi lido
}

  • Hi Mateus,

    When you ordered the TPS65981EVM, it came with an FTDI breakoff board. I would suggest you use the I2C master from the FTDI as an example for your project. You can use your I2C sniffer to read back exactly what messages the FTDI is sending.

    If this answers your question, PLEASE select This resolved my issue

    Thank you,

    Eric

  • I have done that at first, but the signal was totally strange.

    I solved the problem inverting the pins SDA and SCL (yellow and orange wires), and the i2c address is 0x27.

    Thanks for trying to help!

    Bye.