大家好、我在从 Lounchpad TM4C123gxl 到接近传感器 ADPS9960的 I2C 通信方面遇到了问题。 我初始化 MCU、外设、当尝试 从传感器寄存器读取时、我获得0xFF、当我尝试从 Arduino 板读取到同一传感器时、代码工作正常。 因此、我显然做了一些错误、我不知道是什么。 我在 SCL 和 SDA 线路中连接了上拉电阻器(10k)。以下是我的 I2C 代码:
void main (void){ SysCtlClockSet (SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_INT | SYSCTL_XTAL_16MHz); Configuration (); while (1) { Read_Inputs (); } void I2C_Configuration () { SysCtlPeripheralEnable (SYSCTL_Periph_I2C0); SysCtlPeripheralReset (SYSCTL_Periph_I2C0); C0SDA PeripheralEnable (SYSCTL_Periph_GPIOB);GPIOPinConfigure (GPIO_PB2_I2C0);C0C0SDA PeripheralEnable (SYSCTL_PERIPH_GPIO3);GPIOPinConfigure) GPIOPinTypeI2CSCL (GPIO_PORTB_BASE、GPIO_PIN_2); GPIOPinTypeI2C (GPIO_PORTB_BASE、GPIO_PIN_3); I2CMasterInitExpClk (I2C0_BASE、 SysCtlClockGet ()、false); HWREG (I2C0_BASE + I2C_O_FIFOCTL)= 80008000; } uint8_t I2CWriteDataByte (uint8_t SLAVE_addr、uint8_t DEV_reg、uint8_t DATA) {I2CMasterSlaveAddr (I2CM0_Idr、I2CMaster0_Idr) I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_SINGLE_SEND); while (I2CMasterBusy (I2C0_BASE)); I2CMasterDataPut (I2C0_BASE、DATA); I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_FINISH); while (I2CMasterBusy (I2C0_BASE)); return 1; } uint8_t I2CReadDataByte (uint8_t SLAVE_addr、uint8_t SLAVE_reg) { I2CMaster0 、I2CMReadDataSet (I2CMaster0_SLAVE_ADAS);I2CMaster0_SLAVESD_BASE (I2CM0) I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_SINGLE_SEND); while (I2CMasterBusy (I2C0_BASE)); I2CMasterSlaveAddrSet (I2C0_BASE、SLAVE_ADDR、 TRUE); I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_SINGLE_Receive); while (I2CMasterBusy (I2C0_BASE)); return (I2CMasterDataGet (I2C0_BASE))); }