TI中文支持网
TI专业的中文技术问题搜集分享网站

BQ76952: BQ76952的STM32L431驱动代码问题

Part Number:BQ76952Other Parts Discussed in Thread:BQSTUDIO

int I2C_ReadReg(uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
{
unsigned int RX_CRC_Fail = 0; // reset to 0. If in CRC Mode and CRC fails, this will be incremented.
uint8_t RX_Buffer [MAX_BUFFER_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
#if CRC_Mode
{
uint8_t crc_count = 0;
uint8_t ReceiveBuffer [10] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
crc_count = count * 2;
unsigned int j;
unsigned int i;
unsigned char CRCc = 0;
uint8_t temp_crc_buffer [3];

HAL_I2C_Mem_Read(&hi2c1, DEV_ADDR, reg_addr, 1, ReceiveBuffer, crc_count, 1000);
uint8_t crc1stByteBuffer [4] = {0x10, reg_addr, 0x11, ReceiveBuffer[0]};
CRCc = CRC8(crc1stByteBuffer,4);
if (CRCc != ReceiveBuffer[1])
{
   RX_CRC_Fail += 1;
}
RX_Buffer[0] = ReceiveBuffer[0];

j = 2;
for (i=1; i<count; i++)
{
   RX_Buffer[i] = ReceiveBuffer[j];
   temp_crc_buffer[0] = ReceiveBuffer[j];
   j = j + 1;
   CRCc = CRC8(temp_crc_buffer,1);
      if (CRCc != ReceiveBuffer[j])
         RX_CRC_Fail += 1;
       j = j + 1;
   }
   CopyArray(RX_Buffer, reg_data, crc_count);
}
#else
HAL_I2C_Mem_Read(&hi2c1, DEV_ADDR, reg_addr, 1, reg_data, count, 1000);
#endif
return 0;
}

中ReceiveBuffer大小只有10, 而crc_count = count * 2; 则count 就会限制到最大为5对吗?

而 Subcommands函数中I2C_ReadReg(0x40, RX_32Byte, 32); 为32, 是不是上面的ReadReg函数有问题?

Star Xu:

您好,请参考网页提供的sample code

 Here is the link: https://www.ti.com/lit/zip/sluc701 

There is also a video showing how to first configure the device settings using BQStudio and then implementing these settings into the code examples:

https://www.ti2k.com/wp-content/uploads/ti2k/DeyiSupport_电源管理_library.html

赞(0)
未经允许不得转载:TI中文支持网 » BQ76952: BQ76952的STM32L431驱动代码问题
分享到: 更多 (0)

© 2024 TI中文支持网   网站地图 鲁ICP备2022002796号-1