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 clock setting

Part Number: TM4C123GH6PM

I am trying to understand how to write a delay function for a GPIO. For example, 

void PortF_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F
delay = SYSCTL_RCGC2_R; // allow time for clock to start
...
}


unsigned long Led;
void Delay(void){unsigned long volatile time;
time = 145448; // 0.1sec
while(time){
time--;
}
}


int main(void){
PortF_Init(); // make PF1 out (PF1 built-in LED)
while(1){
Led = GPIO_PORTF_DATA_R; // read previous
Led = Led^0x02; // toggle red LED, PF1
GPIO_PORTF_DATA_R = Led; // output
Delay();
}
}

For the function Delay, how can i estimate the following? What is the default clock for the GPIO? 

time = 145448; // 0.1sec

From the documents and 

SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F

, it is not clear to me what clock is being used for the GPIO. 

Regards, 

Leon

  • Hello Leon,

    In general we do not support question related to Direct Register Modification programming, only TivaWare, as stated in point 4 of our TM4C forum guidelines: e2e.ti.com/.../695568

    That said, regarding what you need to do for your application, the delay you want to calculate is going to be based of the system clock. The GPIO's are going to operate based on the system clock.

    Using TivaWare will help you a lot here as we have an API in TivaWare that will give you the system clock frequency for TM4C123x MCU's, so you can use that to build your delay. The API is SysCtlClockGet - just note that API only applies for TM4C123x MCU's, so if you ever use a TM4C129x MCU you would need to use a different API.