Reading Data from Switch pins Tiva c Launcpad

0

I am trying to write code when I press the switch (PF0) the led should be on but my code did not work. I am sure I do all configuration why program don't read data coming from switchs?

#include <stdint.h>
#include <stdlib.h>
#define SYSCTL_RCGC2_R              (*((volatile unsigned long *)0x400FE108))
#define SYSCTL_RCGC2_GPIOF          0x00000020 // Port F Clock Gating Control
#define GPIO_PORTF_DATA_R       (*((volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR_R        (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_PUR_R        (*((volatile unsigned long *)0x40025510))
#define GPIO_PORTF_DEN_R        (*((volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_LOCK_R       (*((volatile unsigned long *)0x40025520))
#define GPIO_PORTF_CR_R         (*((volatile unsigned long *)0x40025524))
#define GPIO_PORTF_AMSEL_R      (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R       (*((volatile unsigned long *)0x4002552C))

#define PF0 (*((volatile unsigned long *)0x40025004))     //0x04 
#define PF4 (*((volatile unsigned long *)0x40025040))           //0x40

void delay(int sec);
int cond;
int k = 2;

int main(void){
    
    SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
    GPIO_PORTF_LOCK_R = 0x4C4F434B; // unlock PF0
    GPIO_PORTF_CR_R = 0x1F;               // can be written 0001.1111
    GPIO_PORTF_AMSEL_R =0x00;       //disableanalog function
    GPIO_PORTF_PCTL_R = 0x00;               // Port control
    GPIO_PORTF_DIR_R = 0x0E;        //0x00001110  leds output swtichs input
    GPIO_PORTF_PUR_R = 0x11;              // pull register active for PF0 and PF4 (switches) 0001.0001
    GPIO_PORTF_DEN_R = 0x0E;                //0x00001110  leds output swtichs input
    PF0 = GPIO_PORTF_DATA_R^0x01; //1  Negative logic will be positive
    PF4 = GPIO_PORTF_DATA_R^0x10; //1
    
    while(1){
        if(PF0 == 0x01){
            GPIO_PORTF_DATA_R = 0x02; // Red for i sec 0x04= blue  yellow = 0x0A
            delay(1+k);
            
        }       
    return 0;
}
}
void delay(int sec){
    int c = 1, d = 1;
    for( c = 1; c <= sec; c++)
        for( d = 1; d <= 4000000; d++){}
        }

I follow this steps;

  1. Activate clock
  2. Unlock GPIO PortF
  3. CR configuration to allow changes PF4-0
  4. Disable analog on PF
  5. Configure Port Control Register
  6. Setting Direction Register
  7. Disable AF if enabled earlier
  8. Enable Digital I/o DEN

Problem solved via putting following lines into the while loop.

  • PF0 = GPIO_PORTF_DATA_R^0x01; //1 Negative logic will be positive
  • PF4 = GPIO_PORTF_DATA_R^0x10; //1
c
arm
embedded
asked on Stack Overflow Apr 3, 2021 by Kerim Turak • edited Apr 4, 2021 by Kerim Turak

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0