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?