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.

Compiler/CC2538-SW: Can't Set PB1 HIGH using GPIOWrite

Part Number: CC2538-SW
Other Parts Discussed in Thread: CC2592, CC2590, CC2591

Tool/software: TI C/C++ Compiler

This is weird but true. SampleSwitch code in its default form is being used in coordinator configuration. 

In Zmain.c :

#ifdef TEST
    varhigh= GPIOPinRead(GPIO_B_BASE, GPIO_PIN_1);//GPIODirModeGet(GPIO_B_BASE, GPIO_PIN_1);
    GPIOPinIntDisable(GPIO_B_BASE, GPIO_PIN_1);
    GPIODirModeSet(GPIO_B_BASE, GPIO_PIN_1,GPIO_DIR_MODE_OUT);

    GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_PIN_1);//EN is at PB1
    while(1)
    {
      //GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 1);//EN goes HIGH-- THIS DOES NOT WORK
      GPIOPinWrite(MYBASE, MY_EN, 1);//-- THIS DOES NOT WORK
        //HAL_TURN_ON_LED2();
      //GPIOPinWrite(GPIO_C_BASE, 0x00000008, 1);//LED4 is PC3
       i=0;
      while( i<50000)
      {//nothing
        i++;
      }
       varhigh= GPIOPinRead(GPIO_B_BASE, GPIO_PIN_1);//GPIODirModeGet(GPIO_B_BASE, GPIO_PIN_1);
       //GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW}
      GPIOPinWrite(MYBASE, MY_EN, 0);
       //HAL_TURN_OFF_LED2();
       //GPIOPinWrite(GPIO_C_BASE, 0x00000008, 0);//LED4 is PC3
       i=0;
       while( i<50000)
      {//nothing
        i++;
      }
      varlow= GPIOPinRead(GPIO_B_BASE, GPIO_PIN_1);
    }
#endif

In above code GPIOWrite commands never work, GPIORead works , Input can be read easily without any issue. Writing PC3(LED_4) can be written using HAL_TURN_ON/OFF/TOGGLE commands easily. What I cant understand is that why am I not able to write any GPIO (tried PC3 and PB1) using GPIOPinWrite API command.

