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.

TM4C1230 BootLoader中控制GPIO高低

我想在BootLoader里通过SPI实现对外部Flash的读写,但是初始化完SPI想要手动拉低CS,发现通过GPIO控不管写0还是写1都会导致管脚被拉低。代码都是直接移植的Gpio.c的库函数。包括

/* 使能外设GPIOA */

void
SysCtlPeripheralEnable(uint32_t ui32Peripheral)
{
    //
    // Check the arguments.
    //
    ASSERT(_SysCtlPeripheralValid(ui32Peripheral));

    //
    // Enable this peripheral.
    //
    HWREGBITW(SYSCTL_RCGCBASE + ((ui32Peripheral & 0xff00) >> 8),
              ui32Peripheral & 0xff) = 1;
}

/* 设置GPIO管脚模式,包括驱动能力和output */

void
GPIOPinTypeGPIOOutput(uint32_t ui32Port, uint8_t ui8Pins)
{
    //
    // Check the arguments.
    //
    ASSERT(_GPIOBaseValid(ui32Port));

    //
    // Set the pad(s) for standard push-pull operation.
    //
    GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);

    //
    // Make the pin(s) be outputs.
    //
    GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_OUT);
}

控制GPIO直接用的底层函数

/* 拉低 */

HWREG(GPIO_PORTA_BASE + (GPIO_O_DATA + (SSI_CS << 2))) = 0;

/* 拉高 */

HWREG(GPIO_PORTA_BASE + (GPIO_O_DATA + (SSI_CS << 2))) = 1;

但现在的情况是不管写0还是写1都会导致被拉低,且无法拉高

想问一下我的用法是不是有问题呢?或者最好是官方提供的BOOT代码中能直接控GPIO,或者SPI的SDK里有直接进行片选的方式?

  • 你好像拉低和拉高的库函数配置有问题,tiva的输出函数和别的芯片的输出函数不一样,不是直接写0和1就可以的。由于没见你的程序代码,只能这么猜测了。
  • 您好,不知道您要看我这里的什么代码,这个输出输出我是从gpio.c里拷出来的

    //*****************************************************************************
    //
    //! Writes a value to the specified pin(s).
    //!
    //! \param ui32Port is the base address of the GPIO port.
    //! \param ui8Pins is the bit-packed representation of the pin(s).
    //! \param ui8Val is the value to write to the pin(s).
    //!
    //! Writes the corresponding bit values to the output pin(s) specified by
    //! \e ui8Pins.  Writing to a pin configured as an input pin has no effect.
    //!
    //! The pin(s) are specified using a bit-packed byte, where each bit that is
    //! set identifies the pin to be accessed, and where bit 0 of the byte
    //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
    //!
    //! \return None.
    //
    //*****************************************************************************
    void
    GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val)
    {
        //
        // Check the arguments.
        //
        ASSERT(_GPIOBaseValid(ui32Port));
    
        //
        // Write the pins.
        //
        HWREG(ui32Port + (GPIO_O_DATA + (ui8Pins << 2))) = ui8Val;
    }

    用的时候就是写0写1啊...没有听说有别的用法...

  • 好像不是这个样子的,你参考下gpio的例程,看看参数的配置,我这里手机,没法翻例程。不要只看函数原型
  • http://bbs.21ic.com/icview-950404-1-1.html

    你可以看看我这个帖子,确实不一样的。

  • 是的~~~谢谢你!!!我犯二了