This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于tm4 硬件IIC的IO口输出方式问题



       之前 一直用STM32,所以就想把一个STM32上的IIC通讯的OLED代码移植到tm4c123GXL Launchpad上。(在这之前从来没用过tm4,所以这是第一个tm4的工程)。按照之前做法,配置时我把SCL和SDA均设为OD输出模式,发现通讯不正常。后来参考了一个代码,发现SCL引脚设置的输出方式为推挽。但是,IIC端口不是一般都设置为OD(开漏)吗?

    GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_2,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD_WPU);
    GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_3,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_OD);

  • STM32设置为开漏模式,并加外部上拉的话,可以作为输入或者输出的。

    TM4C的话,没有规定说是必须设置I2C引脚的输出状态的,配置为I2C功能就好了,代码如下所示:

        //
        // For this example I2C0 is used with PortB[3:2].  The actual port and
        // pins used may be different on your part, consult the data sheet for
        // more information.  GPIO port B needs to be enabled so these pins can
        // be used.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
        //
        // Configure the pin muxing for I2C0 functions on port B2 and B3.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PB2_I2C0SCL);
        GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    
        //
        // Select the I2C function for these pins.  This function will also
        // configure the GPIO pins pins for I2C operation, setting them to
        // open-drain operation with weak pull-ups.  Consult the data sheet
        // to see which functions are allocated per pin.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
        GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

  • 谢谢你花费时间回复我的问题。不过,我还有些疑惑。我最初的代码参考官方例程,没有加我问题里的两句代码,即只把引脚配置为IIC。但此时代码无法正常工作的,通讯程序会卡住。加入了端口输出模式设置,代码才能正常驱动oled。这又是为什么呢?
  • 我猜测你的端口输出模式设置代码是不是在
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);这句代码之后呢?
    这句之后加上就可以,不加就不可以,对吧?