[local]1[/local]最近在用一个电源管理芯片BQ7693003,然后STM32F107在和它通信时,总是收不到应答,大神求助!我用的是模拟I2C,可以和24C02进行读写,和BQ7693003就不行了。
[local]1[/local]
/* defines ——————————————————————*/
#define I2C_PageSize 256
#define I2C1_SLAVE_ADDRESS7_W 0x10
#define I2C1_SLAVE_ADDRESS7_R 0x11
#define FALSE 0
#define TRUE 1
#define SDA_PORT GPIOB
#define SCL_PORT GPIOB
#define SDA_PIN GPIO_Pin_7
#define SCL_PIN GPIO_Pin_6
#define SCL_H GPIOB->BSRR = GPIO_Pin_6
#define SCL_L GPIOB->BRR = GPIO_Pin_6
#define SDA_H GPIOB->BSRR = GPIO_Pin_7
#define SDA_L GPIOB->BRR = GPIO_Pin_7
#define SCL_read GPIOB->IDR & GPIO_Pin_6
#define SDA_read GPIOB->IDR & GPIO_Pin_7
/*******************************************************************************
* File Name : SI2C.c
* Author : zhang
* Version : V1.0.0
* Date : 2011.12.08
*******************************************************************************/
#include "I2C.h"
#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "main.h"
vu8 FRAM_ADDRESS;
/* function ——————————————————————*/
/*******************************************************************************
* Function Name : I2CInit
* Description : I2CInit
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void I2CInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//SDA
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//SCL
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
SCL_H;
SDA_H;
}
/*******************************************************************************
* Function Name : I2C_delay
* Description : I2C_delay
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void I2C_delay(void)
{
//u8 i=200;
//while(i)
//{
// i–;
//}
Delay_us(10);
}
/*******************************************************************************
* Function Name : I2C_Start
* Description : I2C_Start
* Input : None
* Output : None
* Return : None
*******************************************************************************/
u8 I2C_Start(void)
{
SDA_H;
SCL_H;
I2C_delay();
if(!SDA_read)return FALSE;
SDA_L;
I2C_delay();
if(SDA_read) return FALSE;
SCL_L;
I2C_delay();
return TRUE;
}
/*******************************************************************************
* Function Name : I2C_Stop
* Description : I2C_Stop
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void I2C_Stop(void)
{
SCL_L;
I2C_delay();
SDA_L;
I2C_delay();
SCL_H;
I2C_delay();
SDA_H;
I2C_delay();
}
/*******************************************************************************
* Function Name : I2C_Ack
* Description : I2C_Ack
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void I2C_Ack(void)
{
SCL_L;
I2C_delay();
SDA_L;
I2C_delay();
SCL_H;
I2C_delay();
SCL_L;
I2C_delay();
}
/*******************************************************************************
* Function Name : I2C_NoAck
* Description : I2C_NoAck
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void I2C_NoAck(void)
{
SCL_L;
I2C_delay();
SDA_H;
I2C_delay();
SCL_H;
I2C_delay();
SCL_L;
I2C_delay();
}
/*******************************************************************************
* Function Name : I2C_WaitAck
* Description : I2C_WaitAck
* Input : None
* Output : None
* Return : TRUE/FALSE
*******************************************************************************/
u8 I2C_WaitAck(void)
{
SCL_L;
I2C_delay();
SDA_H;
I2C_delay();
SCL_H;
I2C_delay();
if(SDA_read)
{
SCL_L;
return FALSE;
}
SCL_L;
return TRUE;
}
/*******************************************************************************
* Function Name : I2C_SendByte
* Description : I2C_SendByte
* Input : SendByte
* Output : None
* Return : None
*******************************************************************************/
void I2C_SendByte(u8 SendByte)
{
u8 i=8;
while(i–)
{
SCL_L;
I2C_delay();
if(SendByte&0x80)
SDA_H;
else
SDA_L;
SendByte<<=1;
I2C_delay();
SCL_H;
I2C_delay();
}
SCL_L;
}
/*******************************************************************************
* Function Name : I2C_ReceiveByte
* Description : I2C_ReceiveByte
* Input : None
* Output : None
* Return : ReceiveByte
*******************************************************************************/
u8 I2C_ReceiveByte(void)
{
u8 i=8;
u8 ReceiveByte=0;
SDA_H;
while(i–)
{
ReceiveByte<<=1;
SCL_L;
I2C_delay();
SCL_H;
I2C_delay();
if(SDA_read)
{
ReceiveByte|=0x01;
}
}
SCL_L;
return ReceiveByte;
}
/*******************************************************************************
* Function Name : I2C_FRAM_BufferWrite
* Description : I2C_FRAM_BufferWrite
* Input :
* Output : None
* Return : None
*******************************************************************************/
u8 I2C_FRAM_BufferWrite(u8* pBuffer, u16 WriteAddr, u16 NumByteToWrite)
{
u8 Addr = 0, count = 0;
Addr = (WriteAddr) / I2C_PageSize;
count = (WriteAddr) % I2C_PageSize;
Addr = Addr << 1;
Addr = Addr & 0x0F;
FRAM_ADDRESS = I2C1_SLAVE_ADDRESS7_W | Addr;
if (!I2C_Start())
return FALSE;
I2C_SendByte(FRAM_ADDRESS);
if (!I2C_WaitAck())
{
I2C_Stop(); //在这结束,无应答
return FALSE;
}
I2C_SendByte(count);
I2C_WaitAck();
while(NumByteToWrite–)
{
I2C_SendByte(* pBuffer);
I2C_WaitAck();
pBuffer++;
}
I2C_Stop();
return TRUE;
}
/*******************************************************************************
* Function Name : I2C_FRAM_BufferRead
* Description : I2C_FRAM_BufferRead
* Input :
* Output : None
* Return : None
*******************************************************************************/
u8 I2C_FRAM_BufferRead(u8* pBuffer, u16 WriteAddr, u16 NumByteToRead)
{
u8 Addr = 0, count = 0;
Addr = WriteAddr / I2C_PageSize;
count = WriteAddr % I2C_PageSize;
Addr = Addr << 1;
Addr = Addr & 0x0F;
FRAM_ADDRESS = I2C1_SLAVE_ADDRESS7_R | Addr;
if (!I2C_Start()) return FALSE;
I2C_SendByte(FRAM_ADDRESS);
if (!I2C_WaitAck())
{
I2C_Stop();
return FALSE;
}
I2C_SendByte(count);
I2C_WaitAck();
I2C_Start();
I2C_SendByte(FRAM_ADDRESS | 0x01);
I2C_WaitAck();
while(NumByteToRead)
{
*pBuffer = I2C_ReceiveByte();
if(NumByteToRead == 1)I2C_NoAck();
else I2C_Ack();
pBuffer++;
NumByteToRead–;
}
I2C_Stop();
return TRUE;
}
void main(void)
{
u8 BQ769_INITAdd[11] ={0x00,0x01,0x02,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b};
u8 BQ769_INITdata[11]={0x08,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0xAC,0x97,0x19};
u8 BQ769_RegAdd[12] ={0x0c,0x0d,0x0e,0x0f,0x51};
u8 BQ769_Voltage[12] ={0};
bsp_init();
I2CInit();
I2C_FRAM_BufferWrite(BQ769_INITdata,BQ769_INITAdd[0],12);
while(1)
{
I2C_FRAM_BufferRead(BQ769_Voltage,BQ769_RegAdd[0],10);
Delay_us(500);
}
}
Hugo Zhang:
BQ7693003跟电池接上后,默认处于shutdown模式,需要唤醒。可通过REGOUT和CAP1 pin上是否有电压开判断。
另外,关于BQ7693003的I2C通讯,地址是0x08,带CRC校验。
yu liang3:
回复 Hugo Zhang:
谢谢,等会我试试,地址是0x08,不是要左移一位,然后变成0x10发送么
Cheng.W:
回复 yu liang3:
不用左移,0000, 1000是写地址,0000,1001,是读地址
ning wang9:
回复 Cheng.W:
/* BQ76930 communication */#define BQ769x0_IIC_PORT GPIOA#define BQ769x0_IIC_SCL_PIN GPIO_Pin_9#define BQ769x0_IIC_SDA_PIN GPIO_Pin_10
//IO方向设置#define BQ769x0_IIC_SDA_IN() (GPIOA->MODER&=0xFFCFFFFF)#define BQ769x0_IIC_SDA_OUT() (GPIOA->MODER|=0x00100000)
//IO操作函数#define BQ769x0_IIC_SCL_H (GPIOA->BSRR=GPIO_Pin_9) //输出SCL H#define BQ769x0_IIC_SCL_L (GPIOA->BRR=GPIO_Pin_9) //输出SCL L
#define BQ769x0_IIC_SDA_H (GPIOA->BSRR=GPIO_Pin_10) //输出SDA H#define BQ769x0_IIC_SDA_L (GPIOA->BRR=GPIO_Pin_10) //输出SDA L #define BQ769x0_IIC_READ_SDA() ((GPIOA->IDR>>0x0a)&0x01) //输入SDA
#define BQ769x0_IIC_DELAY_US 0x05 //iic 时钟延时5us,100Khz#define BQ769x0_IIC_ACK_TIME_OUT 0xFF //ACK超时 约80us
/* crc_val KEY */#define CRC_KEY 7/* slave adrr */#define BQ769X0_SLAVE_ADDR 0x08/* command bit */#define BQ_CMD_READ 0x01#define BQ_CMD_WRITE 0x00
/* bq register num */#define BQ769X0_REGISTER_NUM 0x40
//初始化IICstatic void HalBq769x0IIC_Init(void){ GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = BQ769x0_IIC_SCL_PIN | BQ769x0_IIC_SDA_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT ; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(BQ769x0_IIC_PORT, &GPIO_InitStructure);
BQ769x0_IIC_SCL_H; BQ769x0_IIC_SDA_H;}//产生IIC起始信号static void HalBq769x0IIC_Start(void){ BQ769x0_IIC_SDA_OUT(); //sda线输出 BQ769x0_IIC_SCL_H; BQ769x0_IIC_SDA_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SDA_L; //START:when CLK is high,DATA change form high to low HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_L; //钳住I2C总线,准备发送或接收数据}//产生IIC停止信号static void HalBq769x0IIC_Stop(void){ BQ769x0_IIC_SDA_OUT();//sda线输出 BQ769x0_IIC_SCL_L; BQ769x0_IIC_SDA_L; //STOP:when CLK is high DATA change form low to high HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SDA_H; //发送I2C总线结束信号 HalNormalDelayUs(BQ769x0_IIC_DELAY_US);}//等待应答信号到来//返回值:1,接收应答失败// 0,接收应答成功static uint8_t HalBq769x0IIC_Wait_Ack(void){ uint32_t ucErrTime = 0; BQ769x0_IIC_SDA_IN(); //SDA设置为输入 HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); while(BQ769x0_IIC_READ_SDA()) { ucErrTime++; if(ucErrTime > BQ769x0_IIC_ACK_TIME_OUT) { SysLog("BQ769x0_IIC_ACK_TIME_OUT"); HalBq769x0IIC_Stop(); return 1; } }
BQ769x0_IIC_SCL_L; //时钟输出L return 0;}//产生ACK应答static void HalBq769x0IIC_Ack(void){ BQ769x0_IIC_SCL_L; BQ769x0_IIC_SDA_OUT(); BQ769x0_IIC_SDA_L; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_L;}
//不产生ACK应答static void HalBq769x0IIC_NAck(void){ BQ769x0_IIC_SCL_L; BQ769x0_IIC_SDA_OUT(); BQ769x0_IIC_SDA_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_L;}//IIC发送一个字节//返回从机有无应答//1,有应答//0,无应答static void HalBq769x0IIC_Send_Byte(uint8_t txd){ uint8_t t; BQ769x0_IIC_SDA_OUT(); BQ769x0_IIC_SCL_L; //拉低时钟开始数据传输 for(t = 0; t < 8; t++) { if(txd & 0x80) { BQ769x0_IIC_SDA_H; } else { BQ769x0_IIC_SDA_L; } txd <<= 1; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_L; } BQ769x0_IIC_SDA_IN();}//读1个字节,ack=1时,发送ACK,ack=0,发送nACKstatic uint8_t HalBq769x0IIC_Read_Byte(uint8_t ack){ uint8_t i, receive = 0; BQ769x0_IIC_SDA_IN();//SDA设置为输入 for(i = 0; i < 8; i++ ) { BQ769x0_IIC_SCL_L; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_H; receive <<= 1; if(BQ769x0_IIC_READ_SDA()) { receive++; } HalNormalDelayUs(BQ769x0_IIC_DELAY_US); } if (!ack) { HalBq769x0IIC_NAck(); //发送nACK } else { HalBq769x0IIC_Ack(); //发送ACK } return receive;}
//初始化IIC接口void HalBq769x0IIC_SoftReset(void){ uint32_t i; //start BQ769x0_IIC_SCL_H; BQ769x0_IIC_SDA_H;
HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SDA_L; //START:when CLK is high,DATA change form high to low HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_L; //钳住I2C总线,准备发送或接收数据
HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SDA_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US);
for(i = 0; i < 9; i++) { BQ769x0_IIC_SCL_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_L; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); }
BQ769x0_IIC_SCL_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SDA_L; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_L; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SCL_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US); BQ769x0_IIC_SDA_H; HalNormalDelayUs(BQ769x0_IIC_DELAY_US);}
/* */static int8_t HalBq769x0I2CSendBytes(uint8_t *DataBuffer, uint16_t ByteCount){ uint16_t i; uint8_t slave_addr = BQ769X0_SLAVE_ADDR << 1;
HalBq769x0IIC_Start(); HalBq769x0IIC_Send_Byte(slave_addr | BQ_CMD_WRITE); HalBq769x0IIC_Wait_Ack();
for(i = 0; i < ByteCount; i++) { HalBq769x0IIC_Send_Byte(DataBuffer[i]); HalBq769x0IIC_Wait_Ack(); }
HalBq769x0IIC_Stop();
return 0x00;}
static int8_t HalBq769x0I2CReadBytes(uint8_t *DataBuffer, uint16_t ExpectedByteNumber){ uint16_t i; uint8_t slave_addr = BQ769X0_SLAVE_ADDR << 1;
HalBq769x0IIC_Start(); HalBq769x0IIC_Send_Byte(slave_addr | BQ_CMD_READ); HalBq769x0IIC_Wait_Ack();
for(i = 0; i < ExpectedByteNumber; i++) { if(i == ExpectedByteNumber – 1) { DataBuffer[i] = HalBq769x0IIC_Read_Byte(0); } else { DataBuffer[i] = HalBq769x0IIC_Read_Byte(1); } }
HalBq769x0IIC_Stop();
return 0;}
void HalBq769x0Init(void){ HalBq769x0IIC_Init();}
#ifdef BQWITHCRCstatic uint8_t CRC8(uint8_t *ptr, uint8_t len, uint8_t key){ uint8_t i; uint8_t 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);}
int8_t HalBQ_ReadRegisterByte(uint8_t Register, uint8_t *Data){ uint8_t TargetRegister = Register; uint8_t ReadData[2]; uint8_t CRCInput[2]; uint8_t crc_val = 0;
HalBq769x0I2CSendBytes(&TargetRegister, 1); HalBq769x0I2CReadBytes(ReadData, 2);
CRCInput[0] = (BQ769X0_SLAVE_ADDR << 1) + 1; CRCInput[1] = ReadData[0];
crc_val = CRC8(CRCInput, 2, CRC_KEY);
if (crc_val != ReadData[1]) { SysLog("crc err!! %02x,%02x,crc_cal=%02x", ReadData[0], ReadData[1], crc_val); return -1; }
*Data = ReadData[0];
return 0;}
int8_t HalBQ_ReadRegisterWord(uint8_t Register, uint16_t *Data){ uint8_t TargetRegister = Register; uint8_t ReadData[4]; uint8_t CRCInput[2]; uint8_t crc_val = 0;
HalBq769x0I2CSendBytes(&TargetRegister, 1); HalBq769x0I2CReadBytes(ReadData, 4);
CRCInput[0] = (BQ769X0_SLAVE_ADDR << 1) + 1; CRCInput[1] = ReadData[0];
crc_val = CRC8(CRCInput, 2, CRC_KEY);
if (crc_val != ReadData[1]) { return -1; }
crc_val = CRC8(ReadData + 2, 1, CRC_KEY);
if (crc_val != ReadData[3]) { return -1; }
*Data = (ReadData[0] << 8) + ReadData[2]; return 0;}
int8_t HalBQ_ReadBlock(uint8_t Register, uint8_t *Buffer, uint8_t Length){ uint8_t TargetRegister = Register; uint8_t ReadData[BQ769X0_REGISTER_NUM * 2]; uint8_t CRCInput[2]; uint8_t crc_val = 0; int8_t i;
HalBq769x0I2CSendBytes(&TargetRegister, 1); HalBq769x0I2CReadBytes(ReadData, 2 * Length);
CRCInput[0] = (BQ769X0_SLAVE_ADDR << 1) + 1; CRCInput[1] = ReadData[0];
crc_val = CRC8(CRCInput, 2, CRC_KEY); if (crc_val != ReadData[1]) { return -1; } else { Buffer[0] = ReadData[0]; }
for(i = 2; i < Length * 2; i += 2) { crc_val = CRC8(ReadData + i, 1, CRC_KEY);
if (crc_val != ReadData[i + 1]) { return -1; } else { Buffer[i >> 1] = ReadData[i]; } }
return 0;}
int8_t HalBQ_WriteRegisterByte(uint8_t Register, uint8_t Data){ uint8_t DataBuffer[4];
DataBuffer[0] = BQ769X0_SLAVE_ADDR << 1; DataBuffer[1] = Register; DataBuffer[2] = Data; DataBuffer[3] = CRC8(DataBuffer, 3, CRC_KEY);
return(HalBq769x0I2CSendBytes(DataBuffer + 1, 3));}
int8_t HalBQ_WriteRegisterWord(uint8_t Register, uint16_t Data){ uint8_t DataBuffer[6];
DataBuffer[0] = BQ769X0_SLAVE_ADDR << 1; DataBuffer[1] = Register; DataBuffer[2] = (uint8_t)(Data & 0xff); DataBuffer[3] = CRC8(DataBuffer, 3, CRC_KEY); DataBuffer[4] = (uint8_t)((Data >> 8) & 0xff); DataBuffer[5] = CRC8(DataBuffer + 4, 1, CRC_KEY);
return(HalBq769x0I2CSendBytes(DataBuffer + 1, 5));}
int8_t HalBQ_WriteBlock(uint8_t StartAddress, uint8_t *Buffer, uint8_t Length){ uint8_t send_buffer[BQ769X0_REGISTER_NUM * 2 + 2]; int8_t result; uint8_t i, *pt;
send_buffer[0] = BQ769X0_SLAVE_ADDR << 1; send_buffer[1] = StartAddress; send_buffer[2] = Buffer[0]; send_buffer[3] = CRC8(send_buffer, 3, CRC_KEY);
pt = send_buffer + 4;
for(i = 1; i < Length; i++) { *pt++ = Buffer[i]; *pt++ = CRC8(Buffer + i, 1, CRC_KEY); }
result = HalBq769x0I2CSendBytes(send_buffer + 1, 2 * Length + 1); return result;}#elseint8_t HalBQ_WriteBlock(uint8_t StartAddress, uint8_t *Buffer, uint8_t Length){ uint8_t send_buffer[BQ769X0_REGISTER_NUM + 1]; int8_t i, result; uint8_t *pt = send_buffer;
if(Length > BQ769X0_REGISTER_NUM) { return -1; }
*pt++ = StartAddress;
for(i = 0; i < Length; i++) { *pt++ = Buffer[i]; }
result = HalBq769x0I2CSendBytes(send_buffer, Length + 1);
return result;}
int8_t HalBQ_WriteRegisterByte(uint8_t Register, uint8_t Data){ uint8_t DataBuffer[2]; int8_t tempVal;
DataBuffer[0] = Register; DataBuffer[1] = Data;
tempVal = HalBq769x0I2CSendBytes(DataBuffer, 2);
return tempVal;}
int8_t HalBQ_WriteRegisterWord(uint8_t Register, uint16_t Data){ uint8_t DataBuffer[3]; int8_t tempVal;
DataBuffer[0] = Register; DataBuffer[1] = (uint8_t)(Data & 0xff); DataBuffer[2] = (uint8_t)((Data >> 8) & 0xff);
tempVal = HalBq769x0I2CSendBytes(DataBuffer, 3); return tempVal;}
int8_t HalBQ_ReadRegisterByte(uint8_t Register, uint8_t *DataBuf){ uint8_t TargetRegister = Register;
HalBq769x0I2CSendBytes(&TargetRegister, 1); HalBq769x0I2CReadBytes(DataBuf, 1);
return 0;}
int8_t HalBQ_ReadRegisterWord(uint8_t Register, uint16_t *DataBuf){ uint8_t ReadData[4]; uint8_t TargetRegister = Register;
HalBq769x0I2CSendBytes(&TargetRegister, 1); HalBq769x0I2CReadBytes(ReadData, 2);
*DataBuf = ((uint16_t)ReadData[0] << 8) + (uint16_t)ReadData[2];
return 0;}
int8_t HalBQ_ReadBlock(uint8_t StartRegisterAddress, uint8_t *Buffer, uint16_t BlockSize){ uint8_t TargetRegister = StartRegisterAddress; uint16_t SentByte = 0;
HalBq769x0I2CSendBytes(&TargetRegister, 1); HalBq769x0I2CReadBytes(Buffer, BlockSize);
return 0;}#endif
ning wang9:
回复 ning wang9:
关于 芯片的地址,是需要左移一位再发送的
user4996058:
回复 ning wang9:
王工您好!
请问您的这段代码可以调试吗!
user4881649:
回复 user4996058:
请问你的问题怎么解决的我也遇到同样的问题
Q X:
你这个调试好了吗?我也遇到了同样的问题,请问怎么解决的