使用TM4C129作为IIC主机通讯,每次都只能发送出从机地址,数据发送不出来。
同样的发送代码,移植到TM4C123上去能够正确发送出全部数据。
下面是发送数据的相关代码,和在不同CPU上运行捕获的波形。
void IIC_WriteData(uint32_t slave_add,uint32_t address,uint32_t *data,uint32_t num)
{
uint32_t i=0;
I2CMasterSlaveAddrSet(I2C0_BASE,slave_add,false);//从机地址 false 表示主机写数据;ture 表示主机读数据
while(I2CMasterBusBusy(I2C0_BASE));//检测总线送是否忙碌 //I2CMasterBusy
I2CMasterDataPut(I2C0_BASE,address);//寄存器地址
I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_SEND_START);
for(i=0;i<num-1;i++)
{
while(I2CMasterBusy(I2C0_BASE));
I2CMasterDataPut(I2C0_BASE,data[i]);//写入数据I2CMasterDataPut
I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);//I2C_MASTER_CMD_SINGLE_SEND I2C_MASTER_CMD_BURST_SEND_CONT
}
while(I2CMasterBusy(I2C0_BASE));
I2CMasterDataPut(I2C0_BASE,data[num-1]);//寄存器地址
I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_BASE));
I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_SEND_STOP);
}

