STM32 通过I2C 读写 BQ27541 的 data flash, 失败的问题

我用单片机 STM32 通过I2C 操作 BQ27541 的 data flash,. 代码是按 TI 的 MSP430 的exsample 来写的 .  写入的数据和

读取的数据比较,是一致的。但重新上电,Block A 还是初始值 00, 是有什么命令没有送吗? 程序如下:

// Write & read back 32 bytes of data in Manufacturer Info Block A
for (i = 0; i < 32; i++)
{
TxData[i] = i; // Initialize data to be written
}
IIC_Write_One_Byte(bq27541CMD_DFDCNTL, 0);// BlockDataControl() = 0x00
IIC_Write_One_Byte(bq27541CMD_DFCLS, 58);// Write the subclass value
IIC_Write_One_Byte(bq27541CMD_DFBLK, 0);// Select offset within the flash
for (i = 0; i < 32; i++) // Compute the checksum of the block
{
sum += TxData[i]; // Calculate the sum of the values
}
checksum = (0xFF - (sum & 0x00FF)); // Compute checksum based on the sum
IIC_Write_One_Byte(bq27541CMD_DFDCKS, checksum); // Write checksum value
for (i = 0; i < 32; i++) // Write 32 bytes to Info Block A
{
IIC_Write_One_Byte((bq27541CMD_ADF+i), TxData[i]);
}
IIC_Read_Bytes(bq27541CMD_ADF,&RxData[0], 32); // Read the contents of the block
for (i = 0; i < 32; i++) // Check if writes were successful
{
if (TxData[i] != RxData[i]) // Tx & Rx data values match?
{
sum=0 ;//error
}
}

3 个回复