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

请问有CC2538硬件I2C多字节收发程序啊?

弄了很久的硬件I2C了,突然发现它不能多字节接收,I2C的接收程序如下:

bool I2C_Recv(uint8 slave_addr,uint8 registerId,uint8* string,uint8 len)
{
if(len < 1 | I2CMasterBusBusy() || NULL == string)
{
return false;
}
I2CMasterSlaveAddrSet(slave_addr, false);
I2CMasterDataPut(registerId);
I2CMasterControl(I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy());
I2CMasterSlaveAddrSet(slave_addr, true);
if(len == 1)
{
I2CMasterControl(I2C_MASTER_CMD_SINGLE_RECEIVE);
while(I2CMasterBusy()); *string = (uint8)I2CMasterDataGet(); }
else
{
I2CMasterControl(I2C_MASTER_CMD_BURST_RECEIVE_START);

for(uint8 count = 0;count < len;count++)
{ string[count] = (uint8)I2CMasterDataGet();
if(count < (len-1))
{ while(I2CMasterBusy());
I2CMasterControl(I2C_MASTER_CMD_BURST_RECEIVE_CONT); }
else
{
I2CMasterControl(I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
} }
}
return true;}

miffy:

多字节收发是没有问题的;

只是每次只收发一个字节,多字节拆分之后也都能正常。

赞(0)
未经允许不得转载:TI中文支持网 » 请问有CC2538硬件I2C多字节收发程序啊?
分享到: 更多 (0)