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.

TM4C213,将I2C配置为GPIO进行数据输入输出。

Other Parts Discussed in Thread: EK-TM4C123GXL

想将TM4C123的I2C接口配置为普通GPIO口使用,参照历程写了如下程序:

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTB_BASE + GPIO_O_CR) |=0x0C; /* bits can be written */
HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = 0;

GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_3);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_2);

然后测试PB2,PB3的端口输出

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_PIN_2);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3,0);

用万用表检测始终无法测得正确数据。

后参考论坛上的前辈进行如下更改:

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTB_BASE + GPIO_O_CR) |= (GPIO_PIN_2 | GPIO_PIN_3); /* bits can be written */
HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = 0x0;

还是不能测出,请教各位前辈,谢谢。