你(们)好
我目前正在 tm4c123gh6pge 板中进行 I2C 通信、主要是...
我想通过 I2C 通信收集传感器(D6F-PH0505AD3)到 tm4c123gh6pge 的压力值。 但是、我将获取未知值作为响应、并执行了如下代码
SysCtlPeripheralEnable (SYSCTL_Periph_I2C3);
SysCtlPeripheralReset (SYSCTL_Periph_I2C3);
GPIOPinConfigure (GPIO_PD0_I2C3SCL);
GPIOPinConfigure (GPIO_PD1_I2C3SDA);
GPIOPinTypeI2CSCL (GPIO_PORTD_BASE、GPIO_PIN_0);
GPIOPinTypeI2C (GPIO_PORTD_base、GPIO_PIN_1);
I2CMasterInitExpClk (I2C3_base、SysCtlClockGet ()、true);
I2CSlaveEnable (I2C3_base);
HWREG (I2C3_base + I2C_O_FIFOCTL)= 0x01;
I2CMasterSlaveAddrSet (I2C3_base、slave_address、true);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x0B); //压力传感器初始化
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x00);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_FINISH);
while (I2CMasterBusy (I2C3_base));
//////////////// INTILIZED////////////////////////////////////////
while (1)
{
I2CMasterSlaveAddrSet (I2C3_base、slave_address、true); //压力传感器的串行控制设置以写入数据
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x00);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0XD0);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x40);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0X18);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x06);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_FINISH);
while (I2CMasterBusy (I2C3_base));
I2CMasterSlaveAddrSet (I2C3_base、slave_address、true);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_STOP);
while (I2CMasterBusy (I2C3_base));
SysCtlDelay (SysCtlClockGet ()/30);
////地址写入////////////////////////////////////////////////////////////
I2CMasterSlaveAddrSet (I2C3_base、slave_address、true); //压力传感器的串行控制设置以读取数据
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x00);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0XD0);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0X51);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x2C);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x07);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_FINISH);
while (I2CMasterBusy (I2C3_base));
I2CMasterSlaveAddrSet (I2C3_base、slave_address、true);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_STOP);
while (I2CMasterBusy (I2C3_base));
SysCtlDelay (SysCtlClockGet ()/30);
////写入
I2CMasterSlaveAddrSet (I2C3_base、slave_address、true); //请求从 read_buffer0读取数据
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy (I2C3_base));
I2CMasterDataPut (I2C3_base、0x07);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_SINGLE_SEND);
while (I2CMasterBusy (I2C3_base));
I2CMasterSlaveAddrSet (I2C3_base、SLAVE_Address1、true);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy (I2C3_base));
SysCtlDelay (SysCtlClockGet ());
SysCtlDelay (SysCtlClockGet ());
I2CMasterSlaveAddrSet (I2C3_base、SLAVE_Address1、true); //从 read_buffer0读取数据
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_SINGLE_Receive);
while (I2CMasterBusy (I2C3_base));
SLAVE_DATA=I2CMasterDataGet (I2C3_base);
I2CMasterSlaveAddrSet (I2C3_base、SLAVE_Address1、true);
I2CMasterControl (I2C3_base、I2C_MASTER_CMD_SINGLE_Receive);
while (I2CMasterBusy (I2C3_base));
Slave_data1=I2CMasterDataGet (I2C3_base);
}