给BQ40Z60上电(VCC=25V,ACP=25V),然后用MCU通过模拟SMBUS读取DF数据。
unsigned int DF[2]={0x00,0x40};//BQ40Z60DF读取那要求先发送低位再发送高位
unsigned int Read_Data[32];//存储读取到的数据
void SMBUS_Send_Byte(uint8_t txd)
{ uint8_t t; SMBD_OUT(); SMBC_0();//拉低时钟开始数据传输
for(t=0;t<8;t++)
{ //SMBUS_SDA=(txd&0x80)>>7;
if((txd&0x80)>>7)
SMBD_1();
else
SMBD_0();
txd<<=1; delay_us(2);
SMBC_1();
delay_us(6); SMBC_0(); delay_us(6);
}}
uint16_t SMBUS_Read_Byte(unsigned char ack)
{
uint16_t i,receive=0;
SMBD_IN();//SDA设置为输入
for(i=0;i<8;i++ )
{
SMBC_0(); delay_us(6);
SMBC_1();
receive<<=1;
if(READ_SDA)receive++; delay_us(6); } if (!ack)
SMBUS_NAck();//发送nACK
else
SMBUS_Ack(); //发送ACK return receive;
}
uint8_t SMBUS_Wait_Ack(void)
{
uint8_t ucErrTime=0;
SMBD_IN(); //SDA设置为输入 SMBD_1();delay_us(1); SMBC_1();delay_us(1); while(READ_SDA)
{
ucErrTime++;
if(ucErrTime>250)
{
SMbus_Stop();
return 1;
}
}
SMBC_0();//时钟输出0 return 0;}
/*Address:从器件地址,command:指令,RData:读取数据存储的数组,TData:发送数据块,N:需要发送的块的数量*/
void Block_Read(uint8_t Address,uint8_t Command,uint8_t RData[32],uint8_t TData[32],uint8_t N)
{
uint8_t i;
SMbus_Start();//开始
SMBUS_Send_Byte(Address&0xFE);
while(SMBUS_Wait_Ack());
SMBUS_Send_Byte(Command);
while(SMBUS_Wait_Ack());
SMBUS_Send_Byte(N);
for(i=0;i<N;i++)
{
SMBUS_Send_Byte(TData[i]);
while(SMBUS_Wait_Ack());
}
SMbus_Start();//开始
SMBUS_Send_Byte(Address|0x01);
while(SMBUS_Wait_Ack());
Byet_Count=SMBUS_Read_Byte(0);
for(i=0;i<Byet_Count;i++)
{
RData[i]=SMBUS_Read_Byte(0);
}
SMbus_Stop();//停止
}
void main()
{
Block_Read(0x14,0x44,Read_Data,DF,2);
}
运行之后一直卡在等待ACK应答处。从器件地址根据SMBUS1998年版参考手册上的,Smart Battery Selector/Smart Battery System Manager=0x14和40Z60参考手册上的smart-charger device address(0x12),host address(0x14)。两个地址都试过都是卡在wait ACK处。求看看是程序不对还是地址没找对。
tech air:
回复 Cheng.W:
怎样判断芯片处于Full Access状态?
Star Xu:
回复 tech air:
SEC[1:0] MODE2'b00 Reserved2'b01 Unsealed2'b10 Full Access2'b11 Sealed
详细的参考TRM 11.1.40.2 OperationStatus() Low Word
Cheng.W:
回复 tech air:
查看 Operation status SEC1.0 状态
tech air:
回复 Star Xu:
读取operation status是不是按照smbus总线协议上的read block格式发送?
Start+salve address+write+ ManufactoryBlockAccess+Data Length+34bytes Data+Start+salve address+Read+Data Length+34bytes Data?
还是参考手册上的
Example: Read Chemical ID() (0x0006) via AlternateManufacturerAccess()1. Send Chemical ID() to AlternateManufacturerAccess().(a) SMBus block write. Command = 0x44. Data sent = 06 00 (data must be sent in little endian)2. Read the result from AlternateManufacturerAccess().(a) SMBus block read. Command = 0x44. Data read = 06 00 00 01 (each data entity is returned in littleendian).
发送两次command 0x44?
Cheng.W:
回复 tech air:
按照手册上的,
Dataflash的读取按照我的回复,
Operation station,是SBS command,直接读取对应的地址即可。
tech air:
回复 Cheng.W:
通过上面的DF的发送格式测试芯片对 ManufactoryBlockAccess : 0x44这个无发产生ack应答,随后跟着的 Data Length: 0x02+ DataFlash Address:0x00 , 0x40高位应答时有时无,DataFlash Address低位无应答,Checksum: 0xAB无应答。地址读写位0x16,0x17应答正常。这是什么情况呢?
tech air:
回复 Cheng.W:
能给个SBS COMMAND的读取的smbus的发送格式吗?
Cheng.W:
回复 tech air:
读取SBS command 有两种,直接读取register 地址的;例如下面:
S Addr:0x16 0x08 S Addr:0x17 0xBF 0x0B 0xC0 P
另外一种是需要发送subcommand 到manufacturor command ,然后到对应的返回地址读取数据。
这个是另一个芯片的subcommand的格式,只是参照格式,但是寄存器地址请按照bq40z60的TRM文件确定
S Addr:0x16 0x00 0x07 0x00 0x78 P S Addr:0x16 0x00 S Addr:0x17 0x00 0x00 0xCD P
tech air:
回复 Cheng.W:
好的,谢谢。还有个问题就是用MCU发送地址0x16和0x17能接收到40Z60的的ACK。紧跟着发送manufacturor command:0x00有一定几率是NACK。后续的subcommand 也有一定的几率是NACK。这是什么情况呢?
TI中文支持网