Analog Pin as Digital Input

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
vivekatamantya
Level 2
Level 2
10 questions asked 10 replies posted 5 replies posted

Hello all,

I am using CY8CKIT-062S4 PSoC 6 kit for development purposes.

In that kit, due to unavailability of the digital input pins, I have to use the Analog pins of the controller. So due to that, I am using P10.5 and P10.6 pins as digital input pins.

I have configured these pins as follows:

.outVal = 0,
.driveMode = CY_GPIO_DM_STRONG,
.hsiom = UserLapSel_HSIOM,
.intEdge = CY_GPIO_INTR_DISABLE,
.intMask = 0UL,
.vtrip = CY_GPIO_VTRIP_CMOS,
.slewRate = CY_GPIO_SLEW_FAST,
.driveSel = CY_GPIO_DRIVE_1_2,
.vregEn = 0UL,
.ibufMode = 0UL,
.vtripSel = 0UL,
.vrefSel = 0UL,
.vohSel = 0UL,

I don't want to enable interrupt, so I have disabled it, after using Cy_GPIO_Pin_Init(GPIO_PRT10, 5U, &UserLapSel_config).

But after initializing the GPIO, when I am reading the state of GPIO, it is not able to sense the 3.3V digital input. 

I have read on the forum that I have enabled some other functionalities specifically for this Analog specialized pin using HSIOM, but I am unable to do that. Please suggest to me what things do I need to operate this P10.5 to read as a digital input pin?

Thank you.

Regards,
Vivek Karna

0 Likes
1 Solution
PandaS
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 5 likes given

Hi @vivekatamantya ,

I have replicated your issue on my end. Please refer to the code below:

int main(void)
{
    cy_rslt_t result;

    /* Initialize the device and board peripherals */
    result = cybsp_init() ;
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

    __enable_irq();

    cy_stc_gpio_pin_config_t GPIO10_5 = {.outVal = 0,
										.driveMode = CY_GPIO_DM_STRONG,
										.hsiom = P10_5_GPIO,
										.intEdge = CY_GPIO_INTR_DISABLE,
										.intMask = 0UL,
										.vtrip = CY_GPIO_VTRIP_CMOS,
										.slewRate = CY_GPIO_SLEW_FAST,
										.driveSel = CY_GPIO_DRIVE_FULL};

    Cy_GPIO_Pin_FastInit(P9_0_PORT, P9_0_NUM, CY_GPIO_DM_STRONG, 1, P9_0_GPIO);
    Cy_GPIO_Pin_Init(P10_5_PORT, P10_5_NUM, &GPIO10_5);

    //Cy_GPIO_Pin_FastInit(P9_0, P9_0, CY_GPIO_DM_STRONG, 1, P9_0_GPIO);

    for (;;)
    {
    	if(Cy_GPIO_Read(P10_5_PORT, P10_5_NUM)){
    		Cy_GPIO_Write(P9_0_PORT, P9_0_NUM, 1);
    	}else{
    		Cy_GPIO_Write(P9_0_PORT, P9_0_NUM, 0);
    	}
    }
}

I have a LED connected to P9_0 to observe whether it works or not. I was able to read P10_5 and toggle P9_0 accordingly. This was done on  CY8CKIT-062S2-43012 kit, please replicate the code at your end and let me know the result.

Warm Regards

Sobhit

View solution in original post

0 Likes
1 Reply
PandaS
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 5 likes given

Hi @vivekatamantya ,

I have replicated your issue on my end. Please refer to the code below:

int main(void)
{
    cy_rslt_t result;

    /* Initialize the device and board peripherals */
    result = cybsp_init() ;
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

    __enable_irq();

    cy_stc_gpio_pin_config_t GPIO10_5 = {.outVal = 0,
										.driveMode = CY_GPIO_DM_STRONG,
										.hsiom = P10_5_GPIO,
										.intEdge = CY_GPIO_INTR_DISABLE,
										.intMask = 0UL,
										.vtrip = CY_GPIO_VTRIP_CMOS,
										.slewRate = CY_GPIO_SLEW_FAST,
										.driveSel = CY_GPIO_DRIVE_FULL};

    Cy_GPIO_Pin_FastInit(P9_0_PORT, P9_0_NUM, CY_GPIO_DM_STRONG, 1, P9_0_GPIO);
    Cy_GPIO_Pin_Init(P10_5_PORT, P10_5_NUM, &GPIO10_5);

    //Cy_GPIO_Pin_FastInit(P9_0, P9_0, CY_GPIO_DM_STRONG, 1, P9_0_GPIO);

    for (;;)
    {
    	if(Cy_GPIO_Read(P10_5_PORT, P10_5_NUM)){
    		Cy_GPIO_Write(P9_0_PORT, P9_0_NUM, 1);
    	}else{
    		Cy_GPIO_Write(P9_0_PORT, P9_0_NUM, 0);
    	}
    }
}

I have a LED connected to P9_0 to observe whether it works or not. I was able to read P10_5 and toggle P9_0 accordingly. This was done on  CY8CKIT-062S2-43012 kit, please replicate the code at your end and let me know the result.

Warm Regards

Sobhit

0 Likes