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.

TM4C123GH6PM GPIO中断问题

Other Parts Discussed in Thread: MSP430F5529

GPIOIntRegister(uint32_t ui32Port, void (*pfnIntHandler)(void));

调用这个函数的时候,I2C端口不能正常读取数据。定义的I2C引脚和中断触发引脚在不同的port端口。

  • 楼主请检查是不是注册中断的那个函数的参数有问题,比如ui32Port是没有初始化完整,或者端口错误,或者函数地址为一个错误值或者空值。

    因为程序跑飞之后,一样会导致I2C没法读取数据。

  • GPIOIntRegister(uint32_t ui32Port, void (*pfnIntHandler)(void));你不会是直接调用的这个程序吧?和楼上说的一样,检测一遍你的初始化过程,所给信息量太少,无法判断。

  • 我觉得是初始化配置的时候出了问题

    int main(void)
    {
     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
     //设置系统时钟为80MHz
     SysCtlClockSet(SYSCTL_SYSDIV_2_5 |SYSCTL_USE_PLL|SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);

    GPIOIntRegister(GPIO_PORTF_BASE, PortFIntHandler);
     //PF4作为中断输入源对应LaunchPad的按键1 SW1
     GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
     //配置PF4为上拉电阻,输出电流能力2mA
     GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
     //终端类型为上升沿触发
     GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4 , GPIO_RISING_EDGE);
     //使能PF4中断
     GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_4);

    我打算用这个引脚采用边沿触发中断

  •  设置PORTA为IIC接口
        SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);  //使能I2C1
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //使能PA6
        GPIOPinConfigure(GPIO_PA6_I2C1SCL);            //配置PA6为I2C1SCL
        GPIOPinConfigure(GPIO_PA7_I2C1SDA);
        GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_7);           //选择PA7作为SDA

        GPIOPinTypeI2CSCL(GPIO_PORTA_BASE,GPIO_PIN_6); //选择PA6作为SCL

    设置PORT F4作为中断接口

            SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

            GPIOIntRegister(GPIO_PORTF_BASE, PortDIntHandler);

            GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);

            GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_RISING_EDGE);

            GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_4);


    分开可以正常工作,

    程序里写了GPIOIntRegister(GPIO_PORTF_BASE, PortDIntHandler);这句话

    不调用它,都没有数据,必须注释掉,IIC才会有数据。

  • PortDIntHandler这个中断函数你定义了没,注释掉就没问题了,说明你中断函数除了问题。

  • 还有,你试着把这个函数GPIOIntRegister这个函数写到后面试试,应该先配置好输入方式,特殊功能,再写中断函数的

  • PORT(ABCEDF)的PIN0~7都可以作为中断检测引脚吗?

  • 楼主你好,不是所有的GPIO都是特仑苏。

    以MSP430F5529为例,只有Port A以及Port B支持外部中断。Datasheet上是这么说的:

    Individually configurable P1 and P2 interrupts. Some devices may include additional port interrupts.

    Ports P1 and P2 always have interrupt capability. Each interrupt for the P1 and P2 I/O lines can be

    individually enabled and configured to provide an interrupt on a rising or falling edge of an input signal. All
    P1 I/O lines source a single interrupt vector P1IV, and all P2 I/O lines source a different, single interrupt
    vector P2IV. On some devices, additional ports with interrupt capability may be available (see the device-
    specific data sheet for details) and contain their own respective interrupt vectors

    所以,是否支持外部中断还得看datasheet。此外,要是所有的引脚都支持外部中断,有时候同一型号的单片机有不一样多的IO口。那么同一个型号的MSP430还得使用不同的中断向量表,想想就觉得很x疼。

    供参考。

  • TIVA的GPIO的引脚都可以作为中断检测引脚,当然JTAG/SWD接口,NMI信号接口这些都需要解锁,最好不要用。