Other Parts Discussed in Thread: BQ34Z100, BQSTUDIO
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.
Hi Shirish,
I do exactly as in document SLUA790 pg.8 (code below). But still unable to write to the flash. Is there any problem with my code?
Aside from the code, is the IC needed to be in Normal mode for the writing process to execute?
Because, I checked the CONTROL_STATUS and the bit for SLEEP mode was set to 1, which means the IC is in Sleep mode.
Do I need to set the IC to Normal mode first before I can write something to the IC?
/* To write 16000 to the Design Capacity on the data flash replacing the default value 4000*/ uint8_t subclass = 48; //or 0x30 uint8_t offset = 21; //or 0x15 uint16_t value = 16000; const uint8_t BQ34Z110_ADDRESS = 0x55; uint8_t flash_block_data[32] = {0}; /* Unsealed */ Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x00); Wire.write(0x14); Wire.write(0x04); Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x00); Wire.write(0x72); Wire.write(0x36); Wire.endTransmission(); delay(4000); // mandatory wait time after unseal /* Reading the data flash */ Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x61); // BlockDataControl() Wire.write(0x00); Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x3e); // DataFlashClass() Wire.write(subclass); // Subclass 48 = 0x30 Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x3f); // DataFlashBlock() Wire.write(offset / 32); // 21/32 = 0x00 Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x40); // BlockData() Wire.endTransmission(); Wire.requestFrom(BQ34Z110_ADDRESS, 32, true); Wire.readBytes(flash_block_data, 32); // read 32 bytes /* Checksum */ Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x60); // BlockDataCheckSum() Wire.write(0x00); Wire.endTransmission(); /* Update block data */ flash_block_data[offset] = value >> 8; flash_block_data[offset + 1] = value & 0xff; /* Writing the data flash */ Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x3e); // DataFlashClass() Wire.write(subclass); // Subclass 48 = 0x30 Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x3f); // DataFlashBlock() Wire.write(offset / 32); // 21/32 = 0x00 Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x40); //BlockData() Wire.write(flash_block_data, 32); // write 32 bytes Wire.endTransmission(); /* Checksum */ uint8_t chksum = flash_block_checksum(); uint8_t chksum2 = flash_block_checksum_2(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x60); // BlockDataCheckSum() Wire.write(chksum); Wire.endTransmission(); delay(5000); /* Reading the data flash */ Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x61); // BlockDataControl() Wire.write(0x00); Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x3e); // DataFlashClass() Wire.write(subclass); // Subclass 48 = 0x30 Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x3f); // DataFlashBlock() Wire.write(offset / 32); // 21/32 = 0x00 Wire.endTransmission(); Wire.beginTransmission(BQ34Z110_ADDRESS); Wire.write(0x40); // BlockData() Wire.endTransmission(); Wire.requestFrom(BQ34Z110_ADDRESS, 32, true); Wire.readBytes(flash_block_data, 32); // read 32 bytes Serial.println("Read Data Flash New"); for (int i = 0; i < 32; i++) { Serial.printf("%02i. 0x%02x\r\n", i, flash_block_data[i]); }
Hello Nur,
The code for each micro can behave differently due to differences in implementation
. I would recommend that you use bqStudio. Turn off dashboard refresh and then use Advanced comm tab to perform the steps. You can then monitor the bus and compare with your implementation.