请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:TM4C129ENCPDT 大家好、
我正在尝试从 I2C 从设备获取一些数据、但 使用 I2C2时程序卡在 I2CMasterBusy (I2C2_base)中。 我无法获得任何具有示波器的信号。 我在 SCL 和 SDA 中有上拉电阻器。
当我尝试使用 I2C5时、它工作正常。
我可以在这个问题上找到一些方向、对吧?
#include #include #include "inc/hw_i2c.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/gpio.h" #include "driverlib/i2c.h" #include "driverlib/pin_map.h" #include "driverlib/sysctexample.uint8 uart_univers" #define #define "driverlib/uint8 uart_univers.u.uint8 u.uinth "#define #define #define #define "driverlib/uintuint8 uint_uintuart.uart.h "#define #define #include "driverlib/uart.int8 uint_uart.uart.uart.h #define #define #include //指定我们要向写入(寄存器地址) //从器件 I2CMasterSlaveAddrSet (I2C2_base、slave_addr、false); //指定要读取的寄存器 I2CMasterDataPut (I2C2_base、reg); //将控制字节和寄存器地址字节发送到从器件 I2CMasterControl (I2C2_base、I2C_MASTER_CMD_BURST_SEND_START); SysCtlDelay (100); //等待 MCU 完成事务 while (!(I2CMasterBusy (I2C2_base))); SysCtlDelay (100); while (I2CMasterBusy (I2C2_base)); //指定我们将从从从器件读取 I2CMasterSlaveAddrSet (I2C2_base、slave_addr、true); //发送控制字节并从我们的寄存器中读取 //specified I2CMasterControl (I2C2_base、I2C_MASTER_CMD_SINGLE_Receive); SysCtlDelay (100); //等待 MCU 完成事务 while (!(I2CMasterBusy (I2C2_base))); SysCtlDelay (100); while (I2CMasterBusy (I2C2_base)); //返回从指定寄存器提取的数据 返回 I2CMasterDataGet (I2C2_base); } //********* // //配置 I2C5主设备。 //// ***************** volatile uint32_t test = 0; void main (void) { uint32_t ui32SysClock; ui32SysClock = SysCtlClockFreqSet ((SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480)、120000000); // //使用前必须启用 I2C2外设。 // SysCtlPeripheralEnable (SYSCTL_Periph_I2C2); while (!SysCtlPeripheralReady (SYSCTL_Periph_I2C2)) {} SysCtlPeripheralEnable (SYSCTL_Periph_GPION); GPIOPinConfigure (GPIO_PN4_I2C2SDA); GPIOPinConfigure (GPIO_PN5_I2C2SCL); GPIOPinTypeI2CSCL (GPIO_PORTN_BASE、GPIO_PIN_5); GPIOPinTypeI2C (GPIO_PORTN_BASE、GPIO_PIN_4); I2CMasterInitExpClk (I2C2_base、ui32SysClock、false); //在外部连接器中启用电源 SysCtlPeripheralEnable (SYSCTL_Periph_GPIOJ); GPIOPinTypeGPIOOutput (GPIO_PORTJ_BASE、GPIO_PIN_0); GPIOPinWrite (GPIO_PORTJ_BASE、GPIO_PIN_0、~0); for (;;){ TEST = I2CReceive (register、ID_address); SysCtlDelay (60000000);//~500ms } }