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.

#20 identifier "GPIO_PORTJ_DIR_R" is undefined

Other Parts Discussed in Thread: TM4C1294NCPDT

Hello,

I am writing a simple program that uses GPIO input on TM4C1294XL launchpad.

When setting the DIR and DEN registers for  GPIO PORTJ and GPIO PORTF the error #20 appears but that doesn't happen with GPIO PORTM.

I have included the tm4c1294ncpdt.h file which defines PORTS F ,J and all other ports as I know.

I also read previous questions by others in the community but I couldn't figure out all the matter as most of them have included rom.h file and I don't.

So, what is the problem here? 

Thanks in advance,

Badr Mohamed.

  • Badr Mohamed said:
    I have included the tm4c1294ncpdt.h file which defines PORTS F ,J and all other ports as I know.

    At my copy of tm4c1294ncpdt.h, there are no GPIO_PORTJ_DIR_R.

    - kel

  • Hello Badr,

    Can you please send the Error message?

    Regards

    Amit

  • The code with the tm4c1294ncpdt.h attached..
    --------------------------------------------------------------------
    #include <stdint.h> #include <stdbool.h> #include "inc/tm4c1294ncpdt.h" #include "driverlib/sysctl.h" ///////////////////////////////// int flag = 0; int main(void) { /////////////ENABLE CLOCKING FOR M, J AND F PORTS////////////////////// SYSCTL_RCGCGPIO_R = SYSCTL_PERIPH_GPIOM; //SYSCTL_RCGCGPIO_R = SYSCTL_PERIPH_GPIOJ; //SYSCTL_RCGCGPIO_R = SYSCTL_PERIPH_GPIOF; GPIO_PORTM_DIR_R = 0X04; GPIO_PORTJ_DIR_R = 0X00; GPIO_PORTF_DIR_R = 0X02; GPIO_PORTM_DEN_R = 0X44; GPIO_PORTJ_DEN_R = 0X03; GPIO_PORTF_DEN_R = 0X02; /////////////////////////////////////////////////////////////////////// while(1) { if (((GPIO_PORTJ_DATA_R|0X00)==0X40)&&flag==0) { GPIO_PORTF_DATA_R=0X02; flag=1; } if (((GPIO_PORTJ_DATA_R|0X00)==0X40)&&flag==1) { GPIO_PORTF_DATA_R=0X00; flag=0; } } }4743.tm4c1294ncpdt.h

  • Hi Amit,

    Sorry, I don't get it.

    Isn't the error is #20 identifier "GPIO_PORTJ_DIR_R" is undefined?
    Because that's what appears to me when I build the file..

    Regards

    Badr

  • Hi,

    Was renamed:

    #define GPIO_PORTJ_AHB_DIR_R

    Petrei

  • Badr Mohamed said:
    Isn't the error is #20 identifier "GPIO_PORTJ_DIR_R" is undefined?

    It is "undefined" because it is not in the tm4c1294ncpdt.h file.

    Have you found it at your tm4c1294ncpdt.h file?

    - kel

  • Thanks Kel

    Thanks Amit

    I ran the program with some errors I think it's some electronics and with code itself.

    Another question please, When I enable clocking for more than one port like I say

    SYSCTL_RCGCGPIO_R=SYSCTL_PERIPH_GPIOM;
    SYSCTL_RCGCGPIO_R=SYSCTL_PERIPH_GPIOJ;
    SYSCTL_RCGCGPIO_R=SYSCTL_PERIPH_GPIOF;
    

    It doesnt enable anything but PORTM

    but If wrote into the whole register like:
    SYSCTL_RCGCGPIO_R=0x00000920

    It works fine

    Also, I searched and I found that USR_SW1  SYSCTL_RCGCGPIO_R are PORTJ bit 0 & 1 so I used them to switch on and off an external LED which is connected to PORTF bit 1 but it didnt work.
    What is the mistake I made here?
    Regards,
    Badr.
  • Hello Badr

    The operation that you are performing is a write operation using defines which do not match the exact port bit. You can check for the SYSCTL_PERIPH_GPIOx in the sysctl.h and you would see it is a encoded define. If he intent is to do using SYSCTL_RCGCGPIO_R (which I would strongly advise not to use due to it's very low readability and portability), then use something like this

    SYSCTL_RCGCGPIO_R |= (0x1 << 6);

    SYSCTL_RCGCGPIO_R |= (0x1 << 9);

    SYSCTL_RCGCGPIO_R |= (0x1 << 12);

    to enable individual bits in the port mapping

    For the second part of the question, you would need to show the code and indicate w.r.t. the code what is the issue.

    Regards

    Amit

  • Thanks Amit,

    For the second question the code uses USR_SW1 to turn on the LED and USR_SW2 to turn off it.

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/tm4c1294ncpdt.h"
    #include "driverlib/sysctl.h"
    /////////////////////////////////
    int flag = 0;
    int ripple =0;
    int main(void)
    {
    /////////////ENABLE CLOCKING FOR M, J AND F PORTS//////////////////////
    //SYSCTL_RCGCGPIO_R = 0x00000925;
    SYSCTL_RCGCGPIO_R |= (0x1 << 5);
    SYSCTL_RCGCGPIO_R |= (0x1 << 8);
    SYSCTL_RCGCGPIO_R |= (0x1 << 11);
    GPIO_PORTM_DIR_R = 0X04;
    GPIO_PORTJ_AHB_DIR_R = 0X00;
    GPIO_PORTF_AHB_DIR_R = 0X02;
    GPIO_PORTM_DEN_R = 0X44;
    GPIO_PORTJ_AHB_DEN_R = 0X03;
    GPIO_PORTF_AHB_DEN_R = 0X02;
    ///////////////////////////////////////////////////////////////////////
    while(1)
    	{
    	if (((GPIO_PORTJ_AHB_DATA_R|0XFE)==0XFF)&&flag==0)
    		{
    		for(ripple=0;ripple>200000;ripple++)
    		{}
    		GPIO_PORTF_AHB_DATA_R=0X02;
    		flag=1;
    		}
    	if (((GPIO_PORTJ_AHB_DATA_R|0XFD)==0XFF)&&flag==1)
    		{
    		for(ripple=0;ripple>200000;ripple++)
    		{}
    		GPIO_PORTF_AHB_DATA_R=0X00;
    		flag=0;
    		}
    	}
    
    }
    

  • Hello Badr

    for(ripple=0;ripple>200000;ripple++

    If this a delay loop then shouldn't it be

    for(ripple=0;ripple<200000;ripple++)

    Regards

    Amit

  • Thanks Amit,

    Yeah, I corrected it but even so, nothing changed.

    Regards,

    Badr.

  • Hello Badr,

    Since you are looking for a bit to be 1 the sequence for check should be

      if (((GPIO_PORTJ_AHB_DATA_R&0X01)==0X01)&&flag==0)

      if (((GPIO_PORTJ_AHB_DATA_R&0X02)==0X02)&&flag==0)

    Regards

    Amit

  • Thanks Amit,

    I tried that also but nothing changed.

    I  measured the voltage on the node of the PJ1 & PJ2 (The interface side) referenced to GND and it gave 0V so, I think I should make the input active low in the code.

    I  measured the voltage on the node of the PJ1 & PJ2 (The mcu side) referenced to GND and it gives some noise so, I think it needs a pull up resistor.

    Is this right or wrong?

     

    Regards

    Badr

  • Hello Badr,

    Please enable the Pull Up for the Pins by programming the GPIOPUR register for Port J pins

    EDIT STARTS

    And changing the code as to detect key press (Please note that I had previously made a typo for flag)

      if (((GPIO_PORTJ_AHB_DATA_R&0X01)==0X00)&&flag==0)

      if (((GPIO_PORTJ_AHB_DATA_R&0X02)==0X00)&&flag==1)

    EDIT END

    Regards

    Amit

  • Thanks Amit

    Regards

    Badr