主题中讨论的其他器件: BQ34Z100、 MSP430FR2155
工具与软件:
您好、TI 专家!
我正在使用由 MSP430FR2155、BQ76952和 BQ34Z100组成的定制设计 PCB。 我正在尝试访问数据存储器寄存器、我将打捆从寄存器中读取数据、但当我尝试写入寄存器时、操作无法正常工作。 我在 TI 网站上获取了 BQ799x2示例代码中的代码。 我已经按照 BQ76952 TRM 中所述的步骤访问第13.1节中的数据存储器。 我将上传我要使用的代码以及逻辑分析仪的屏幕截图。 您能告诉我在这里可以做些什么吗?
提前感谢! 祝你度过美好的一天!
// main program
CommandSubcommands(SET_CFGUPDATE);
BQ76952_write(monitor, EnabledProtectionsA, 0x8C, 1);
delayUS(50000);
rx_arr = BQ76952_readDMA(monitor, EnabledProtectionsA, 1);
tx_arr[6] = rx_arr[0];
tx_arr[7] = rx_arr[1];
CommandSubcommands(EXIT_CFGUPDATE);
// source code
int BQ76952_write(unsigned char Slave_address, uint16_t reg_addr, uint16_t data, int len)
{
unsigned int sentbyte = 0;
uint8_t TX_Buffer[3] = {0x00, 0x00, 0x00};
uint8_t TX_RegData[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
TX_RegData[0] = 0x3E;
TX_RegData[1] = reg_addr & 0xff;
TX_RegData[2] = (reg_addr >> 8) & 0xff;
TX_RegData[3] = data & 0xff; //1st byte of data
switch(len)
{
case 1: //1 byte datalength
I2CSendBytes(Slave_address, TX_RegData, 4, &sentbyte);
delayUS(2000);
TX_Buffer[0] = 0x60;
TX_Buffer[1] = Checksum(TX_RegData, 4);
TX_Buffer[2] = 0x06; //combined length of register address and data
I2CSendBytes(Slave_address, TX_Buffer, 3, &sentbyte); // Write the checksum and length
delayUS(2000);
break;
case 2: //2 byte datalength
TX_RegData[4] = (data >> 8) & 0xff;
I2CSendBytes(Slave_address, TX_RegData, 5, &sentbyte);
delayUS(2000);
TX_Buffer[0] = 0x60;
TX_Buffer[1] = Checksum(TX_RegData, 5);
TX_Buffer[2] = 0x07; //combined length of register address and data
I2CSendBytes(Slave_address, TX_Buffer, 3, &sentbyte); // Write the checksum and length
delayUS(2000);
break;
}
return 0;
}
unsigned char* BQ76952_readDMA(unsigned char Slave_address, uint16_t reg_addr, int len)
{
unsigned int sentbyte = 0;
unsigned int count = 0;
static unsigned char RX_Buffer[3] = {0x00, 0x00, 0x00};
uint8_t TX_RegData[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
TX_RegData[0] = 0x3E;
TX_RegData[1] = reg_addr & 0xff;
TX_RegData[2] = (reg_addr >> 8) & 0xff;
switch(len)
{
case 1: //1 byte datalength
I2CSendBytes(Slave_address, TX_RegData, 3, &sentbyte);
delayUS(2000);
I2CReadBytes(Slave_address, RX_Buffer, len, &count);
delayUS(2000);
break;
case 2: //2 byte datalength
I2CSendBytes(Slave_address, TX_RegData, 3, &sentbyte);
delayUS(2000);
I2CReadBytes(Slave_address, RX_Buffer, len, &count);
delayUS(2000);
break;
}
return RX_Buffer;
}
unsigned char Checksum(unsigned char *ptr, unsigned char len)
// Calculates the checksum when writing to a RAM register. The checksum is the inverse of the sum of the bytes.
{
unsigned char i;
unsigned char checksum = 0;
for(i=0; i<len; i++)
checksum += ptr[i];
checksum = 0xff & ~checksum;
return(checksum);
}
进入 CONFIG_UPDATE 模式: 
数据写入: 
校验和: 
数据读取: 
退出 CONFIG_UPDATE:









