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.

BQ76940: BQ76940 no response

Part Number: BQ76940

Hi

Please help check the schematic, the IIC has no response signal.

YT-BMS-A00_20210525.pdf

Thanks

Star

  • Hi Star,

    In the BQ76940 data sheet pin map table https://www.ti.com/document-viewer/BQ76940/datasheet/bq76940-pin-map-slusbk00#slusbk00 pins 11 and 12 should connect to CAP2 rather than CAP3 as shown in the schematic.  This pin mis-connection may have damaged the part, I don't know if it would prevent I2C from ack but would certainly have some odd current draw.

    TS1 must have a rising edge to wake the part.  The schematic shows it connected to C1 through R51 which would keep a continuous voltage on the pin. A continuous voltage will not wake the part or keep it from going to sleep, it will prevent a rising edge.

    Another thing to check is the part version, there are 2 addresses available on the BQ76940, see the table https://www.ti.com/document-viewer/BQ76940/datasheet/device-comparison-table-slusbk23421#SLUSBK23421 , be sure the MCU is using the correct address for the part version installed.

    With the CAP2, CAP3 swap I suspect the part is damaged.  You might try to lift the pins or cut the trace to them.  R51 might be removed and momentarily shorted to wake the part, if it is damaged it will have an XREADY fault.  With a working part if it is shutdown and re-started quickly without the thermistor or resistor on TS2 and TS3 it may also have a XREADY fault.  The pull down resistors or thermistors discharges the pins so the IC can start properly.   

  • Hi WM5295

    Thanks for your reply.

    The customer has modified the schematic on the new board.
    1. Connect pins 11 and 12 to CAP2, and pins 16, 17 to CAP3.
    2. TS1 is connected to the ground through a 10K resistor, and TS1 is connected to the GPIO (3.3V/0V) of the microcontroller through a 100 ohm resistor. After power-on, TS1 is controlled to switch from 0V to 3.3V through GPIO, and TS2 is connected to VC5X through a 10K resistor, TS3 is connected to VC10X through a 10K resistor;
    However, there is still no response (ACK) to the acquired waveform. Please check the attached waveform.


    After testing, the voltage as follows:

    V(C10X-TS3) = 0, V(C10X-GND) = 37.37V, V(TS3) = 37.37V
    V(C5X-TS2) = 0, V(C5X) = 18.67V, V(TS2) = 18.67V
    V(TS1-GND) = 3.2V
    VPACK+ = 52.2V
    VCELL14 = 3.73V
    VCELL13 = 3.73V
    VCELL.. = 3.73V
    VREGSRC = 17.17V
    VREGOUT = 3.28V
    //main函数
    int main(void)
    {
    	//rcu_config();
        /* configure systick */
        systick_config();
    	
    	bsp_can_init(CAN_250K);
    	gd_eval_led_init();
        gd_eval_com_init(EVAL_COM0);
    	gd_eval_com_init(EVAL_COM1);
        bsp_adc_init();
    	
    	BQ76940_config();
    	
    	sd_file_init();
    	
        // print out the clock frequency of system, AHB, APB1 and APB2 
        printf("\r\nCK_SYS is %d", rcu_clock_freq_get(CK_SYS));
        printf("\r\nCK_AHB is %d", rcu_clock_freq_get(CK_AHB));
        printf("\r\nCK_APB1 is %d", rcu_clock_freq_get(CK_APB1));
        printf("\r\nCK_APB2 is %d", rcu_clock_freq_get(CK_APB2));
    
    	gd_eval_led_on();
    	
    	
    	bms_application_init();
        while (1)
    	{
    		if(task_10ms_flag == 1)
    		{
    		
    			task_10ms_flag = 0;
    		}
    		if(task_20ms_flag == 1)
    		{
    		
    			task_10ms_flag = 0;
    		}
    		if(task_50ms_flag == 1)
    		{
    			
    			task_50ms_flag = 0;
    		}
    		if(task_100ms_flag == 1)
    		{
    			test_data_tx_can_message();
    			task_100ms_flag = 0;
    		}
    		if(task_200ms_flag == 1)
    		{
    			bms_pack_parameter_to_usart0();
    			task_200ms_flag = 0;
    		}
    		if(task_500ms_flag == 1)
    		{
    			adc_proc();
    			jdata_d0_real_data_send();
    			jdata_d1_soc_data_send();
    			jdata_d2_power_data_send();
    			jdata_d3_safe_data_send();
    			task_500ms_flag = 0;
    		}	
    		if(task_1000ms_flag == 1)
    		{
    			sd_write_file();
    			gd_eval_led_toggle();
    			printf("USART0 OK!");	
    
    			bsp_bq76940_get_update_data();
    			
    			task_1000ms_flag = 0;
    		}
    		
        }
    }
    
    //IIC.c
    //头文件
    #include "iic.h"
    #include "gd32f10x_eval.h"
    #include "systick.h"
    #include "bsp_bq76940.h" 
    
    
    void BQ_IIC_Configuration(void)
    {
    	rcu_periph_clock_enable(RCU_GPIOB);
    	
    	gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, IIC1_SCL_Pin);
    	gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, IIC1_SDA_Pin);
    	IIC1_SCL_H;
    	IIC1_SDA_H;
    }
    
    void delay_us(uint8_t time)
    {
    	u16 i;
    	while(time --)
    
    	for(i=0;i<20;i++) 
    	__asm("nop");
    }
    
    void IIC1_SDA_OUT(void)
    {
    	gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, IIC1_SDA_Pin);
    }
    
    void IIC1_SDA_IN(void)
    {
    	gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, IIC1_SDA_Pin);//GPIO_MODE_IPU
    }
    
    //产生起始信号
    void IIC1_Start(void)
    {
    	IIC1_SDA_OUT();
    	
    	IIC1_SDA_H;
    	IIC1_SCL_H;
    	delay_us(4);//5
    	IIC1_SDA_L;
    	delay_us(4);//6
    	IIC1_SCL_L;
    	//delay_us(10);
    }
    
    //产生停止信号
    void IIC1_Stop(void)
    {
       IIC1_SDA_OUT();
    
       IIC1_SCL_L;
       IIC1_SDA_L;
       delay_us(4);//6	
       IIC1_SCL_H;
       IIC1_SDA_H;
       delay_us(4);//6
    }
    
    //主机产生应答信号ACK
    void IIC1_Ack(void)
    {
       IIC1_SCL_L;
       IIC1_SDA_OUT();
       IIC1_SDA_L;
       delay_us(4);//2
       IIC1_SCL_H;
       delay_us(4);//5
       IIC1_SCL_L;
    }
    
    //主机不产生应答信号NACK
    void IIC1_NAck(void)
    {
       IIC1_SCL_L;
       IIC1_SDA_OUT();
       IIC1_SDA_H;
       delay_us(4);//2
       IIC1_SCL_H;
       delay_us(4);//5
       IIC1_SCL_L;
    }
    //等待从机应答信号
    //返回值: 1 接收应答失败
    //		  0 接收应答成功
    u8 IIC1_Wait_Ack(void)
    {
    	u16 tempTime=0;
    
    	IIC1_SCL_L;
    	delay_us(4);
    	IIC1_SDA_H;
    	delay_us(4);
    	IIC1_SCL_H;
    	delay_us(4);
    	IIC1_SDA_IN();
    	while(gpio_input_bit_get(GPIO_IIC1, IIC1_SDA_Pin))
    	{
    		tempTime++;
    		if(tempTime>1000)
    		{
    			IIC1_Stop();
    			return 1;
    		}	 
    	}
    
    	IIC1_SCL_L;
    	return 0;
    }
    //IIC 发送一个字节
    void IIC1_Send_Byte(u8 txd)
    {
    	u8 i=0;
    
    	IIC1_SDA_OUT();
    	IIC1_SCL_L;//拉低时钟开始数据传输
    	delay_us(4);//2
    	for(i=0;i<8;i++)
    	{
    		if((txd&0x80)>>7) //0x80  1000 0000
    			IIC1_SDA_H;
    		else
    			IIC1_SDA_L;
    
    		txd<<=1;
    		IIC1_SCL_H;
    		delay_us(4); //2
    		IIC1_SCL_L;
    		delay_us(4);//2
    	}
    }
    
    //IIC 读取一个字节
    u8 IIC1_Read_Byte(u8 ack)
    {
       u8 i=0,receive=0;
    
       IIC1_SDA_IN();
       for(i=0;i<8;i++)
       {
       		IIC1_SCL_L;
    		delay_us(4);//2
    		IIC1_SCL_H;
    		receive<<=1;
    		if(gpio_input_bit_get(GPIO_IIC1, IIC1_SDA_Pin))
    		   receive|=0x01;
    		delay_us(4);	
       }
    
       if(ack==0)
    	   	IIC1_NAck();
    	else
    		IIC1_Ack();
    
    	return receive;
    }
    
    void BQ_IIC_write_one_byte_CRC(uint16_t WriteAddr,uint8_t DataToWrite)
    {
    	unsigned char DataBuffer[4];
    
    	DataBuffer[0] = 0X08 << 1;
    	DataBuffer[1] = WriteAddr;
    	DataBuffer[2] = DataToWrite;
    	DataBuffer[3] = IIC_CRC8(DataBuffer, 3, 7);
    
    	IIC1_Start();  	
    	IIC1_Send_Byte(DataBuffer[0]);   //发送器件地址0X10,写数据 		 
    	IIC1_Wait_Ack();	   
    	IIC1_Send_Byte(DataBuffer[1]);   //发送地址
    	IIC1_Wait_Ack(); 										  		   
    	IIC1_Send_Byte(DataBuffer[2]);     //发送字节							   
    	IIC1_Wait_Ack();	
    	IIC1_Send_Byte(DataBuffer[3]);     //发送CRC
    	IIC1_Wait_Ack();
    	IIC1_Stop();//产生一个停止条件 	  
    	delay_1ms(10);
    }
    
    uint8_t BQ_IIC_read_one_byte(uint16_t ReadAddr)
    {				  
    	uint8_t temp=0;		  	    																 
    	IIC1_Start();  
    	IIC1_Send_Byte(0x08 << 1);   //发送器件地址0XA0,写数据 	 
    	IIC1_Wait_Ack();
    	IIC1_Send_Byte(ReadAddr);   //发送低地址
    	IIC1_Wait_Ack();    
    	IIC1_Start();  	 	   
    	IIC1_Send_Byte(0x11);           //进入接收模式			   
    	IIC1_Wait_Ack(); 
    	temp=IIC1_Read_Byte(1);		   
    	IIC1_Stop();//产生一个停止条件
    	return temp;
    }
    
    //IIC.h
    #ifndef IIC_H_
    #define IIC_H_
    
    
    
    #include "main.h"
    #include "gd32f10x_gpio.h"
    
    
    #define IIC1_SCL_Pin	GPIO_PIN_10
    #define IIC1_SDA_Pin	GPIO_PIN_11	
    #define IIC1_SCL IIC1_SCL_Pin
    #define IIC1_SDA IIC1_SDA_Pin
    #define GPIO_IIC1 GPIOB
    
    #define IIC1_SCL_H gpio_bit_write(GPIO_IIC1, IIC1_SCL_Pin, SET)
    #define IIC1_SCL_L gpio_bit_write(GPIO_IIC1, IIC1_SCL_Pin, RESET)
    
    #define IIC1_SDA_H gpio_bit_write(GPIO_IIC1, IIC1_SDA_Pin, SET)
    #define IIC1_SDA_L gpio_bit_write(GPIO_IIC1, IIC1_SDA_Pin, RESET)
    
    void IIC1_SDA_OUT(void);
    void IIC1_SDA_IN(void);
    void IIC1_Start(void);
    void IIC1_Stop(void);
    void IIC1_Ack(void);
    void IIC1_NAck(void);
    uint8_t IIC1_Wait_Ack(void);
    void IIC1_Send_Byte(uint8_t txd);
    uint8_t IIC1_Read_Byte(u8 ack);
    
    #define IIC2_SLAVE_ADDRESS7    	0x08
    
    #define IIC_WRITE				0x01
    #define IIC_READ				0x00
    
    extern void BQ_IIC_Configuration(void);
    extern void BQ_IIC_write_one_byte_CRC(uint16_t WriteAddr,uint8_t DataToWrite);
    extern uint8_t BQ_IIC_read_one_byte(uint16_t ReadAddr);
    
    /*
    #define BQ_I2C_SCL_PIN      		GPIO_PIN_10   
    #define BQ_I2C_SCL_GPIO_PORT   	    GPIOB  
    
     
    #define BQ_I2C_SDA_PIN      		GPIO_PIN_11   
    #define BQ_I2C_SDA_GPIO_PORT   	    GPIOB  
    
    
    #define BQ_IIC_SCL_H         	 	gpio_bit_set(BQ_I2C_SCL_GPIO_PORT , BQ_I2C_SCL_PIN)   
    #define BQ_IIC_SCL_L            	gpio_bit_reset(BQ_I2C_SCL_GPIO_PORT , BQ_I2C_SCL_PIN) 
       
    #define BQ_IIC_SDA_H         	 	gpio_bit_set(BQ_I2C_SDA_GPIO_PORT , BQ_I2C_SDA_PIN)   
    #define BQ_IIC_SDA_L         	 	gpio_bit_reset(BQ_I2C_SDA_GPIO_PORT , BQ_I2C_SDA_PIN) 
    
    #define BQ_IIC_SCL_read       		gpio_input_bit_get(BQ_I2C_SCL_GPIO_PORT , BQ_I2C_SCL_PIN)
    #define BQ_IIC_SDA_read       		gpio_input_bit_get(BQ_I2C_SDA_GPIO_PORT , BQ_I2C_SDA_PIN)
    
    
    void BQ_IIC_Configuration(void);
    ControlStatus BQ_IIC_WriteByte(uint8_t SendByte, uint16_t WriteAddress, uint8_t DeviceAddress);
    ControlStatus BQ_IIC_ReadByte(uint8_t* pBuffer, uint16_t length, uint16_t ReadAddress, uint8_t DeviceAddress);
    uint8_t BQ_IIC_read_one_byte(uint16_t ReadAddr);
    void BQ_IIC_write_one_byte(uint16_t WriteAddr,uint8_t DataToWrite);
    void BQ_IIC_write_one_byte_CRC(uint16_t WriteAddr,uint16_t DataToWrite);
    uint8_t BQ_IIC_read_one_byte(uint16_t ReadAddr);
    */
    
    #endif
    
    //BQ76940.c
    #include "bsp_bq76940.h"
    #include "gd32f10x_i2c.h"
    #include "iic.h"
    #include "systick.h"
    #include "math.h"
    #include "gd32f10x_eval.h"
    
    
    /******************************************Code Start*************************************************/
    int Batteryval[50]={0};
    unsigned char shang[500]={0xAA,0x01};
    unsigned char shang1[50]={0xAA,0x02};
    unsigned char shang2[50]={0xAA,0x03};
    unsigned char shang3[50]={0xAA,0x04};
    
    unsigned char can_buf1[8]={0xAA,0x01};
    unsigned char can_buf2[8]={0xAA,0x02};
    unsigned char can_buf3[8]={0xAA,0x03};
    unsigned char can_buf4[8]={0xAA,0x04};
    unsigned char can_buf5[8]={0xAA,0x05};
    unsigned char can_buf6[8]={0xAA,0x06};
    unsigned char can_buf7[8]={0xAA,0x07};
    
    uint16_t g_iCell1mVolt = 0;
    uint16_t g_iCell2mVolt = 0;
    uint16_t g_iCell3mVolt = 0;
    uint16_t g_iCell4mVolt = 0;
    uint16_t g_iCell5mVolt = 0;
    uint16_t g_iCell6mVolt = 0;
    uint16_t g_iCell7mVolt = 0;
    uint16_t g_iCell8mVolt = 0;
    uint16_t g_iCell9mVolt = 0;
    uint16_t g_iCell10mVolt = 0;
    uint16_t g_iCell11mVolt = 0;
    uint16_t g_iCell12mVolt = 0;
    uint16_t g_iCell13mVolt = 0;
    uint16_t g_iCell14mVolt = 0;
    uint16_t g_iCell15mVolt = 0;
    uint16_t g_iPackVolt = 0;
    uint16_t g_iPackCurrent = 0;
    uint16_t g_iTemp1 = 0;
    uint16_t g_iTemp2 = 0;
    uint16_t g_iTemp3 = 0;
    uint16_t g_iTemp4 = 0;
    uint16_t g_iTemp5 = 0;
    uint16_t g_iTemp6 = 0;
    uint16_t g_iSoc = 0;
    
    
    
    
    
    
    
    
    int ADC_offset,GAIN;
    float ADC_GAIN = 0;
    
    
    void MCU_WAKE_BQ_ONOFF(uint8_t onoff)
    {
    
    }
    
    void Get_offset(void)
    {
     unsigned char gain[2];
     
     gain[0]=BQ_IIC_read_one_byte(ADCGAIN1);//ADC_GAIN1
     gain[1]=BQ_IIC_read_one_byte(ADCGAIN2);//ADC_GAIN2
     ADC_GAIN = ((gain[0]&0x0c)<<1)+((gain[1]&0xe0)>>5);//12uV
     ADC_offset=BQ_IIC_read_one_byte(ADCOFFSET);//45mV
     GAIN = 365+ADC_GAIN;//GAIN=377uV
    }
    
    void BQ76940_config(void)
    {
    	BQ_IIC_Configuration();
    	
    	WAKE_ALL_DEVICE(); 
    	BQ_1_2_config();
    	Get_offset();
    	OV_UV_1_2_PROTECT();
    	OCD_SCD_PROTECT();  
    	//Open_DSG_CHG();  
    
    	BQ_IIC_write_one_byte_CRC(SYS_STAT,0xFF);  
    }
    
    void BQ_1_2_config(void)
    {
        BQ_1_config();//
    }
    
    void OV_UV_1_2_PROTECT(void)
    {
        OV_UV_1_PROTECT();
    }
    
    void WAKE_ALL_DEVICE(void)
    {
    	bms_boot_init();
    //	delay_1ms(100);
    	bms_boot_on();
    	//MCU_D_POWER_ONOFF(1);
    	//MCU_KZ_QB_POWER_ONOFF(1);
    	//MCU_WAKE_BQ_ONOFF(1);
    	//可做BQ76940的唤醒
    	delay_1ms(100);
    }
    
    
    void SHIP_ALL_DEVICE(void)
    {
    	BQ_IIC_write_one_byte_CRC(SYS_STAT,0xFF);
    }
    
    void Get_Battery1(void)
    {
    	unsigned int readbattbuf[2];
    	unsigned int battery1val[2];
    	short batteryval1;
    
    	readbattbuf[1] = BQ_IIC_read_one_byte(0x0c);
    	readbattbuf[0] = BQ_IIC_read_one_byte(0x0d);
    
    	batteryval1= readbattbuf[1];
    	batteryval1= (batteryval1 << 8) |readbattbuf[0];
    	batteryval1=((batteryval1*GAIN)/1000)+ADC_offset;//单体电压计算公式,第1串
    	printf("bat1 volt = %d\r\n",batteryval1);
    	Batteryval[0]=batteryval1;
    
    	battery1val[1]=(char)(batteryval1 >> 8);
    	battery1val[0]=(char)(batteryval1 & 0x00FF);
    
    	shang[2]=battery1val[1];
    	shang[3]=battery1val[0];
    
    	shang1[2]=battery1val[1];
    	shang1[3]=battery1val[0];
    
    	can_buf1[2]=battery1val[1];
    	can_buf1[3]=battery1val[0];
    }
    
    
    /****************************************
    fuction: void Get_Battery2(void)
    description:获取第2号单体电池电压
    Parameters:battery2val[0],battery2val[1];
    ******************************************/
    void Get_Battery2(void)
    {
    	char readbattbuf[2];
    	int batteryval2;
    	short battery2val[2];
    
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x0e);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x0f);
    
    	batteryval2= readbattbuf[1];
    	batteryval2= (batteryval2 << 8) |readbattbuf[0];
    
    	batteryval2=((batteryval2*GAIN)/1000)+ADC_offset;//????????,?2?
    	Batteryval[1]=batteryval2;
    	printf("bat2 volt = %d\r\n",batteryval2);
    	battery2val[1]=(char)(batteryval2 >> 8);
    	battery2val[0]=(char)(batteryval2 & 0x00FF);
    
    	shang[4]=battery2val[1];
    	shang[5]=battery2val[0];
    	shang1[4]=battery2val[1];
    	shang1[5]=battery2val[0];
    
    	can_buf1[4]=battery2val[1];
    	can_buf1[5]=battery2val[0];
    
    }
    /****************************************
    fuction: void Get_Battery3(void)
    description:获取第3号单体电池电压
    Parameters:battery3val[0],battery3val[1];
    ******************************************/
    void Get_Battery3(void)
    {
    	char readbattbuf[2];
    	int batteryval3 ;
    	char battery3val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x10);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x11);
    
    	batteryval3= readbattbuf[1];
    	batteryval3= (batteryval3 << 8) |readbattbuf[0];
    	batteryval3=((batteryval3*GAIN)/1000)+ADC_offset;//????????,?3?
    	battery3val[1]=(char)(batteryval3 >> 8);
    	battery3val[0]=(char)(batteryval3 >> 0);
    	Batteryval[2]=batteryval3;
    
    	shang[6]=battery3val[1];
    	shang[7]=battery3val[0];
    
    	shang1[6]=battery3val[1];
    	shang1[7]=battery3val[0];
    
    	can_buf1[6]=battery3val[1];
    	can_buf1[7]=battery3val[0];
    }
    /****************************************
    fuction: void Get_Battery4(void)
    description:获取第4号单体电池电压
    Parameters:battery4val[0],battery4val[1];
    ******************************************/
    void Get_Battery4(void)
    {
    	char readbattbuf[2];
    	int batteryval4 ;
    	char battery4val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x12);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x13);
    
    	batteryval4= readbattbuf[1];
    	batteryval4= (batteryval4 << 8) |readbattbuf[0];
    	batteryval4=((batteryval4*GAIN)/1000)+ADC_offset;//????????,?4?
    	battery4val[1]=(char)(batteryval4 >> 8);
    	battery4val[0]=(char)(batteryval4 >> 0);
    	Batteryval[3]=batteryval4;
    
    	shang[8]=battery4val[1];
    	shang[9]=battery4val[0];
    
    	shang1[8]=battery4val[1];
    	shang1[9]=battery4val[0];
    
    	can_buf2[2]=battery4val[1];
    	can_buf2[3]=battery4val[0];
    
    }
    /****************************************
    fuction: void Get_Battery5(void)
    description:获取第5号单体电池电压
    Parameters:battery5val[0],battery5val[1];
    ******************************************/
    void Get_Battery5(void)
    {
    	char readbattbuf[2];
    	short batteryval5 ;
    	char battery5val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x14);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x15);
    
    	batteryval5= readbattbuf[1];
    	batteryval5= (batteryval5 << 8) |readbattbuf[0];
    	batteryval5=((batteryval5*GAIN)/1000)+ADC_offset;//????????,?5?
    	Batteryval[4]=batteryval5;
    	battery5val[1]=(char)(batteryval5 >> 8);
    	battery5val[0]=(char)(batteryval5 & 0x00FF);
    
    	shang[10]=battery5val[1];
    	shang[11]=battery5val[0];
    
    	shang1[10]=battery5val[1];
    	shang1[11]=battery5val[0];
    
    	can_buf2[4]=battery5val[1];
    	can_buf2[5]=battery5val[0];
    
    }
    /****************************************
    fuction: void Get_Battery6(void)
    description:获取第6号单体电池电压
    Parameters:battery6val[0],battery6val[1];
    ******************************************/
    void Get_Battery6(void)
    {
    	char readbattbuf[2];
    	short batteryval6 ;
    	char battery6val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x16);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x17);
    
    	batteryval6= readbattbuf[1];
    	batteryval6= (batteryval6 << 8) |readbattbuf[0];
    	batteryval6=((batteryval6*GAIN)/1000)+ADC_offset;//????????,?6?
    	Batteryval[5]=batteryval6;
    	battery6val[1]=(char)(batteryval6 >> 8);
    	battery6val[0]=(char)(batteryval6 & 0x00FF);
    
    	shang[12]=battery6val[1];
    	shang[13]=battery6val[0];
    
    	shang1[12]=battery6val[1];
    	shang1[13]=battery6val[0];
    
    	can_buf2[6]=battery6val[1];
    	can_buf2[7]=battery6val[0];
    
    }
    /****************************************
    fuction: void Get_Battery7(void)
    description:获取第7号单体电池电压
    Parameters:battery7val[0],battery7val[1];
    ******************************************/
    void Get_Battery7(void)
    {
    	char readbattbuf[2];
    	short batteryval7 ;
    	char battery7val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x18);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x19);
    
    	batteryval7= readbattbuf[1];
    	batteryval7= (batteryval7 << 8) |readbattbuf[0];
    	batteryval7=((batteryval7*GAIN)/1000)+ADC_offset;//????????,?7?
    	Batteryval[6]=batteryval7;
    	battery7val[1]=(char)(batteryval7 >> 8);
    	battery7val[0]=(char)(batteryval7 & 0x00FF);
    
    	shang[14]=battery7val[1];
    	shang[15]=battery7val[0];
    
    	shang1[14]=battery7val[1];
    	shang1[15]=battery7val[0];
    
    	can_buf3[2]=battery7val[1];
    	can_buf3[3]=battery7val[0];
    
    }
    /****************************************
    fuction: void Get_Battery8(void)
    description:获取第8号单体电池电压
    Parameters:battery8val[0],battery8val[1];
    ******************************************/
    void Get_Battery8(void)
    {
    	char readbattbuf[2];
    	int batteryval8 ;
    	char battery8val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x1a);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x1b);
    
    	batteryval8= readbattbuf[1];
    	batteryval8= (batteryval8 << 8) |readbattbuf[0];
    	batteryval8=((batteryval8*GAIN)/1000)+ADC_offset;//????????,?8?
    	battery8val[1]=(char)(batteryval8 >> 8);
    	battery8val[0]=(char)(batteryval8 >> 0);
    	Batteryval[7]=batteryval8;
    
    	shang[16]=battery8val[1];
    	shang[17]=battery8val[0];
    
    	shang1[16]=battery8val[1];
    	shang1[17]=battery8val[0];
    
    	can_buf3[4]=battery8val[1];
    	can_buf3[5]=battery8val[0];
    
    }
    
    
    /****************************************
    fuction: void Get_Battery9(void)
    description:获取第9号单体电池电压
    Parameters:battery9val[0],battery9val[1];
    ******************************************/
    void Get_Battery9(void)
    {
    	char readbattbuf[2];
    	short batteryval9 ;
    	char battery9val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x1c);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x1d);
    
    	batteryval9= readbattbuf[1];
    	batteryval9= (batteryval9 << 8) |readbattbuf[0];
    	batteryval9=((batteryval9*GAIN)/1000)+ADC_offset;//????????,?8?
    	battery9val[1]=(char)(batteryval9 >> 8);
    	battery9val[0]=(char)(batteryval9 & 0x00FF);
    	Batteryval[8]=batteryval9;
    
    	shang[18]=battery9val[1];
    	shang[19]=battery9val[0];
    
    	shang1[18]=battery9val[1];
    	shang1[19]=battery9val[0];
    
    	can_buf3[6]=battery9val[1];
    	can_buf3[7]=battery9val[0];
    
    }
    /****************************************
    fuction: void Get_Battery10(void)
    description:获取第10号单体电池电压
    Parameters:battery10val[0],battery10val[1];
    ******************************************/
    void Get_Battery10(void)
    {
    	char readbattbuf[2];
    	short batteryval10 ;
    	char battery10val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x1e);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x1f);
    
    	batteryval10= readbattbuf[1];
    	batteryval10= (batteryval10 << 8) |readbattbuf[0];
    	batteryval10=((batteryval10*GAIN)/1000)+ADC_offset;//????????,?8?
    	Batteryval[9]=batteryval10;
    	battery10val[1]=(char)(batteryval10 >> 8);
    	battery10val[0]=(char)(batteryval10 & 0x00FF);
    
    	shang[20]=battery10val[1];
    	shang[21]=battery10val[0];
    
    	shang2[2]=battery10val[1];
    	shang2[3]=battery10val[0];
    	can_buf4[2]=battery10val[1];
    	can_buf4[3]=battery10val[0];
    }
    
    /****************************************
    fuction: void Get_Battery10(void)
    description:获取第11号单体电池电压
    Parameters:battery10val[0],battery10val[1];
    ******************************************/
    void Get_Battery11(void)
    {
    	char readbattbuf[2];
    	short batteryval11 ;
    	char battery11val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x20);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x21);
    
    	batteryval11= readbattbuf[1];
    	batteryval11= (batteryval11 << 8) |readbattbuf[0];
    	batteryval11=((batteryval11*GAIN)/1000)+ADC_offset;//????????,?8?
    	Batteryval[10]=batteryval11;
    	battery11val[1]=(char)(batteryval11 >> 8);
    	battery11val[0]=(char)(batteryval11 & 0x00FF);
    
    	shang[22]=battery11val[1];
    	shang[23]=battery11val[0];
    
    	shang2[4]=battery11val[1];
    	shang2[5]=battery11val[0];
    
    	can_buf4[4]=battery11val[1];
    	can_buf4[5]=battery11val[0];
    
    }
    /****************************************
    fuction: void Get_Battery10(void)
    description:获取第12号单体电池电压
    Parameters:battery10val[0],battery10val[1];
    ******************************************/
    void Get_Battery12(void)
    {
    	char readbattbuf[2];
    	short batteryval12 ;
    	char battery12val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x22);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x23);
    
    	batteryval12= readbattbuf[1];
    	batteryval12= (batteryval12 << 8) |readbattbuf[0];
    	batteryval12=((batteryval12*GAIN)/1000)+ADC_offset;//????????,?8?
    	Batteryval[11]=batteryval12;
    	battery12val[1]=(char)(batteryval12 >> 8);
    	battery12val[0]=(char)(batteryval12 & 0x00FF);
    
    	shang[24]=battery12val[1];
    	shang[25]=battery12val[0];
    
    	shang2[6]=battery12val[1];
    	shang2[7]=battery12val[0];
    
    	can_buf4[6]=battery12val[1];
    	can_buf4[7]=battery12val[0];
    
    }
    /****************************************
    fuction: void Get_Battery10(void)
    description:获取第13号单体电池电压
    Parameters:battery10val[0],battery10val[1];
    ******************************************/
    void Get_Battery13(void)
    {
    	char readbattbuf[2];
    	short batteryval13 ;
    	char battery13val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x24);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x25);
    
    	batteryval13= readbattbuf[1];
    	batteryval13= (batteryval13 << 8) |readbattbuf[0];
    	batteryval13=((batteryval13*GAIN)/1000)+ADC_offset;//????????,?8?
    	Batteryval[12]=batteryval13;
    	battery13val[1]=(char)(batteryval13 >> 8);
    	battery13val[0]=(char)(batteryval13 & 0x00FF);
    
    	shang[26]=battery13val[1];
    	shang[27]=battery13val[0];
    
    	shang2[8]=battery13val[1];
    	shang2[9]=battery13val[0];
    
    	can_buf5[2]=battery13val[1];
    	can_buf5[3]=battery13val[0];
    
    }
    /****************************************
    fuction: void Get_Battery10(void)
    description:获取第14号单体电池电压
    Parameters:battery10val[0],battery10val[1];
    ******************************************/
    void Get_Battery14(void)
    {
    	char readbattbuf[2];
    	short batteryval14 ;
    	char battery14val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x26);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x27);
    
    	batteryval14= readbattbuf[1];
    	batteryval14= (batteryval14 << 8) |readbattbuf[0];
    	batteryval14=((batteryval14*GAIN)/1000)+ADC_offset;//????????,?8?
    	Batteryval[13]=batteryval14;
    	battery14val[1]=(char)(batteryval14 >> 8);
    	battery14val[0]=(char)(batteryval14 & 0x00FF);
    
    	shang[28]=battery14val[1];
    	shang[29]=battery14val[0];
    
    	shang2[10]=battery14val[1];
    	shang2[11]=battery14val[0];
    
    	can_buf5[4]=battery14val[1];
    	can_buf5[5]=battery14val[0];
    
    }
    /****************************************
    fuction: void Get_Battery10(void)
    description:获取第15号单体电池电压
    Parameters:battery10val[0],battery10val[1];
    ******************************************/
    void Get_Battery15(void)
    {
    	char readbattbuf[2];
    	short batteryval15 ;
    	char battery15val[2];
    	readbattbuf[1]=BQ_IIC_read_one_byte(0x28);
    	readbattbuf[0]=BQ_IIC_read_one_byte(0x29);
    
    	batteryval15= readbattbuf[1];
    	batteryval15= (batteryval15 << 8) |readbattbuf[0];
    	batteryval15=((batteryval15*GAIN)/1000)+ADC_offset;//????????,?8?
    	Batteryval[14]=batteryval15;
    	battery15val[1]=(char)(batteryval15 >> 8);
    	battery15val[0]=(char)(batteryval15 & 0x00FF);
    
    	shang[30]=battery15val[1];
    	shang[31]=battery15val[0];
    
    	shang2[12]=battery15val[1];
    	shang2[13]=battery15val[0];
    
    	can_buf5[6]=battery15val[1];
    	can_buf5[7]=battery15val[0];
    
    
    }
    
    
    
    /****************************
    获取所有电池的总电压值并用串口1打印出来
     *****************************/
    
    void Get_Update_ALL_Data(void)
    {
    	int i,Sum_val;
    
    	Sum_val= Batteryval[0]+Batteryval[1]+Batteryval[4]+Batteryval[5]+Batteryval[6]+Batteryval[9]+Batteryval[10]+Batteryval[11]+Batteryval[14];
    
    	Batteryval[15] = Sum_val;
    
    	shang[32]=(char)(Batteryval[15] >> 8);
    	shang[33]=(char)(Batteryval[15] &0XFF);
    
    	shang2[14]=(char)shang[32];
    	shang2[15]=(char)shang[33];
    
    	can_buf6[2]=(char)shang[32];
    	can_buf6[3]=(char)shang[33];
    
    }
    
    int SOC;
    void Get_SOC(void)
    {
    	if(Batteryval[15] >(4100*9))
    	{SOC=100;}
    	else if((	Batteryval[15] >(4100*9))&&(Batteryval[15]<(4150*9))){SOC=95;}
    	else if((Batteryval[15]>(4050*9))&&(Batteryval[15]<(4100*9))){SOC=90;}
    	else if((Batteryval[15]>(4000*9))&&(Batteryval[15]<(4050*9))){SOC=88;}
    	else if((Batteryval[15]>(3950*9))&&(Batteryval[15]<(4000*9))){SOC=87;}
    	else if((Batteryval[15]>(3900*9))&&(Batteryval[15]<(3950*9))){SOC=86;}
    	else if((Batteryval[15]>(3900*9))&&(Batteryval[15]<(3950*9))){SOC=85;}
    	else if((Batteryval[15]>(3850*9))&&(Batteryval[15]<(3900*9))){SOC=84;}
    	else if((Batteryval[15]>(3800*9))&&(Batteryval[15]<(3850*9))){SOC=83;}
    	else if((Batteryval[15]>(3750*9))&&(Batteryval[15]<(3800*9))){SOC=82;}
    	else if((Batteryval[15]>(3700*9))&&(Batteryval[15]<(3750*9))){SOC=81;}
    	else if((Batteryval[15]>(3650*9))&&(Batteryval[15]<(3700*9))){SOC=80;}
    	else if((Batteryval[15]>(3600*9))&&(Batteryval[15]<(3650*9))){SOC=79;}
    	else if((Batteryval[15]>(3550*9))&&(Batteryval[15]<(3600*9))){SOC=78;}
    	else if((Batteryval[15]>(3500*9))&&(Batteryval[15]<(3550*9))){SOC=77;}
    
    	else if((Batteryval[15]>(3450*9))&&(Batteryval[15]<(3500*9))){SOC=40;}
    	else if((Batteryval[15]>(3400*9))&&(Batteryval[15]<(3500*9))){SOC=30;}
    	else if((Batteryval[15]>(3300*9))&&(Batteryval[15]<(3400*9))){SOC=20;}
    	else if((Batteryval[15]>(3200*9))&&(Batteryval[15]<(3300*9))){SOC=10;}
    	else if((Batteryval[15]>(3100*9))&&(Batteryval[15]<(3200*9))){SOC=5;}
    	Batteryval[16] = SOC;
    
    	shang[34]=(char)(Batteryval[16] >> 8);
    	shang[35]=(char)(Batteryval[16] &0XFF);
    
    
    	shang2[16]=(char)shang[34];
    	shang2[17]=(char)shang[35];
    
    	can_buf6[4]=(char)shang[34];
    	can_buf6[5]=(char)shang[35];
    
    }
    
    
    //获取所有电池的电压值并用串口打印出来
    
    
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    void OV_UV_1_PROTECT(void)
    {
    	unsigned char OVTrip_Val,UVTrip_Val;
    	float t = 0.377;
    	OVTrip_Val = (unsigned char)((((unsigned int)((OVPThreshold - ADC_offset)/t + 0.5 ) )>>4) &0xFF);
    	UVTrip_Val = (unsigned char)((((unsigned int)((UVPThreshold - ADC_offset)/t + 0.5 ) )>>4) &0xFF);
    	BQ_IIC_write_one_byte_CRC(OV_TRIP,OVTrip_Val);
    	BQ_IIC_write_one_byte_CRC(UV_TRIP,UVTrip_Val);
     }
    
     
    
    void OCD_SCD_PROTECT(void) 
    {
    	BQ_IIC_write_one_byte_CRC(PROTECT1,0x19);//设置短路电流66A(SRN-SRP33mV),短路延时400us,RSNS=0.
    	BQ_IIC_write_one_byte_CRC(PROTECT2,0x7F);//设置OSD为100A(SRN-SRP50mV),延时设置最长为1280ms。
    }
    
    
    /****************************************
    fuction: void BQ_1_config(void)
    description:BQ76930初始化
    Parameters: None
     //0x04寄存器0x19对应SCD延时70uS,放电短路电压33mV;
     //0x05寄存器设置检测电流为1-shot模式;
     //0x06寄存器0x39对应OCD的延时时间80mS,放电过流电压33mV;短路和过流对应电流都是60A.
    ******************************************/
    unsigned char BQ769_INITAdd[12]={SYS_STAT,CELLBAL1,CELLBAL2,CELLBAL3,SYS_CTRL1,SYS_CTRL2,PROTECT1,PROTECT2,PROTECT3,OV_TRIP,UV_TRIP,CC_CFG};
    unsigned char BQ769_INITdata[12]={0xFF,     0x00,    0x00,     0x00,     0x18,    0x40,      0x00,     0x00,    0x00,    0x00,   0x00,  0x19};
    void BQ_1_config(void)
    {
       char i;
       for(i=0;i<12;i++)
        {
    			delay_1ms(10);
    			BQ_IIC_write_one_byte_CRC(BQ769_INITAdd[i],BQ769_INITdata[i]);
        }
    }
    
    /****************************************
    fuction: 均衡的1、2、5、6、7、10分别表示电池组上第1到6节的均衡,
             并且需要注意相邻的电池串不能同时开启均衡。由于均衡的条件不同需要用户根据自己的需求开启。
    description:
    Parameters: None
    ******************************************/
    void Battery1_Balance(void)
    {
       BQ_IIC_write_one_byte_CRC(CELLBAL1,0X01);
    }
    
    void Battery2_Balance(void)
    {
       BQ_IIC_write_one_byte_CRC(CELLBAL1,0X02);
    }
    
    void Battery5_Balance(void)
    {
       BQ_IIC_write_one_byte_CRC(CELLBAL1,0X10);
    }
    
    void Battery6_Balance(void)
    {
       BQ_IIC_write_one_byte_CRC(CELLBAL2,0X01);
    }
    
    void Battery7_Balance(void)
    {
       BQ_IIC_write_one_byte_CRC(CELLBAL2,0X02);
    }
    
    void Battery10_Balance(void)
    {
       BQ_IIC_write_one_byte_CRC(CELLBAL2,0X10);
    }
    
    
    /****************************************
    fuction: void BQ_1_config(void)
    description:BQ76930初始化
    Parameters: None
    ******************************************/
    void BQ_2_config(void)
    {
       char i;
       for(i=0;i<11;i++)
        {
    			delay_1ms(50);
        }
    }
    /****************************************
    fuction:void SHIP_1_BQ769(void)
    description:BQ76930进入低功耗模式
    Parameters: None
    ******************************************/
    void SHIP_1_BQ769(void)
    {
      BQ_IIC_write_one_byte_CRC(SYS_CTRL1,0x19); //01
      delay_1ms(20);
      BQ_IIC_write_one_byte_CRC(SYS_CTRL1,0x1a); //10
     }
    
     
    
    
    /****************************************
    fuction:void SHIP_2_BQ769(void)
    description:从BQ76930低功耗模式唤醒
    Parameters: None
    ******************************************/
    void WAKE_1_BQ769(void)
    {
    	MCU_WAKE_BQ_ONOFF(1);
    	delay_1ms(50);
    	MCU_WAKE_BQ_ONOFF(0);
    	//NVIC_SystemReset();                       //重启
     }
    
     
     /****************************************
    fuction: void Get_BQCurrent(void)
    description:BQ76940电流测量,采样电阻按4mΩ/8计算
    Parameters: None
    ******************************************/
    
     void Get_BQ_Current(void)
     {	 
    	unsigned char readCurrentbuf[2];
    	unsigned int    Currentbufval;
    	float  Currentval;
    	unsigned char Currentbuf[1];
    
    	readCurrentbuf[1]=BQ_IIC_read_one_byte(CC_HI_BYTE);
    	readCurrentbuf[0]=BQ_IIC_read_one_byte(CC_LO_BYTE);
    	Currentbufval = readCurrentbuf[1];
    	Currentbufval = (Currentbufval << 8)|readCurrentbuf[0];
    	if(  Currentbufval <= 0x7D00 )
    	{	 
    		Currentval = (Currentbufval*2.11); //单位mV;按4mΩ/8计算,单位mA;
    		Batteryval[17]=Currentval;
    		shang[36]=Batteryval[17]>>8;
    		shang[37]=Batteryval[17]&0X00FF;
    		shang2[18]=shang[36];
    		shang2[19]=shang[37];
    
    		can_buf6[6]=(char)shang[36];
    		can_buf6[7]=(char)shang[37];
    
    	 
    	}
    	else
    	{		  
    		Currentval = ((0XFFFF - Currentbufval )*2.11);
    		Batteryval[17]=Currentval;
    		shang[36]=Batteryval[17]>>8;
    		shang[37]=Batteryval[17]&0X00FF;
    		shang2[18]=shang[36];
    		shang2[19]=shang[37];		 
    		can_buf6[6]=(char)shang[36];
    		can_buf6[7]=(char)shang[37];
    	 
    	}		 	 
    }
     /****************************************
    fuction: void Get_BQ_1_Temp(void)
    description:BQ76930 103AT温度测量
    Parameters: None
    ******************************************/
    
     float  Tempval_1,Tempval_2,Tempval_3,Tempval_4;
     void Get_BQ1_1_Temp(void)
     {
    	float Rt=0;
    	float Rp=10000;
    	float T2=273.15+25;
    	float Bx=3380;
    	float Ka=273.15;
    	unsigned char readTempbuf[2];
    	int  TempRes;
    	unsigned char Tempbuf[1];
    	readTempbuf[1]=BQ_IIC_read_one_byte(TS1_HI_BYTE);
    	readTempbuf[0]=BQ_IIC_read_one_byte(TS1_LO_BYTE);
    	TempRes = (readTempbuf[1] << 8 ) | readTempbuf[0];
    	TempRes = (10000*(TempRes*382/1000))/(3300-(TempRes*382/1000)); 
    	Tempval_1 = 1/(1/T2+(log(TempRes/Rp))/Bx)- Ka + 0.5;
    	Batteryval[18] = Tempval_1;
       	 	 
     }
    
    
    void Get_BQ1_2_Temp(void)
    {
    	float Rt=0;
    	float Rp=10000;
    	float T2=273.15+25;
    	float Bx=3380;
    	float Ka=273.15;
    	unsigned char readTempbuf[2];
    	int  TempRes;
    	unsigned char Tempbuf[1];
    	readTempbuf[1]=BQ_IIC_read_one_byte(TS2_HI_BYTE);
    	readTempbuf[0]=BQ_IIC_read_one_byte(TS2_LO_BYTE);
    	TempRes = (readTempbuf[1] << 8 ) | readTempbuf[0];
    	TempRes = (10000*(TempRes*382/1000))/(3300-(TempRes*382/1000)); 
    	Tempval_2 = 1/(1/T2+(log(TempRes/Rp))/Bx)- Ka + 0.5;
    	Batteryval[18] = Tempval_2;
    	shang[38]=Batteryval[18];	 	 
    	shang3[2]=shang[38];	 
    	can_buf7[2]=(char)shang[38];
    	printf("Tempval_2 = %f\r\n",Tempval_2);
    }
      
    unsigned char BMS_sta,DSG_STA,CHG_STA,DSG_STA_FLAG,CHG_STA_FLAG;	
    void BMS_STA(void)
    {
    	BMS_sta = BQ_IIC_read_one_byte(SYS_CTRL2);
    	DSG_STA = BMS_sta&0x02;
    	CHG_STA = BMS_sta&0x01;
    	shang[39]=DSG_STA;
    	shang[40]=CHG_STA;
    
    	can_buf7[3]=(char)shang[39];
    	can_buf7[4]=(char)shang[40];
    
    }
     
     void Only_Open_CHG(void)
    {
    	BMS_STA();
    	if(DSG_STA!=0)
    	{
    		BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X43);	
    	}
    	else 
    	{
    		BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X41);
    	}
    }
    	
     void Only_Close_CHG(void)
    {
    	BMS_STA();
    	if(DSG_STA!=0)
    	{
    		BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X42);	
    	}
    	else
    	{
    		BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X40);	
    	}
    }
    	
    void Only_Open_DSG(void)
    {
    	BMS_STA();
    	if(CHG_STA!=0)
    	{
    		BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X43);	
    	}
    	else
    	{
    		BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X42);
    	}	
    }
    void Only_Close_DSG(void)
    {
    	BMS_STA();
    	if(CHG_STA!=0)
    	{
    		BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X41);	
    	}
    	else
    	{
    		BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X40);	
    	}
    }
    	
    void Open_DSG_CHG(void)
    {
    	BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X43);
    
    }
    
    void Close_DSG_CHG(void)
    {
    	BQ_IIC_write_one_byte_CRC(SYS_CTRL2,0X40);	
    }
     
     void Update_val(void)
    {
    	printf("第一节电池电压为:%dmV",Batteryval[0]); 	
    	printf("第二节电池电压为:%dmV",Batteryval[1]); 	
    }
    
    
    
    
    
    
    
     void bsp_bq76940_get_update_data(void)
    {	  
    	Get_Battery1();
    	Get_Battery2();
    //	//Get_Battery3();
    //	// Get_Battery4();
    //	Get_Battery5();
    //	Get_Battery6();
    //	Get_Battery7();
    //	// Get_Battery8();
    //	//Get_Battery9();
    //	Get_Battery10();
    //	Get_Battery11();
    //	Get_Battery12();
    //	//Get_Battery13();
    //	// Get_Battery14();
    //	Get_Battery15(); 	
    //	Get_Update_ALL_Data();//总电压
    //	Get_SOC();
    //	Get_BQ1_2_Temp();
    //	Get_BQ_Current();	
    //	BMS_STA();	
    	Update_val();			
    }
    
     
     
     
     
    /****************************************
    fuction:void readbqstate(void)
    description:读取报警信号值
    Parameters: UV_Alarm_flagOV_Alarm_flag
                SCD_Alarm_flag,OCD_Alarm_flag
    ******************************************/
    
    int UV_Alarm_flag,OV_Alarm_flag,SCD_Alarm_flag,OCD_Alarm_flag;
    void ALERT_1_Recognition(void)
    {
    	unsigned char sys_stat_1,sys_stat_2,UV_1,OV_1,UV_2,OV_2,SCD,OCD;
    	sys_stat_1 = BQ_IIC_read_one_byte(SYS_STAT);//获取状态
    	UV_1  =  sys_stat_1&0x08;  //取出UV位
    	OV_1  =  sys_stat_1&0x04;
    	SCD   =  sys_stat_1&0x02;
    	OCD   =  sys_stat_1&0x01;
    	if((UV_1 == 0x08)||(UV_2 == 0x08))
    	{
    		UV_Alarm_flag = 1;    //欠压报警
    		printf("pack UV\n");
    	}	
    	else
    	UV_Alarm_flag = 0;     //没有欠压
    	if((OV_1 == 0x04)||(OV_2 == 0x04))
    	{
    		OV_Alarm_flag = 1;			 
    		printf("pack OV\n");
    	}
            else
               OV_Alarm_flag = 0;
               if(SCD == 0x02)
    			{
    				SCD_Alarm_flag = 1;
    				printf("pack SCD\n");		
    			}
    				else
    						SCD_Alarm_flag = 0;
    
    						if(OCD == 0x01)
    							{
    								OCD_Alarm_flag = 1;
    								printf("pack OCD\n");		
    							}   
    								else
    										OCD_Alarm_flag = 0;	
    }
    
    
    /******************************************Code End*************************************************/
    
    // CRC8校验计算:X8 + X2 + X + 1   
    //ptr:字节数据的指针
    //len:字节数量
    //key = 7
    unsigned char IIC_CRC8(unsigned char *ptr, unsigned char len,unsigned char key)
    {
    	unsigned char i;
    	unsigned char crc=0;
    	while(len--!=0)
    	{
    		for(i=0x80; i!=0; i/=2)
    		{
    			if((crc & 0x80) != 0)
    			{
    				crc *= 2;
    				crc ^= key;
    			}
    			else
    				crc *= 2;
    
    			if((*ptr & i)!=0)
    				crc ^= key;
    		}
    		ptr++;
    	}
    	return(crc);
    }
    
    //BQ76940.h
    #ifndef _BSP_BQ76940_H_
    #define _BSP_BQ76940_H_
    
    
    #include "gd32f10x.h"
    #include <stdio.h>
    /**************************************************************************************/
    #define SYS_STAT 0x00
    #define CELLBAL1 0x01
    #define CELLBAL2 0x02
    #define CELLBAL3 0x03
    #define SYS_CTRL1 0x04
    #define SYS_CTRL2 0x05
    #define PROTECT1 0x06
    #define PROTECT2 0x07
    #define PROTECT3 0x08
    #define OV_TRIP 0x09
    #define UV_TRIP 0x0A
    #define CC_CFG  0x0B
    
    #define OVPThreshold     4400  // 3150-4700
    #define OV_Re_Threshold  4300
    
    #define UVPThreshold  2400 //  1580-3100
    #define UV_Re_Threshold  2500
    
    #define OTPThreshold  60 //  
    #define UTPThreshold  -20 //
    #define TempPThreshold -50
    
    #define VC1_HI_BYTE 0x0C
    #define VC1_LO_BYTE 0x0D
    
    #define VC2_HI_BYTE 0x0E
    #define VC2_LO_BYTE 0x0F
    
    #define VC3_HI_BYTE 0x10
    #define VC3_LO_BYTE 0x11
    
    #define VC4_HI_BYTE 0x12
    #define VC4_LO_BYTE 0x13
    
    #define VC5_HI_BYTE 0x14
    #define VC5_LO_BYTE 0x15
    
    #define VC6_HI_BYTE 0x16
    #define VC6_LO_BYTE 0x17
    
    #define VC7_HI_BYTE 0x18
    #define VC7_LO_BYTE 0x19
    
    #define VC8_HI_BYTE 0x1A
    #define VC8_LO_BYTE 0x1B
    
    #define VC9_HI_BYTE 0x1C
    #define VC9_LO_BYTE 0x1D
    
    #define VC10_HI_BYTE 0x1E
    #define VC10_LO_BYTE 0x1F
    
    #define BAT_HI_BYTE 0x2A
    #define BAT_LO_BYTE 0x2B
    
    #define TS1_HI_BYTE 0x2C
    #define TS1_LO_BYTE 0x2D
    
    #define TS2_HI_BYTE 0x2E
    #define TS2_LO_BYTE 0x2F
    
    #define CC_HI_BYTE 0x32
    #define CC_LO_BYTE 0x33
    
    #define ADCGAIN1 0x50
    #define ADCOFFSET 0x51
    #define ADCGAIN2 0x59
    
    #define SCD_DELAY_50us		0x0
    #define SCD_DELAY_100us		0x1
    #define SCD_DEALY_200us		0x2
    #define SCD_DELAY_400us		0x3
    
    #define SCD_THRESH_44mV_22mV	0
    #define SCD_THRESH_67mV_33mV	1
    #define SCD_THRESH_89mV_44mV	2
    #define SCD_THRESH_111mV_56mV	3
    #define SCD_THRESH_133mV_67mV	4
    #define SCD_TRHESH_155mV_68mV	5
    #define SCD_THRESH_178mV_89mV	6
    #define SCD_THRESH_200mV_100mV	7
    
    #define OCD_DEALY_10ms		0x0
    #define OCD_DELAY_20ms		0x1
    #define OCD_DELAY_40ms		0x2
    #define OCD_DELAY_80ms		0x3
    #define OCD_DELAY_160ms		0x4
    #define OCD_DELAY_320ms		0x5
    #define OCD_DELAY_640ms		0x6
    #define OCD_DELAY_1280ms	0x7
    
    #define OCD_THRESH_17mV_8mV		0
    #define OCD_THRESH_22mV_11mV	1
    #define OCD_THRESH_28mV_14mV	2
    #define OCD_THRESH_33mV_17mV	3
    #define OCD_THRESH_39mV_19mV	4
    #define OCD_THRESH_44mV_22mV	5
    #define OCD_THRESH_50mV_25mV	6
    #define OCD_THRESH_56mV_28MV	7
    #define OCD_THRESH_61mV_31mV	8
    #define OCD_THRESH_67mV_33mV	9
    #define OCD_THRESH_72mV_36mV	0xA
    #define OCD_THRESH_78mV_39mV	0xB
    #define OCD_THRESH_83mV_42mV	0xC
    #define OCD_THRESH_89mV_44mV	0xD
    #define OCD_THRESH_94mV_47mV	0xE
    #define OCD_THRESH_100mV_50mV	0xF
    
    #define UV_DELAY_1s				0
    #define UV_DELAY_4s				1
    #define UV_DELAY_8s				2
    #define UV_DELAY_16s			3
    
    #define OV_DELAY_1s				0
    #define OV_DELAY_2s				1
    #define OV_DELAY_4s				2
    #define OV_DELAY_8s				3
    
    #define OV_THRESH_BASE			0x2008
    #define UV_THRESH_BASE			0x1000
    #define OV_STEP					0x10
    #define UV_STEP					0x10
    
    #define ADCGAIN_BASE			365
    
    #define LOW_BYTE(Data)			(unsigned char)(0xff & Data)
    #define HIGH_BYTE(Data)			(unsigned char)(0xff & (Data >> 8))
    
    
    
    
    
    extern unsigned char can_buf1[8];
    extern unsigned char can_buf2[8];
    extern unsigned char can_buf3[8];
    extern unsigned char can_buf4[8];
    extern unsigned char can_buf5[8];
    extern unsigned char can_buf6[8];
    extern unsigned char can_buf7[8];
    
    extern uint16_t g_iCell1mVolt;
    extern uint16_t g_iCell2mVolt;
    extern uint16_t g_iCell3mVolt;
    extern uint16_t g_iCell4mVolt;
    extern uint16_t g_iCell5mVolt;
    extern uint16_t g_iCell6mVolt;
    extern uint16_t g_iCell7mVolt;
    extern uint16_t g_iCell8mVolt;
    extern uint16_t g_iCell9mVolt;
    extern uint16_t g_iCell10mVolt;
    extern uint16_t g_iCell11mVolt;
    extern uint16_t g_iCell12mVolt;
    extern uint16_t g_iCell13mVolt;
    extern uint16_t g_iCell14mVolt;
    extern uint16_t g_iCell15mVolt;
    extern uint16_t g_iPackVolt;
    extern uint16_t g_iPackCurrent;
    extern uint16_t g_iTemp1;
    extern uint16_t g_iTemp2;
    extern uint16_t g_iTemp3;
    extern uint16_t g_iTemp4;
    extern uint16_t g_iTemp5;
    extern uint16_t g_iTemp6;
    extern uint16_t g_iSoc;
    
    
    
    
    void Get_offset(void);
    void Get_Battery1(void);
    void Get_Battery2(void);
    void Get_Battery3(void);
    void Get_Battery4(void);
    void Get_Battery5(void);
    void Get_Battery6(void);
    void Get_Battery7(void);
    void Get_Battery8(void);
    void Get_Battery9(void);
    void Get_Battery10(void);
    void Get_Battery11(void);
    void Get_Battery12(void);
    void Get_Battery13(void);
    void Get_Battery14(void);
    void Get_Battery15(void);
    void Get_Battery16(void);
    void Get_Battery17(void);
    void Get_Battery18(void);
    void Get_Battery19(void);
    void Get_Battery20(void);
    void Get_Update_Data(void);
    void OV_UV_1_PROTECT(void);
    void BQ_1_config(void);
    void SHIP_1_BQ769(void);
    void ALERT_1_Recognition(void );
    void Temp_ALERT(void);
    void Get_BQ_Current(void);
    void Get_BQ1_1_Temp(void);
    void Get_BQ1_2_Temp(void);
    void Get_BQ2_1_Temp(void);
    void Get_BQ2_2_Temp(void);
    void BMS_STA(void);
    unsigned char CRC8(unsigned char *ptr, unsigned char len,unsigned char key);
    
    
    void OV_UV_2_PROTECT(void);
    void BQ_2_config(void);
    void SHIP_2_BQ769(void);
    void ALERT_2_Recognition(void );
    void SHIP_2_BQ769(void);
    void BQ76940_config(void);
    void Get_Update_ALL_BAT(void);
    void BQ_1_2_config(void);
    void OV_UV_1_2_PROTECT(void);
    void WAKE_ALL_DEVICE(void);
    void Only_Open_CHG(void);
    void Only_Close_CHG(void);
    void Only_Open_DSG(void);
    void Only_Close_DSG(void);
    void Open_DSG_CHG(void);
    void Close_DSG_CHG(void);
    void OCD_SCD_PROTECT(void);
    void SHIP_ALL_DEVICE(void);
    void Led_Alarm(void);
    void Get_SOC(void);
     void bsp_bq76940_get_update_data(void);
    
    
    
    
    /**************************************************************************************/
    
    /*
    typedef struct _Register_Group
    {
    	union
    	{
    		struct
    		{
    			unsigned char OCD			:1;
    			unsigned char SCD			:1;
    			unsigned char OV			:1;
    			unsigned char UV			:1;
    			unsigned char OVRD_ALERT	:1;
    			unsigned char DEVICE_XREADY	:1;
    			unsigned char WAKE			:1;
    			unsigned char CC_READY		:1;
    		}StatusBit;
    		unsigned char StatusByte;
    	}SysStatus;
    
    	union
    	{
    		struct
    		{
    			unsigned char RSVD			:3;
    			unsigned char CB5			:1;
    			unsigned char CB4			:1;
    			unsigned char CB3			:1;
    			unsigned char CB2			:1;
    			unsigned char CB1			:1;
    		}CellBal1Bit;
    		unsigned char CellBal1Byte;
    	}CellBal1;
    
    	union
    	{
    		struct
    		{
    			unsigned char RSVD			:3;
    			unsigned char CB10			:1;
    			unsigned char CB9			:1;
    			unsigned char CB8			:1;
    			unsigned char CB7			:1;
    			unsigned char CB6			:1;
    		}CellBal2Bit;
    		unsigned char CellBal2Byte;
    	}CellBal2;
    
    	union
    	{
    		struct
    		{
    			unsigned char RSVD			:3;
    			unsigned char CB15			:1;
    			unsigned char CB14			:1;
    			unsigned char CB13			:1;
    			unsigned char CB12			:1;
    			unsigned char CB11			:1;
    		}CellBal3Bit;
    		unsigned char CellBal3Byte;
    	}CellBal3;
    
    	union
    	{
    		struct
    		{
    			unsigned char SHUT_B		:1;
    			unsigned char SHUT_A		:1;
    			unsigned char RSVD1			:1;
    			unsigned char TEMP_SEL		:1;
    			unsigned char ADC_EN		:1;
    			unsigned char RSVD2			:2;
    			unsigned char LOAD_PRESENT	:1;
    		}SysCtrl1Bit;
    		unsigned char SysCtrl1Byte;
    	}SysCtrl1;
    
    	union
    	{
    		struct
    		{
    			unsigned char CHG_ON		:1;
    			unsigned char DSG_ON		:1;
    			unsigned char WAKE_T		:2;
    			unsigned char WAKE_EN		:1;
    			unsigned char CC_ONESHOT	:1;
    			unsigned char CC_EN			:1;
    			unsigned char DELAY_DIS		:1;
    		}SysCtrl2Bit;
    		unsigned char SysCtrl2Byte;
    	}SysCtrl2;
    
    	union
    	{
    		struct
    		{
    			unsigned char SCD_THRESH	:3;
    			unsigned char SCD_DELAY		:2;
    			unsigned char RSVD			:2;
    			unsigned char RSNS			:1;
    		}Protect1Bit;
    		unsigned char Protect1Byte;
    	}Protect1;
    
    	union
    	{
    		struct
    		{
    			unsigned char OCD_THRESH	:4;
    			unsigned char OCD_DELAY		:3;
    			unsigned char RSVD			:1;
    		}Protect2Bit;
    		unsigned char Protect2Byte;
    	}Protect2;
    
    	union
    	{
    		struct
    		{
    			unsigned char RSVD			:4;
    			unsigned char OV_DELAY		:2;
    			unsigned char UV_DELAY		:2;
    		}Protect3Bit;
    		unsigned char Protect3Byte;
    	}Protect3;
    
    	unsigned char OVTrip;
    	unsigned char UVTrip;
    	unsigned char CCCfg;			//must be 0x19
    
    	union
    	{
    		struct
    		{
    			unsigned char VC1_HI;
    			unsigned char VC1_LO;
    		}VCell1Byte;
    		unsigned short VCell1Word;
    	}VCell1;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC2_HI;
    			unsigned char VC2_LO;
    		}VCell2Byte;
    		unsigned short VCell2Word;
    	}VCell2;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC3_HI;
    			unsigned char VC3_LO;
    		}VCell3Byte;
    		unsigned short VCell3Word;
    	}VCell3;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC4_HI;
    			unsigned char VC4_LO;
    		}VCell4Byte;
    		unsigned short VCell4Word;
    	}VCell4;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC5_HI;
    			unsigned char VC5_LO;
    		}VCell5Byte;
    		unsigned short VCell5Word;
    	}VCell5;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC6_HI;
    			unsigned char VC6_LO;
    		}VCell6Byte;
    		unsigned short VCell6Word;
    	}VCell6;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC7_HI;
    			unsigned char VC7_LO;
    		}VCell7Byte;
    		unsigned short VCell7Word;
    	}VCell7;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC8_HI;
    			unsigned char VC8_LO;
    		}VCell8Byte;
    		unsigned short VCell8Word;
    	}VCell8;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC9_HI;
    			unsigned char VC9_LO;
    		}VCell9Byte;
    		unsigned short VCell9Word;
    	}VCell9;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC10_HI;
    			unsigned char VC10_LO;
    		}VCell10Byte;
    		unsigned short VCell10Word;
    	}VCell10;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC11_HI;
    			unsigned char VC11_LO;
    		}VCell11Byte;
    		unsigned short VCell11Word;
    	}VCell11;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC12_HI;
    			unsigned char VC12_LO;
    		}VCell12Byte;
    		unsigned short VCell12Word;
    	}VCell12;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC13_HI;
    			unsigned char VC13_LO;
    		}VCell13Byte;
    		unsigned short VCell13Word;
    	}VCell13;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC14_HI;
    			unsigned char VC14_LO;
    		}VCell14Byte;
    		unsigned short VCell14Word;
    	}VCell14;
    
    	union
    	{
    		struct
    		{
    			unsigned char VC15_HI;
    			unsigned char VC15_LO;
    		}VCell15Byte;
    		unsigned short VCell15Word;
    	}VCell15;
    
    	union
    	{
    		struct
    		{
    			unsigned char BAT_HI;
    			unsigned char BAT_LO;
    		}VBatByte;
    		unsigned short VBatWord;
    	}VBat;
    
    	union
    	{
    		struct
    		{
    			unsigned char TS1_HI;
    			unsigned char TS1_LO;
    		}TS1Byte;
    		unsigned short TS1Word;
    	}TS1;
    
    	union
    	{
    		struct
    		{
    			unsigned char TS2_HI;
    			unsigned char TS2_LO;
    		}TS2Byte;
    		unsigned short TS2Word;
    	}TS2;
    
    	union
    	{
    		struct
    		{
    			unsigned char TS3_HI;
    			unsigned char TS3_LO;
    		}TS3Byte;
    		unsigned short TS3Word;
    	}TS3;
    
    	union
    	{
    		struct
    		{
    			unsigned char CC_HI;
    			unsigned char CC_LO;
    		}CCByte;
    		unsigned short CCWord;
    	}CC;
    
    	union
    	{
    		struct
    		{
    			unsigned char RSVD1			:2;
    			unsigned char ADCGAIN_4_3	:2;
    			unsigned char RSVD2			:4;
    		}ADCGain1Bit;
    		unsigned char ADCGain1Byte;
    	}ADCGain1;
    
    	unsigned char ADCOffset;
    
    	union
    	{
    		struct
    		{
    			unsigned char RSVD			:5;
    			unsigned char ADCGAIN_2_0	:3;
    		}ADCGain2Bit;
    		unsigned char ADCGain2Byte;
    	}ADCGain2;
    
    }RegisterGroup;
    
    
    typedef enum
    {
      HAL_OK       = 0x00U,
      HAL_ERROR    = 0x01U,
      HAL_BUSY     = 0x02U,
      HAL_TIMEOUT  = 0x03U
    } HAL_StatusTypeDef;
    
    //ALERT
    #define AFEBoot_GPIO_Port	GPIOC
    #define AFEBoot_Pin			GPIO_PIN_4		
    
    
    
    
    #define BQ76940_ADDRESS		0x08
    
    #define BQMAXIMO 0x08
    
    #define LOWBYTE(Data) (unsigned char)(0x00ff & Data)
    
    #define HIGHBYTE(Data) (unsigned char)((0xff00 & Data)>>8)
    
    #define CRC_KEY 7
    
    #define DELAY_LIMIT 0xffff
    
    #define SYS_STAT 0
    #define CELLBAL1 1
    #define CELLBAL2 2
    #define CELLBAL3 3
    #define SYS_CTRL1 4
    #define SYS_CTRL2 5
    #define PROTECT1 0x06
    #define PROTECT2 0x07
    #define PROTECT3 0x08
    #define OV_TRIP 0x09
    #define UV_TRIP 0x0A
    #define VC1_HI_BYTE 0x0C
    #define CC_HI_BYTE	0x32
    #define BAT_HI_BYTE	0x2A
    #define TS1_HI_BYTE	0x2C
    #define TS2_HI_BYTE	0x2E
    
    #define ADCGAIN1 0x50
    #define ADCOFFSET 0x51
    #define ADCGAIN2 0x59
    
    #define SCD_DELAY_50us		0x0
    #define SCD_DELAY_100us		0x1
    #define SCD_DEALY_200us		0x2
    #define SCD_DELAY_400us		0x3
    
    #define SCD_THRESH_44mV_22mV	0
    #define SCD_THRESH_67mV_33mV	1
    #define SCD_THRESH_89mV_44mV	2
    #define SCD_THRESH_111mV_56mV	3
    #define SCD_THRESH_133mV_67mV	4
    #define SCD_TRHESH_155mV_68mV	5
    #define SCD_THRESH_178mV_89mV	6
    #define SCD_THRESH_200mV_100mV	7
    
    #define OCD_DEALY_10ms		0x0
    #define OCD_DELAY_20ms		0x1
    #define OCD_DELAY_40ms		0x2
    #define OCD_DELAY_80ms		0x3
    #define OCD_DELAY_160ms		0x4
    #define OCD_DELAY_320ms		0x5
    #define OCD_DELAY_640ms		0x6
    #define OCD_DELAY_1280ms	0x7
    
    #define OCD_THRESH_17mV_8mV		0
    #define OCD_THRESH_22mV_11mV	1
    #define OCD_THRESH_28mV_14mV	2
    #define OCD_THRESH_33mV_17mV	3
    #define OCD_THRESH_39mV_19mV	4
    #define OCD_THRESH_44mV_22mV	5
    #define OCD_THRESH_50mV_25mV	6
    #define OCD_THRESH_56mV_28MV	7
    #define OCD_THRESH_61mV_31mV	8
    #define OCD_THRESH_67mV_33mV	9
    #define OCD_THRESH_72mV_36mV	0xA
    #define OCD_THRESH_78mV_39mV	0xB
    #define OCD_THRESH_83mV_42mV	0xC
    #define OCD_THRESH_89mV_44mV	0xD
    #define OCD_THRESH_94mV_47mV	0xE
    #define OCD_THRESH_100mV_50mV	0xF
    
    #define UV_DELAY_1s				0
    #define UV_DELAY_4s				1
    #define UV_DELAY_8s				2
    #define UV_DELAY_16s			3
    
    #define OV_DELAY_1s				0
    #define OV_DELAY_2s				1
    #define OV_DELAY_4s				2
    #define OV_DELAY_8s				3
    
    #define OV_THRESH_BASE			0x2008
    #define UV_THRESH_BASE			0x1000
    #define OV_STEP					0x10
    #define UV_STEP					0x10
    
    #define ADCGAIN_BASE			365
    
    #define LOW_BYTE(Data)			(unsigned char)(0xff & Data)
    #define HIGH_BYTE(Data)			(unsigned char)(0xff & (Data >> 8))
    
    #define IIC_TIME_OUT	10
    */
    
    extern unsigned char IIC_CRC8(unsigned char *ptr, unsigned char len,unsigned char key);
    
    
    #endif
    Please give some suggestions.
    Thanks
    Star
  • Hi Star,

    Check that the CAP1 has a voltage, should be nominal 3.3V.

    Also check that the part is not a BQ7694006 which would be address 0x18, 0x30 on the bus.

    Check the clock frequency and for edge disturbances on the bus.  The digital seems to check fine on the analyzer, but be sure the signal is slow enough for the IC