cancel
Showing results for 
Search instead for 
Did you mean: 

STC3115 fuel gauge is not Working(NACK returned when I read the device id from master) and startup failed

EEngg.1
Associate

Hello Everyone,

We are having an issue with STC3115 (fuel gauge). We are connect Nrf51822(as Master) and stc3115 (as slave). we are read the device address from 0 to 127 . we got (I2C device found at address 0x70) from slave (stc3115) and then we read device id in the address of (STC3115_REG_ID 0x18) but we got (NACK) from slave . and then device does not startup.

Software:

1. https://github.com/st-sw/STC3115GenericDriver Library.

2.nrf51822 i2c master

Hardware:

1.sda (master-nrf51822) ->4.7k->sda(slave-stc3115)

2.scl (master-nrf51822) ->4.7k ->scl(slave-stc3115)

3.RSTO pin connect with 10k resistor (Pull Up)

My code is:

//Check I2C is working and Fuel gauge device connected

status = STC3115_CheckI2cDeviceId();

SEGGER_RTT_printf(0, "staus: %d\n", status);

if (status != 0) //error

{

if(status == -1)

{

printf(0,"STC3115: I2C error\n");

#ifdef DEBUG

//wait to simulate the whole application restart

while( GasGaugeTimerFinished() != 1);

nrf_delay_ms(1000);

goto GasGauge_Restart;

#endif

}

else if(status == -2)

printf(0,"STC3115: Wrong device detected\n");

else

printf(0,"STC3115: Unknown Hardware error\n");

return -1; //return on error

}

//----------------------------------------------------------------------

//Check Gasgauge is powered up & ready, and first measurement (V, I) is done (i.e. wait CounterValue is 3 or more)

for(i=0; i<20; i++) //check for 20*100ms = 2s

{

//CounterValue = STC3115_GetRunningCounter();

if(CounterValue >= 3) //ok, device ready

{

break; //exit loop

}

else if(CounterValue < 0) //communication Error

{

printf(0,"STC3115: Error power up.\n");

goto GasGauge_Restart;

}

else

{

//wait

Delay_ms(100);

}

}

if(CounterValue < 3) //timeout, the devise has not started

{

printf(0,"STC3115: Error power up.\n");

//goto GasGauge_Restart;

}

//----------------------------------------------------------------------

//Call STC3115 driver init&start function

status = GasGauge_Initialization(&STC3115_ConfigData, &STC3115_BatteryData);

if(status!=0 && status!=-2)

{

SEGGER_RTT_WriteString(0,"STC3115: Error in GasGauge_Initialization\n");

return -1; //return on error

}

#ifdef DEBUG

//----------------------------------------------------------------------

//Check Gasgauge is running (also checked in GasGauge_Task)

for(i=0; i<20; i++)

{

CounterValue = STC3115_GetRunningCounter();

if(CounterValue > 3) //Gas gauge COUNTER stays at value '3' after power up or Soft Reset, if not running

{

break; //exit loop

}

else

{

//wait

Delay_ms(100);

}

}

if(CounterValue <= 3) 

{

printf("STC3115: Error, GasGauge not running. Check your hardware.\n");

goto GasGauge_Restart;

}

#endif

//----------------------------------------------------------------------

while(1) //main infinite loop

{

if(GasGauge_HardwareShutDown == 1) //Completely shutdown the platform and the Gas gauge. (not recommended, it is better to let the Gas Gauge running connected to battery)

{

GasGauge_HardwareShutDown = 0;

status = GasGauge_Stop(); //stop the Gas gauge but keep its RAM content

if(status != 0)SEGGER_RTT_WriteString(0,"STC3115: Error in GasGauge_Stop\n");

#ifdef DEBUG

//wait to simulate the application is powered off for a couple of time

while( GasGaugeTimerFinished() != 1);

goto GasGauge_Restart;

#endif

return 0;

}

else if(GasGauge_UnknowError == 1)

{

GasGauge_UnknowError = 0;

status = GasGauge_Reset(); //Reset the Gasgauge without disconnecting the battery

if(status != 0) printf(0,"STC3115: Error in GasGauge_Reset\n");

goto GasGauge_Restart;

}

else //normal case

{

if(GasGaugeTimerFinished() == 1) //every 5s

{

/* if(GasGauge_ChangeLowPowerMode == 1) //switch between Voltage mode and Mixed mode

{

ChangeLowPowerMode();

GasGauge_ChangeLowPowerMode = 0;

}*/

//Call task function

status = GasGauge_Task(&STC3115_ConfigData, &STC3115_BatteryData); /* process gas gauge algorithm, returns results */

if (status > 0) //OK, new data available

{

/* printf("Battery: SoC=%i %%, Vbat=%i mV, I=%i mA, Cap=%i mAh, T=%i °C, Pres=%i ALM=%i , CCounter=%d, Time=%d s \r\n", 

STC3115_BatteryData.SOC * 0.1,

STC3115_BatteryData.Voltage, 

STC3115_BatteryData.Current, 

STC3115_BatteryData.ChargeValue,

STC3115_BatteryData.Temperature,

STC3115_BatteryData.Presence, 

STC3115_BatteryData.StatusWord >> 13, 

STC3115_BatteryData.ConvCounter, 

STC3115_BatteryData.ConvCounter * 0.5 //elapsed time since gas gauge started

);*/

 SEGGER_RTT_printf(0,"Vbat=%i mV",STC3115_BatteryData.Voltage);

}

else if(status == 0) //only previous SOC, OCV and voltage are valid 

{

printf("Battery: Previous_SoC=%i %%, Vbat=%i mV, OCV=%i mV, T=%i °C \r\n", 

STC3115_BatteryData.SOC * 0.1,

STC3115_BatteryData.Voltage,

STC3115_BatteryData.OCV,

STC3115_BatteryData.Temperature);

}

else if(status == -1) //error occured

{

if(STC3115_BatteryData.Presence == 0)

{  /* Battery disconnection has been detected */

printf(0,"STC3115 Error: Battery disconnected, or BATD pin level is over 1.61, or Vcc is below 2.7V \r\n");

}

else

{

printf("STC3115: I2C failure \r\n");

}

}

} // END Timer finished

else

{

//Do other Tasks here ...

}

} //END normal case

}//END loop

I am always Getting STC3115: Wrong device detected

What is the problem ?

0 REPLIES 0