Please Help

 

  • Hi Saurabh,

    So you're saying a call to HAL_TURN_ON_LED4() in that function works, but a call to GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_3, 1) does not work? HAL_TURN_ON_LED4() is simply a macro that is replaced with a function that is equivalent the latter at run time, so I don't see how this could be possible. Also, do you have any of the following macros defined? They change the behavior of the macro HAL_TURN_ON_LED4():

    HAL_PA_LNA
    HAL_PA_LNA_CC2592
    HAL_PA_LNA_CC2590
    MAC_RUNTIME_CC2591
    MAC_RUNTIME_CC2592
    MAC_RUNTIME_CC2590
  • Hi Jason. You got the point right. None of these macros are defined in preprocessor list. Reading the pin happens just fine but neither can the pin be defined as OUTPUT nor writing to it toggles it . it stays HIGH before stepping to GPIOPinWrite(MYBASE, MY_EN, 1);//-- THIS DOES NOT WORK
    . after execution of this line, it goes LOW and remains LOW forever
  • Issue resolved ! GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_0,1 ) works fine but GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1,1 ) wont work ever as third argument '1' means 0x00000001 and GPIO_PIN_1 would expect '2' as third argument because '2' would mean 0x00000010. Alternatively, we can write GPIO_PIN_X, GPIO_PIN_X as 2nd and 3rd arguments to write pin X HIGH. Following code works just fine (in zmain.c).

    ...
    extern uint32_t varhigh=0;
    extern uint32_t varlow=0;
    extern uint32_t cntvar=0;
    /******************************************************************************
    * LOCAL DEFINITIONS
    */
    ...

    ...
    /******************************************************************************
    * LOCAL FUNCTIONS
    */

    static void zmain_dev_info( void );
    static void zmain_ext_addr( void );

    static void helloworld(void);
    ...

    ...
    /* Display the device info on the LCD */
    #ifdef LCD_SUPPORTED
    zmain_dev_info();
    zmain_lcd_init();
    #endif

    #ifdef LCD3
    helloworld();
    while(1)
    {}//*/
    #endif
    ...

    ...
    #ifdef LCD3
    static void helloworld( void )
    {
    varhigh= GPIOPinRead(GPIO_B_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_PIN_2|GPIO_PIN_3);//PC2 is RS, PC3 is RW.LED4 is PC3

    GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_PIN_1);//PB1 is EN

    GPIOPinTypeGPIOOutput(GPIO_A_BASE, GPIO_PIN_6|GPIO_PIN_7);//PA6 is DB4,PA7 is DB5
    GPIOPinTypeGPIOOutput(GPIO_D_BASE, GPIO_PIN_4|GPIO_PIN_5);//PD4 is DB6,PD5 is DB7
    //D3 to D0 are tied to ground and data/commands are transferred 1, 4 bit nibble at a time.
    //while(1)
    //{
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_3, 0);//RW goes LOW
    //0 0 0 1 0 - 0 0 0 0 Set to 4 bit operation (note: 1 nibble operation)
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, 0);//RS goes 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 0);//D7 is 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, 0);//D6 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, GPIO_PIN_7);//D5 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms

    //next command
    // 0 0 0 1 0 - 0 0 0 0 Function set, 8 bit
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, 0);//RS goes 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 0);//D7 is 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, 0);//D6 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, GPIO_PIN_7);//D5 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms
    //0 1 0 0 0 - 0 0 0 0 2nd nibble
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, 0);//RS goes 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 1);//D7 is 1
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, 0);//D6 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, 0);//D5 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms

    // next command
    // 0 0 0 0 0 - 0 0 0 0 Display ON, Cursor On, Cursor Blinking
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, 0);//RS goes 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 0);//D7 is 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, 0);//D6 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, 0);//D5 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms
    //0 1 1 1 1 - 0 0 0 0 2nd nibble
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, 0);//RS goes 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, GPIO_PIN_5);//D7 is 1
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, GPIO_PIN_4);//D6 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, GPIO_PIN_7);//D5 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, GPIO_PIN_6);//D4 is 1
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms

    //next command
    //0 0 0 0 0 - 0 0 0 0 Entry Mode, Increment cursor position, No display shift
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, 0);//RS goes 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 0);//D7 is 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, 0);//D6 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, 0);//D5 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms
    //0 0 1 1 0 - 0 0 0 0 2nd nibble
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, 0);//RS goes 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 0);//D7 is 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, GPIO_PIN_4);//D6 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, GPIO_PIN_7);//D5 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms

    for (varhigh=0;varhigh<4;varhigh++)
    {
    //data 'H'
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, GPIO_PIN_2);//RS goes 1
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 0);//D7 is 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, GPIO_PIN_4);//D6 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, 0);//D5 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms
    // 1 1 0 0 0 - 0 0 0 0 2nd nibble
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, GPIO_PIN_2);//RS goes 1
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, GPIO_PIN_5);//D7 is 1
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, 0);//D6 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, 0);//D5 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms

    //data 'E'
    //1 0 1 1 0 - 0 0 0 0 e
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, GPIO_PIN_2);//RS goes 1
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 0);//D7 is 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, GPIO_PIN_4);//D6 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, GPIO_PIN_7);//D5 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, 0);//D4 is 0
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms
    //1 0 1 0 1 - 0 0 0 0 2nd nibble
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, GPIO_PIN_1);//EN goes HIGH
    GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_2, GPIO_PIN_2);//RS goes 1
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_5, 0);//D7 is 0
    GPIOPinWrite(GPIO_D_BASE, GPIO_PIN_4, GPIO_PIN_4);//D6 is 1
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, 0);//D5 is 0
    GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_6, GPIO_PIN_6);//D4 is 1
    GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_1, 0);//EN goes LOW
    for(cntvar=0;cntvar<5000;cntvar++){};//wait for 31 ms
    //}
    }
    //data "l"

    }
    #endif