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 Microcontroller

Other Parts Discussed in Thread: LMFLASHPROGRAMMER

I am very much new to Embedded systems, and will like to develop myself in this aspect.

I will like to use a port, E,g PORT A. I know that i will have to activate the clock for the port, set the direction register and so on, but my problem is getting the addresses needed.

for example: #define SYSCTL_RCGC2_R(*((volatile unsigned long *) 0x400xxxx)

How do I get this from the data sheet.

Thank You

  • Hi Kevin,

         I think what you need first guides and tutorials on how to make programs for your Tiva Launchpad.

         TI has laboratory workshop that you can learn from. Besides that there are several example codes from Tivaware, that you can learn from to develop programs for your Tiva Launchpad.

         I would also suggest Tiva Launchpad tutorials in the internet besides here. 

         If you have already made some code for your Launchpad, post it here, so, others can give you advice what improvement is needed.

    - kel

  • Hello Kevin

    Welcome to Embedded Systems.

    As Kel Mentioned there are labs to start with. However if you want to do get information on the address and bits, the data sheet has it in the Register Map and Register Description Section.

    Also how to use a IP would be mentioned in the Initialization and Configuration Section if the IP in the data sheet.

    Regards

    Amit

  • Thanks a lot, I have managed to get the information that I needed and progressed a bit to write some code. Below is what  I have managed to do.

    #define GPIO_PORTE_DATA_R       (*((volatile unsigned long *)0x40024000))
    #define GPIO_PORTE_DIR_R        (*((volatile unsigned long *)0x40024400))
    #define GPIO_PORTE_AFSEL_R      (*((volatile unsigned long *)0x40024420))
    #define GPIO_PORTE_PUR_R        (*((volatile unsigned long *)0x40024510))
    #define GPIO_PORTE_DEN_R        (*((volatile unsigned long *)0x4002451C))
    #define GPIO_PORTE_CR_R         (*((volatile unsigned long *)0x40024524))
    #define GPIO_PORTE_AMSEL_R      (*((volatile unsigned long *)0x40024528))
    #define GPIO_PORTE_PCTL_R       (*((volatile unsigned long *)0x4002452C))
    #define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))

     

    // 2. Declarations Section
    //   Global Variables
    unsigned long sw;  // input from PF4
    unsigned long Out; // outputs to PF3,PF2,PF1 (multicolor LED)

    //   Function Prototypes
    void PortE_Init(void);
    void Delay(void);


    int main(void){   
       PortE_Init();        // Call initialization of port E  
        while(1){
      sw = GPIO_PORTE_DATA_R&0x08; // read PE4 into sw
        if(sw == 0x00){              // if switch is pressed
          GPIO_PORTE_DATA_R = 0x02;  // LED is green
      } else{                     
          GPIO_PORTE_DATA_R = 0x04;  // LED is red
        }
       Delay();                     // wait 0.1 sec
       GPIO_PORTE_DATA_R = 0x01;    // LED is blue
       Delay();                     // wait 0.1 sec
      }
    }

    // Subroutine to initialize port E pins for input and output
    // PE3 is an input from a switch SW
    // PE2, PE1, PE0 are outputs to the LED

    void PortE_Init(void){ volatile unsigned long delay;
      SYSCTL_RCGC2_R |= 0x00000010;     // 1) E clock
      delay = SYSCTL_RCGC2_R;           // delay  
      GPIO_PORTE_CR_R = 0x2F;           // allow changes to PE5,3-0      
      GPIO_PORTE_AMSEL_R = 0x00;        // 3) disable analog function
      GPIO_PORTE_PCTL_R = 0x00000000;   // 4) GPIO clear bit PCTL 
      GPIO_PORTE_DIR_R |= 0x08;          // 5) PE3 input
      GPIO_PORTE_DIR_R &=~ 0x07;          // 5) PE2,PE1,PE0 output 
      GPIO_PORTE_AFSEL_R = 0x00;        // 6) no alternate function
      GPIO_PORTE_PUR_R = 0x08;          // enable pullup resistors on PE3      
      GPIO_PORTE_DEN_R = 0x0F;          // 7) enable digital pins PE3-PE0       
    }


    // Subroutine to wait 0.1 sec

    void Delay(void){unsigned long volatile time;
      time = 727240*200/91;  // 0.1sec
      while(time){
      time--;
      }
    }

    I will be glad if you could point me in the right direction if I am wrong before I try do the hardware bit.

    Thank you

  • Hello Kevin,

    While I agree on your approach on doing low level register access, I would strongly recommend you to use TIVAWare API's to ensure

    1. The code scales as you develop it.

    2. Review of code is eliminated for basic operation setup.

    As for the code above

    1. CR is not required for Port E. It is 0xFF

    2.  sw = GPIO_PORTE_DATA_R&0x08 is not Pin PE4 but Pin PE3.

    3. GPIO_PORTE_DATA_R is bin banded locations and hence it will read the value of Pin PE0 only. To read the 8-bits it has to 0x400243FC
    4. the delay loop will be ~0.3 sec

    Regards

    Amit

  • Thanks a lot Amit.

    I am only intrested in the first four bits of PORT E, so I have this now:

    #define GPIO_PORTE_DATA_R       (*((volatile unsigned long *)0x4002403C))

    I hope I am right now. And please can you enlighten me more on the calculation involved in the delay loop.

    Thank you

  • Hello Kevin,

    Yes the new address is fine.

    The Delay loop takes 3 system clock cycles to compute a decrement. Hence each decrement value is 3 system clocks worth of delay.

    Thus if the delay value is put as 1000, then the actual delay would be 3000 System Clock

    Regards

    Amit

  • Thanks a lot Amit

  • Good morning Amit,

    I have this question about the RCGC2 of the TM4C123 microcontroller.

    I saw an example online, using Port D, in which the input is on PortD bit3 and output on PortD bit 0

     

    The RCGC2  address is 0x400FE108.

    From the data sheet of the microcontroller, I figured out that the

    Base address for RCGC2 is 0x400FE000

    The offset is 0x108

    And this is associated with Bit 3 of the GPIOD, which is equivalent to 0x0020.

    Putting this information together, I think the address for RCGC2 for Port D should be 0x400FE128.

     Please I will like to know what I  am doing wrong on this, and will it be right if on the data

    DATA_R = 0x40007024.

    Thank You

  • Hello Kevin

    Your calculation for absolute address of RCGC2 is not correct. The offset is 0x108 and the bit position for GPIOD is bit-3 and that's it.

    HWREG(0x400FE108) |= 0x8;

    is sufficient to enable the clock to GPIO Port-D

    Regards

    Amit

  • I am trying to write a code using Port D Bit0 as input and Bit 3 as output. I want the led to be ON when the switch is not pressed and OFF when the switch is pressed. This is my Port initialisation as well as my main function. I will like to confirm if I am right, and if I am, how can I alter the value of the input.

    void PortD_Init(void)
    {
      volatile unsigned long delay;
       SYSCTL_RCGC2_R  |=0x08;  //PORT D clock       
       delay = SYSCTL_RCGC2_R;
       GPIO_PORTD_DIR_R  |= 0x08; //make PORT D Bit 3 an Output     
      GPIO_PORTD_DIR_R  &=~0x01; //make PORT D Bit 0 an Input 
      GPIO_PORTD_AFSEL_R &=~0x09;
      GPIO_PORTD_AMSEL_R &=~0x09;
      GPIO_PORTD_DEN_R |=0x09;  //enable PD), PD3
      GPIO_PORTD_PCTL_R &=~0x0000F00F;
    }

     

    int main(void)
    {
     PortD_Init();
     while(1){
      in = GPIO_PORTD_DATA_R  &0x01; //PD0 as an input
     
      if(in == 0x00)  //if switch is not pressed
      {
       out = GPIO_PORTD_DATA_R  |0x08; //LED ON
      }
      else
      {
       out = GPIO_PORTD_DATA_R  &~0x08;  //LED OFF
      }
     }
    }

  • Hello Kevin,

    Corrections

       GPIO_PORTD_DATA_R  |= 0x08; //LED ON

    and

       GPIO_PORTD_DATA_R  &= ~0x08; //LED OFF

    Regards

    Amit

  • I have a switch connected to PORT D, I will like to have access to the bit that the switch is connected to so I can change its value (ON and OFF) in the simulation mode.

    I go to;

    peripherals->system viewer->GPIO->GPIOD.

    I see all the properties of PORT D, but I do not have access to any of the output or input.

    How do I verify the proper operation of the code before loading unto the main kit

    thanks

     

  • Hello Kevin

    I have not used the Simulation Mode for CCS. But looking at the code it should be OK.

    Worst case if you happen to lock the part, you can use the LMFlashProgrammer to Unlock it.

    Regards

    Amit