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.

is there any problem in the code for tm4c123gxl

Other Parts Discussed in Thread: TM4C123GH6PM

#define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR_R (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL_R (*((volatile unsigned long *)0x40025420))
#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 SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))
#define PF0 (*((volatile unsigned long *)0x40025004)) // defining port F bit 0

#define PF1 (*((volatile unsigned long *)0x40025008)) // defining port F bit 1
void PortF_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000020; // 1) F clock
delay = SYSCTL_RCGC2_R; // delay to activate clock
GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock PortF PF0
GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0
GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog function
GPIO_PORTF_PCTL_R = 0x00000000; // 4) GPIO clear bit PCTL
GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 input, PF3,PF2,PF1 output
GPIO_PORTF_AFSEL_R = 0x00; // 6) no alternate function
GPIO_PORTF_PUR_R = 0x11; // enable pullup resistors on PF4,PF0
GPIO_PORTF_DEN_R = 0x1F; // 7) enable digital pins PF4-PF0
}
unsigned long i;
int main(void)
{
PortF_Init();
while(1)
{
if(PF0==0x00) //to check whether switch is pressed or not
{
PF1=0x02; // to send digital 1 to port F bit 1
}
else
PF1=0x00; // to send digital 0 to port F bit 1
}
}

  • is there any problem in the code

    Yes.

    You cannot access any peripheral when not clocked and initialized.

    Check the device datasheet and/or the ARM Cortex M4 manual if you don't know what it's about.

  • but i have used it see SYSCTL_RCGC2_R |= 0x00000020; // 1) F clock
  • Ah, I overlooked this. Perhaps because I'm somehow unwilling to wade through obscure register hacking code.
    Are you sure that this is all it needs ?
    Are you sure the register address and the bitmask is correct ?
    Do you have good reasons to discount the tested TivaWare API, and use direct register access ?
  • ya i have looked into the header file for this.. bcoz this code turned my red led stay on for always rather reset or switchoff the device and again plug in...
  • Hello Manish,

    I ran your exact code on TM4C123 LaunchPad and it works as expected. It seems that the transistor for the Red LED may have been spoilt causing the RED LED to remain ON.

    Regards
    Amit
  • SO HOW TO REPLACE THIS..
  • Hello Manish,

    First check the code by changing the LED Port Pin to either of the other color (the blue and green leds would still be OK). Once you confirm that they work fine, then order and replace Q1 Transistor DTC114EET1G.

    Regards
    Amit
  • Hi amit i'm Haseeb.
    i've got the same problem but by changing the code instead of Blue led , red goes on but green Led is working fine.
    when i press the reset button (while green led is on) red led shows up again but when i release it goes to normal (goes to green according to code). so i figured out that when there is no code in flash red led shows its status to up,
    again keep please keep in mind that blue in also not working.
  • First check...
    Press and leave pressed reset button then answer are some led on?
    2> write a simple code that init all bit of led, write 0 to all bit of that port then remain in a loop.
    Are led all off?
    3 Write a securely running code example setting leds, load code then from serial try full red full green full blue, can you have correct color on led?
    Please do all test then answer question to help us really understand what can be faulty at your side...
    If not reload program at point 2 then measure voltage on GPIO pin and report too.
  • write a code which will turn off all the led ..
  • i did the same as you said, but change of code dose not change the state of led, but i figured out by implementing 5 to 6 codes that any pin of any port which is made enable ( for input or for output) , always gives 3.25 volts regardless of code, plus the PF1 always remain high, whether you make it one or zero (through code),

    All the other pins which are not in enable state gives 0 v.

  • Hello Haseeb

    Can you please share the code that you are using?
    For the pins not enabled they are left floating. In floating state they would tend to be close to 0V as they would discharge through parasitic on the board and device.

    Regards
    Amit
  • Yes sure!  as a test code i used these lines


    // Initialize GPIO used for
    void 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
      GPIO_PORTF_LOCK_R = 0x4C4F434B;   // 2) unlock GPIO Port F
      GPIO_PORTF_CR_R = 0x1F;           // allow changes to PF4-0
      GPIO_PORTF_AMSEL_R = 0x00;        // 3) disable analog on PF
      GPIO_PORTF_PCTL_R = 0x00000000;   // 4) PCTL GPIO on PF4-0
      GPIO_PORTF_DIR_R = 0x0E;          // 5) PF4,PF0 in, PF3-1 out
      GPIO_PORTF_AFSEL_R = 0x00;        // 6) disable alt funct on PF7-0
      GPIO_PORTF_PUR_R = 0x11;          // enable pull-up on PF0 and PF4
      GPIO_PORTF_DEN_R = 0x1F;          // 7) enable digital I/O on PF4-0
    }

    as you see i've made PF4,PF0 input and, PF3-1 ( GPIO_PORTF_DIR_R = 0x0E) but all the  pins PF0-4 gives me 3.25 volts all the time.

    but when change this line "GPIO_PORTF_DEN_R = 0x1F"  with  "GPIO_PORTF_DEN_R |= 0x01" then pins  PF2-4 goes off (0 volt) and PF0 goes high along with PF1.

    now if i change it with "GPIO_PORTF_DEN_R |= 0x08"  PF3 goes high along with PF1, similarly if we keep on going with the each pin one by one that pin will show a high status and PF1 remain high all the times ,its state never changes whether you write zero or one to enable register it doesn't matter.

  • Hello Haseeb,

    Why are you using the OR operator? Also you may want to change the use of DEN to DATA register to make pins High or Low. (Pardon me bu this is the TM4C123GXL LaunchPad?)

    Regards
    Amit
  • hello haseeb
    better run this code

    #include<inc/tm4c123gh6pm.h>

    int main(){

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //enable clock for port f
    SysCtlDelay(5);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); set gpio pin
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);

    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 01);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
    return 0 ;

    //it will turn off your all leds

    }