Only some GPIOs work with supplied SDK

I can control Port 4, pin 0 or 1 quite well but when it comes to Port 1, Pin 5, it always goes back to high. 

I am enabling the pull up, setting the output enable and input enable before pulling it high or low through the supplied functions then looking at the outputs. 

Do you know why I can't set Port 1 Pin 5 to be low continuously? When I set it low, and then sense the input, it immediately reads high. 


This does not happen with the other port I tested Port 4 Pin 1 or 0. 

Please help me understand how to set GPIO Port 1 Pin 5 low continuously. 

Thanks. 

  • Hi,

    Which example code and which board(s) are you using?

    -Mark

  • It's ADuCM350 with SDK 2.3.0. I can recreate this effect on both the evaluation kit and my own custom board suggesting it's a larger problem. 

    GetOutputData will give a difference value from GetData though I am setting the PIN to HIGH. I am happy to supply the code I am using if that will help also.  

  • Hi,

    Can you share your code? It might be that there is a wrong setting in here that's causing the pin to toggle

    -Mark

  • Here, I can see I am setting GPIO4.0 with the oscilloscope, but the other two(2.6,2.7) aren't working but are programmed the same way. Please try it out, love your advice on how to get the other GPIO's working. 


    /*****************************************************************************
    * @file: Blinky.c
    * @brief: LED blinking example modified to test GPIO functionality.
    *
    *****************************************************************************/

    #include <stdio.h>
    #include "arm_math.h"
    #include "test_common.h"
    #include "afe.h"
    #include "afe_lib.h"
    #include "uart.h"
    #include "sequences.h"
    #include "lookup.h"
    #include "gpio.h"

    /* Helper macro for printing strings to UART or Std. Output */
    #define PRINT(s) test_print(s)
    #define USE_UART_FOR_DATA (1)

    ADI_UART_HANDLE hUartDevice = NULL;

    void test_print (char *pBuffer);
    ADI_UART_RESULT_TYPE uart_Init (void);
    ADI_UART_RESULT_TYPE uart_UnInit (void);
    extern int32_t adi_initpinmux (void);
    void delay (uint32_t counts);

    // ADI_GPIO_PORT_1,ADI_GPIO_PIN_5
    PinMap EN = {ADI_GPIO_PORT_2,ADI_GPIO_PIN_6}; // ENABLE PIN suspect is not latched.
    PinMap A4 = {ADI_GPIO_PORT_2, ADI_GPIO_PIN_7}; // LATCHED PIN
    PinMap I2C = {ADI_GPIO_PORT_4, ADI_GPIO_PIN_0}; // I2C free PIN.


    int main(void) {

    volatile uint32_t i;
    // uint32_t count = 0;

    /* Initialize system */
    SystemInit();
    /* Change the system clock source to HFXTAL and change clock frequency to 16MHz */
    /* Requirement for AFE (ACLK) */
    if (ADI_SYS_SUCCESS != SystemTransitionClocks(ADI_SYS_CLOCK_TRIGGER_MEASUREMENT_ON))
    {
    PRINT("SystemTransitionClocks");
    }

    /* SPLL with 32MHz used, need to divide by 2 */
    SetSystemClockDivider(ADI_SYS_CLOCK_UART, 2);

    /* Test initialization */
    test_Init();

    // START PROBLEM ///

    ADI_GPIO_RESULT_TYPE d; //,e,f;
    //ADI_UART_RESULT_TYPE a,b,c;

    /* Initialize static pinmuxing */
    adi_initpinmux();
    /* Initialize the UART for transferring measurement data out */
    if (ADI_UART_SUCCESS != uart_Init())
    {
    FAIL("uart_Init failed ");
    }
    PRINT("UART test\n");

    d = adi_GPIO_Init();
    /* Initialize GPIO */
    if (ADI_GPIO_SUCCESS != d)
    {
    PRINT("adi_GPIO_Init went wrong");
    }

    ADI_GPIO_RESULT_TYPE Result;

    if ( (Result = adi_GPIO_SetPullUpEnable (EN.Port, EN.Pins, false)) != ADI_GPIO_SUCCESS) {
    PRINT ("Problem with setting pull up enable");
    }
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetPullUpEnable (A4.Port, A4.Pins, false)) {
    PRINT ("Problem with setting pull up enable");
    }
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetPullUpEnable (I2C.Port, I2C.Pins, false)) {
    PRINT ("Problem with setting pull up enable");
    }

    /* Enable GPIO output drivers */
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetOutputEnable(EN.Port, EN.Pins, true))
    {
    PRINT("adi_GPIO_SetOutputEnable (led_DISPLAY)");
    }
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetOutputEnable(A4.Port, A4.Pins, true))
    {
    PRINT("adi_GPIO_SetOutputEnable (led_DISPLAY1)");
    }
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetOutputEnable(I2C.Port, I2C.Pins, true))
    {
    PRINT("adi_GPIO_SetOutputEnable (led_DISPLAY1)");
    }

    /* Enable GPIO output drivers */
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetInputEnable(EN.Port, EN.Pins, true))
    {
    PRINT("adi_GPIO_SetInputEnable (led_DISPLAY)");
    }
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetInputEnable(A4.Port, A4.Pins, true))
    {
    PRINT("adi_GPIO_SetInputEnable (led_DISPLAY1)");
    }
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetInputEnable(I2C.Port, I2C.Pins, true))
    {
    PRINT("adi_GPIO_SetInputEnable (led_DISPLAY1)");
    }


    /* ever the optimist */
    Result = ADI_GPIO_SUCCESS;

    /* Loop indefinitely */
    while (1)
    {

    char msg[500];
    char tmp[100];
    /* Delay */
    delay(5000);


    sprintf(tmp,"A4 : ");
    strcat(msg,tmp);
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetLow(A4.Port, A4.Pins))
    {
    PRINT("adi_GPIO_SetLow (A4)");
    }
    if ((adi_GPIO_GetOutputData(A4.Port)) & A4.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // when the input is sensed, it is high?
    if ((adi_GPIO_GetData(A4.Port)) & A4.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // PRINT ERROR CODES
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetHigh(A4.Port, A4.Pins))
    {
    PRINT("adi_GPIO_SetHigh (A4)");
    }
    if ((adi_GPIO_GetOutputData(A4.Port)) & A4.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // when the input is sensed, it is high?
    if ((adi_GPIO_GetData(A4.Port)) & A4.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    sprintf(tmp,"\n\r");
    strcat(msg,tmp);
    // AND A4


    sprintf(tmp,"I2C : ");
    strcat(msg,tmp);
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetLow(I2C.Port, I2C.Pins))
    {
    PRINT("adi_GPIO_SetLow (I2C)");
    }
    if ((adi_GPIO_GetOutputData(I2C.Port)) & I2C.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // when the input is sensed, it is high?
    if ((adi_GPIO_GetData(I2C.Port)) & I2C.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // PRINT ERROR CODES
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetHigh(I2C.Port, I2C.Pins))
    {
    PRINT("adi_GPIO_SetHigh (I2C)");
    }
    if ((adi_GPIO_GetOutputData(I2C.Port)) & I2C.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // when the input is sensed, it is high?
    if ((adi_GPIO_GetData(I2C.Port)) & I2C.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    sprintf(tmp,"\n\r");
    strcat(msg,tmp);
    // END I2C

    sprintf(tmp,"EN: ");
    strcat(msg,tmp);
    //// Start new formatting here.
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetLow(EN.Port, EN.Pins))
    {
    PRINT("adi_GPIO_SetLow issue (EN)");
    }
    if ((adi_GPIO_GetOutputData(EN.Port)) & EN.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // when the input is sensed, it is high?
    if ((adi_GPIO_GetData(EN.Port)) & EN.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // PRINT ERROR CODES
    if (ADI_GPIO_SUCCESS != adi_GPIO_SetHigh(EN.Port, EN.Pins))
    {
    PRINT("adi_GPIO_SetHigh (EN)");
    }
    if ((adi_GPIO_GetOutputData(EN.Port)) & EN.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    // when the input is sensed, it is high?
    if ((adi_GPIO_GetData(EN.Port)) & EN.Pins) { //HIGH
    sprintf(tmp,"1,");
    strcat(msg,tmp);
    } else { // LOW
    sprintf(tmp,"0,");
    strcat(msg,tmp);
    }
    sprintf(tmp,"\n\r");
    strcat(msg,tmp);

    strcat(msg,"\n\r");
    PRINT(msg);


    } // end of while loop.


    }


    /* Helper function for printing a string to UART or Std. Output */
    void test_print (char *pBuffer) {
    #if (1 == USE_UART_FOR_DATA)
    int16_t size;
    /* Print to UART */
    size = strlen(pBuffer);
    adi_UART_BufTx(hUartDevice, pBuffer, &size);

    #elif (0 == USE_UART_FOR_DATA)
    /* Print to console */
    printf(pBuffer);

    #endif /* USE_UART_FOR_DATA */
    }

    /* Initialize the UART, set the baud rate and enable */
    ADI_UART_RESULT_TYPE uart_Init (void) {
    ADI_UART_RESULT_TYPE result = ADI_UART_SUCCESS;

    /* Open UART in blocking, non-intrrpt mode by supplying no internal buffs */
    if (ADI_UART_SUCCESS != (result = adi_UART_Init(ADI_UART_DEVID_0, &hUartDevice, NULL)))
    {
    return result;
    }

    /* Set UART baud rate to 115200 */
    if (ADI_UART_SUCCESS != (result = adi_UART_SetBaudRate(hUartDevice, ADI_UART_BAUD_115200)))
    {
    return result;
    }

    /* Enable UART */
    if (ADI_UART_SUCCESS != (result = adi_UART_Enable(hUartDevice,true)))
    {
    return result;
    }

    return result;
    }

    /* Uninitialize the UART */
    ADI_UART_RESULT_TYPE uart_UnInit (void) {
    ADI_UART_RESULT_TYPE result = ADI_UART_SUCCESS;

    /* Uninitialize the UART API */
    if (ADI_UART_SUCCESS != (result = adi_UART_UnInit(hUartDevice)))
    {
    return result;
    }

    return result;
    }

    void delay(uint32_t count)
    {
    while(count>0)
    {
    count--;
    }
    }
    Blinky.c.zip
  • Hi,

    You're not controlling P1.5 in the code above... did you attached the correct c file?

    -Mark