微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 硬件电路设计 > TI电源管理交流 > 关于bq76920通过I2C写入的问题

关于bq76920通过I2C写入的问题

时间:10-02 整理:3721RD 点击:

经过社区上各位大神的解答,现在已经可以通过控制器(TM4C123G)与BQ76920进行通信了,并且可以正常读出各个寄存器里的数据。但是新的问题是,我尝试写入新的值到控制寄存器(例如 SYS_CTRL2),以激活库伦计(CC_EN)。但是写不进去,写完再读取寄存器的状态,显示还是原来的值。这是为什么呢?

附上我的写入代码,望各位大神斧正

比如我要是想写入0100 0000的话,在指令里直接写入64就可以了吧?   如 I2CSend(0x08,2,0x05,64)


void I2CSend(uint8_t slave_addr, uint8_t num_of_args, ...)
{
// Tell the master module what address it will place on the bus when
// communicating with the slave.
I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);

//stores list of variable number of arguments
va_list vargs;

//specifies the va_list to "open" and the last fixed argument
//so vargs knows where to start looking
va_start(vargs, num_of_args);

//put data to be sent into FIFO
I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint8_t));

//if there is only one argument, we only need to use the
//single send I2C function
if(num_of_args == 1)
{
//Initiate send of data from the MCU
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));

//"close" variable argument list
va_end(vargs);
}

//otherwise, we start transmission of multiple bytes on the
//I2C bus
else
{
//Initiate send of data from the MCU
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));

//send num_of_args-2 pieces of data, using the
//BURST_SEND_CONT command of the I2C module

int i =1;
for( i = 1; i < (num_of_args - 1); i++)
{
//put next piece of data into I2C FIFO
I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint8_t));
//send next data that was just placed into FIFO
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);

// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));
}

//put last piece of data into I2C FIFO
I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint8_t));
//send next data that was just placed into FIFO
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));

//"close" variable args list
va_end(vargs);
}
}

唉,又研究了一天,毫无头绪,既然可以从寄存器中读出数据,就说明通信没问题了吧?

当写入的时候,比如要写入0100 0000,直接换算成十进制64写进去吗?

写入是按照十六进制, 0100 0000,是0x40.

如果是带CRC校准的芯片,请参照: http://www.ti.com/lit/an/slva626b/slva626b.pdf 

找到原因了,写数据的时候,必须要带有CRC校验(并不是像说明书上说的那样是可选项),不过读数据的时候,可以不带CRC。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top