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.

[参考译文] TM4C123BH6PGE:将端口 B 用作 GPIO

Guru**** 2387080 points
Other Parts Discussed in Thread: EK-TM4C123GXL
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1298000/tm4c123bh6pge-using-port-b-as-gpio

器件型号:TM4C123BH6PGE
主题中讨论的其他器件:EK-TM4C123GXL

下午好!

我正在尝试设置 TM4C 微控制器、以将端口 B (引脚0 - 2)用作数字输入。 数据表显示引脚2是特殊的、它可能与此错误有任何关系、也可能没有关系。

无论我如何尝试、对端口 B 寄存器的任何访问之后的下一条指令都会导致硬故障。

按照手册中指示的说明、我已经尝试过:

-配置 SYSCTRL_RCGCGPIO 寄存器包括端口 B

-通过向 DIR 寄存器写入0将端口 B 配置为输入

-通过写入0x4C4F434B 禁用 PORTB_LOCK

-写入提交寄存器(似乎是必要的,但我不管怎样做)

-设置 AFSEL 为0

-通过向 DEN 寄存器写入相应的位配置为 I/O。

几乎每一个可能的顺序和组合。 在执行了与端口 B 有关的任何操作后、它似乎总是抛出硬故障。 我可以设置 SYSCTRL_RCGCGPIO 寄存器并观察寄存器情况良好、但任何与端口 B 相关的指令似乎都会引起硬件故障。 我不确定是否有办法可以获得更多有关其实际原因的信息。

下面是一个代码片段:

#define PORT_A         (1U << 0)
#define PORT_B         (1U <<1)
#define PORT_C         (1U <<2)
#define PORT_D         (1U <<3)
#define PORT_E         (1U <<4)
#define PORT_F         (1U <<5)
#define PORT_G         (1U <<6)
#define PORT_H         (1U <<7)
#define PORT_J         (1U <<8)
#define PORT_K         (1U <<9)
#define PORT_L         (1U <<10)
#define PORT_M         (1U <<11)
#define PORT_N         (1U <<12)
#define PORT_P         (1U <<13)

#define PIN_0          (1U <<0)
#define PIN_1          (1U <<1)
#define PIN_2          (1U <<2)
#define PIN_3          (1U <<3)
#define PIN_4          (1U <<4)
#define PIN_5          (1U <<5)
#define PIN_6          (1U <<6)
#define PIN_7          (1U <<7)
#define PIN_ALL        0xFF   

...

 SYSCTL_RCGCGPIO_R  |=(PORT_A|PORT_B|PORT_D|PORT_G|PORT_H|PORT_J|PORT_L|PORT_M|PORT_N);
 SYSCTL_GPIOHBCTL_R |=(PORT_J|PORT_L|PORT_M|PORT_N);
 
 
/*端口 A 初始化...*/

 
 //端口 B         
 GPIO_PORTB_LOCK_R = 0x4C4F434B;
 GPIO_PORTB_CR_R = 0x07;//将始终出现硬故障,无论顺序如何
 GPIO_PORTB_AFSEL_R = 0x0;  
 GPIO_PORTB_DEN_R =(PIN_0|PIN_1|PIN_2);
 GPIO_PORTB_DIR_R = 0x0;
 GPIO_PORTB_PCTL_R = 0x0;

感谢任何协助。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

     您是否有任何确凿的理由不使用 TivaWare SDK? 您使用 DRM 样式进行编码、而不是使用提供的 API。 如果您在 FAQ https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/695568/faq-faqs-for-tm4c-arm-cortex-m4f-microcontrollers 中参考#4, 我们实际上不支持 DRM 风格的编码。  

    这是一段用于切换 PB (2:0)的简单程序。 如常见问题解答所述、如果由于任何原因必须使用 DRM、请参阅执行 DRM 编程的 API 的源代码。  

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/sysctl.h"
    
    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>Blinky (blinky)</h1>
    //!
    //! A very simple example that blinks the on-board LED using direct register
    //! access.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
        while(1);
    }
    #endif
    
    //*****************************************************************************
    //
    // Blink the on-board LED.
    //
    //*****************************************************************************
    int
    main(void)
    {
        volatile uint32_t ui32Loop;
    
        //
        // Enable the GPIO port that is used for the on-board LED.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
        //
        // Check if the peripheral access is enabled.
        //
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))
        {
        }
    
        //
        // Enable the GPIO pin PB[2:0].  Set the direction as output, and
        // enable the GPIO pin for digital function.
        //
        GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0);
    
        //
        // Loop forever.
        //
        while(1)
        {
            //
            // Set the pins high.
            //
            GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0, GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0);
    
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
            {
            }
    
            //
            // Set the pins low.
            //
            GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0, 0x0);
    
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
            {
            }
        }
    }
    

    下面这篇文章展示了如何解锁某些 TM4C123特殊引脚、但您不需要它来解锁 PB。  

    https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1020814/faq-how-to-get-locked-gpio-pins-on-tm4c123-devices-to-work

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢您的回复 Charles、

    DRM =直接寄存器操作是这样吗?

    我将尝试使用 SDK、看看它是否起作用。

    加油打气

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

     是的、DRM 表示 直接寄存器操作。 TivaWare SDK  提供为 TM4C MCU 开发应用所需的所有组件。 TivaWare SDK 简单易用、可使开发人员快速开始软件开发。 API 使用户无需操作硬件寄存器。 SDK 是一款经过测试和维护的成熟工具。 在 SDK 中可以找到一些示例。 请转到以下目录以获取许多可立即使用的示例。 掌握窍门后、只需根据您的应用要求进行修改和调整即可。  

    C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c123gxl

    C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals