Tool/software:
*I edited because I found a mistake in my code, but still not working.*
Hi,
I am programming the fuel gauge and I am entering in calibration mode by accessing UNSEALED mode. However, when I read the CONTROL_STATUS register (by sending {0x00, 0x01, 0x00, 0x00}) I always get 0x0000. This is how I am doing it:
This is the function to enable CALIBRATION mode:
void gau_enable_calib(void)
{
uint8_t u8OperationConfALowW[2];
uint8_t u8OperationConfAHighW[2];
uint8_t u8AccumW[2];
// uint8_t u8OpConfAR;
uint8_t u8AccMode = 0xA5;
uint8_t u8LenW[2];
uint8_t u8ChecksumW[2];
uint8_t u8GauStartW[3];
uint8_t u8EnableCalW[3];
bool boolStatusAccumW = false;
bool boolStatusEnableCal = false;
bool boolStatusGauStartW = false;
/*Enable DF write*/
gau_flash_write_enable();
/*Manufacturer access control Operation Config A decomposition addresses*/
gau_MAC_decomp(u8OperationConfALowW, u8OperationConfAHighW, u16OperationConfigA);
/*Gauge start address decomposition*/
gau_address_decomp(u8GauStartW, u16GauStart);
/*Enable calibration address decomposition*/
gau_address_decomp(u8EnableCalW, u16EnableCal);
/*Access Operation Config A in little endian format*/
gau_flash_access(u8OperationConfALowW, u8OperationConfAHighW);
/*MAC data to change to ACCUMULATOR mode*/
u8AccumW[0] = 0x40;
u8AccumW[1] = u8AccMode;
/*Change to ACCUMULATOR mode*/
boolStatusAccumW = SERCOM4_I2C_Write(u8GaugeAddrW, u8AccumW, sizeof(u8AccumW));
while(SERCOM4_I2C_IsBusy());
uint8_t u8Checksum = ~(u8OperationConfALowW[1] + u8OperationConfAHighW[1] + u8AccMode) & 0xFF;
/*Write Operation Config A checksum*/
gau_checksum_get_write(u8Checksum, u8ChecksumW);
/*Write Operation Config A length*/
gau_length_get_write(u8LenW, u8OperationConfALowW[1], u8OperationConfAHighW[1], u8AccMode, u8Checksum, 0, 0, 0);
/*Enable calibration*/
boolStatusEnableCal = SERCOM4_I2C_Write(u8GaugeAddrW, u8EnableCalW, sizeof(u8EnableCalW));
while (SERCOM4_I2C_IsBusy());
/*Gauge enable (PA18 in final product and demo) HIGH*/
PORT_PinSet(PORT_PIN_PA18);
boolStatusGauStartW = SERCOM4_I2C_Write(u8GaugeAddrW, u8GauStartW, sizeof(u8GauStartW));
while(SERCOM4_I2C_IsBusy());
}
And the function where I try to access UNSEALED mode is this one:
void gau_flash_write_enable(void)
{
uint8_t u8Unsealed1W[3];
uint8_t u8Unsealed2W[3];
uint8_t u8BlockDataW[2];
bool boolStatusUnsealed1W = false;
bool boolStatusUnsealed2W = false;
bool boolStatusBlockDataW = false;
/*Control and UNSEALED mode step 1 decomposition addresses*/
gau_MAC_decomp(u8Unsealed1LowW, u8Unsealed1HighW, u16UnsealedMode1);
/*Control and UNSEALED mode step 2 decomposition addresses*/
gau_MAC_decomp(u8Unsealed2LowW, u8Unsealed2HighW, u16UnsealedMode2);
/*Block Data control addresses*/
u8BlockDataW[0] = BLK_DATA_CTRL;
u8BlockDataW[1] = 0x00;
/*Enter UNSEALED mode*/
gau_flash_access(u8Unsealed1LowW, u8Unsealed1HighW);
gau_flash_access(u8Unsealed2LowW, u8Unsealed2HighW);
/*Enable writing in DF*/
boolStatusBlockDataW = SERCOM4_I2C_Write(u8GaugeAddrW, &u8BlockDataW[0], sizeof(u8BlockDataW));
while(SERCOM4_I2C_IsBusy());
}
gau_MAC_decomp() function is for decomposing the value 0x0414 and 0x3672 from Unseal Step 1/2 and sending it with little endian through 0x3E and 0x3F. What is the purpose of FullUnseal Step 1/2, by the way?
Carlos