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.

can I blinking onboard led with API given by TI?

Other Parts Discussed in Thread: EK-TM4C1294XL

Hello Guys,

I have a EK-TM4C1294XL board, I was trying to use only driver files given by TI to turn on one of the led, but I didn't find a way it worked. so is that possible? here is my code:

SysCtlClockFreqSet(SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_320, 40000000);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);

GPIODirModeSet(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_DIR_MODE_OUT);

// GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);

GPIOPadConfigSet(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_STRENGTH_4MA,
GPIO_PIN_TYPE_STD);
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 1);

while(1);

  • Hello Ruoshi,

    Couple of pointers on the code

    1. The System Clock Function must have the crystal value

    SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                     SYSCTL_OSC_MAIN |
                                                     SYSCTL_USE_PLL |
                                                     SYSCTL_CFG_VCO_480), 120000000);

    2. Use the API GPIOPinTypeGPIOOutput. That will take care of most of the work for you.

    3. To write the value 1 to a pin the API Call has to be

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1);

    Regards

    Amit

  • Try to use the GPIOOutput instead of the DirModeSet.

    After SysCtlPeripheralEnable you need at least 3 clock cycles before accessing the peripheral registers so try to add SysCtlDelay(3); (this will delay the code for 9 clock cycles)

    I don't quite remember the system clock configurations but try this if what i said before doesn't work:

    SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
        SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
        SYSCTL_CFG_VCO_480), 120000000);


    Edit:

    Amit wrote the solution while i was writing this one 

  • Hi Amit,

    Thank you for your answer, its worked! but one thing I dont understand, in GPIOPinWrite(), why the last argument must be GPIO_PIN_1 instead of the value I want to assign the pin? and also according to API comments it should be the value not the pin name

  • That is due to how the hardware actually works. check out 10.2.1.2 Data Register Operation in the datasheet

  • Hello Ruoshi,

    Please refer to the last 2 posts from the following thread from today on why the value has to be written the way it is been suggested.

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/371414.aspx

    The GPIO module in TM4C uses bit-banded address to give the flexibility of updating only specific pins w/o affecting other pins in the port.

    Hello Luis

    Please un-edit, there was a crucial piece of information that I obviously overlooked on the enabling of clocks.

    Regards

    Amit

  • Thanks Amit, i missed that. Today i'm too distracted in my answers.


    For better reference this what i should have not crossed with a line:


    Luis Afonso said:
    After SysCtlPeripheralEnable you need at least 3 clock cycles before accessing the peripheral registers so try to add SysCtlDelay(3); (this will delay the code for 9 clock cycles)