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

cross mob
newelectronic1
Level 2
Level 2
10 replies posted 10 sign-ins First question asked

How can setting the same pin as input and output for different time?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I just tried to create a project to test it.

Since I don't have a test hardware I could not test it.

So in case it does not work please reply here.

Meantime, "FOLKS", please let me know if I'm missing something 😉

 

The mode_pin should be connected to a switch and an external pull-up.

And each time the switch (or button) is pushed, mode will change.

001-schematic.JPG

main.c

#include "project.h"

#define MODE_INPUT  0
#define MODE_OUTPUT 1

volatile int sw_flag = 0 ;
int pin_direction = MODE_INPUT ;

CY_ISR(sw_isr)
{
    mode_pin_ClearInterrupt() ;
    sw_flag = 1 ;
}

void init_hardware(void)
{
    isr_1_ClearPending() ;
    isr_1_StartEx(sw_isr) ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */
}

#if 0
In pin_1.h Drive Modes are defined as
        #define Pin_1_DM_ALG_HIZ         (0x00u) /**< \brief High Impedance Analog   */
        #define Pin_1_DM_DIG_HIZ         (0x01u) /**< \brief High Impedance Digital  */
        #define Pin_1_DM_RES_UP          (0x02u) /**< \brief Resistive Pull Up       */
        #define Pin_1_DM_RES_DWN         (0x03u) /**< \brief Resistive Pull Down     */
        #define Pin_1_DM_OD_LO           (0x04u) /**< \brief Open Drain, Drives Low  */
        #define Pin_1_DM_OD_HI           (0x05u) /**< \brief Open Drain, Drives High */
        #define Pin_1_DM_STRONG          (0x06u) /**< \brief Strong Drive            */
        #define Pin_1_DM_RES_UPDWN       (0x07u) /**< \brief Resistive Pull Up/Down  */
#endif

int main(void)
{
    init_hardware() ;

    for(;;)
    {
        if (sw_flag) {
            if (pin_direction == MODE_INPUT) {
                pin_direction = MODE_OUTPUT ;
                Pin_1_SetDriveMode(Pin_1_DM_STRONG) ;                
            } else { 
                pin_direction = MODE_INPUT ;
                Pin_1_SetDriveMode(Pin_1_DM_DIG_HIZ) ;
            }
            sw_flag = 0 ;
        }
    }
}

 

moto

View solution in original post

10 Replies
Raj_C
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 replies posted

Hi @newelectronic1,

In PSoC Creator, the GPIO pin can be initialised as an input and output pin in the TopDesign tab.

Please, refer to the PSoC 4 PDL API reference manual for usage:

  • Initialise desired GPIO pin using following API:

            Cy_GPIO_Pin_Init  (GPIO_PRT_Type  *base, uint32_t pinNum, const cy_stc_gpio_pin_config_t  *config)

  • For writing the data using GPIO pin use following API:

            Cy_GPIO_Write  (GPIO_PRT_Type  *base, uint32_t pinNum, uint32_t value)

  • For reading the data use the following API:

            Cy_GPIO_Read  (const GPIO_PRT_Type  *base, uint32_t pinNum)

Please, let us know if you need further clarification.

Thank you

Best Regards

Raj Chaudhari

0 Likes

Dear,

Thnaks your feedback.How I add PDL?bec. I have   error  that I use  Cy_GPIO_Pin_Init function.

like  file cy_gpio.h

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I just tried to create a project to test it.

Since I don't have a test hardware I could not test it.

So in case it does not work please reply here.

Meantime, "FOLKS", please let me know if I'm missing something 😉

 

The mode_pin should be connected to a switch and an external pull-up.

And each time the switch (or button) is pushed, mode will change.

001-schematic.JPG

main.c

#include "project.h"

#define MODE_INPUT  0
#define MODE_OUTPUT 1

volatile int sw_flag = 0 ;
int pin_direction = MODE_INPUT ;

CY_ISR(sw_isr)
{
    mode_pin_ClearInterrupt() ;
    sw_flag = 1 ;
}

void init_hardware(void)
{
    isr_1_ClearPending() ;
    isr_1_StartEx(sw_isr) ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */
}

#if 0
In pin_1.h Drive Modes are defined as
        #define Pin_1_DM_ALG_HIZ         (0x00u) /**< \brief High Impedance Analog   */
        #define Pin_1_DM_DIG_HIZ         (0x01u) /**< \brief High Impedance Digital  */
        #define Pin_1_DM_RES_UP          (0x02u) /**< \brief Resistive Pull Up       */
        #define Pin_1_DM_RES_DWN         (0x03u) /**< \brief Resistive Pull Down     */
        #define Pin_1_DM_OD_LO           (0x04u) /**< \brief Open Drain, Drives Low  */
        #define Pin_1_DM_OD_HI           (0x05u) /**< \brief Open Drain, Drives High */
        #define Pin_1_DM_STRONG          (0x06u) /**< \brief Strong Drive            */
        #define Pin_1_DM_RES_UPDWN       (0x07u) /**< \brief Resistive Pull Up/Down  */
#endif

int main(void)
{
    init_hardware() ;

    for(;;)
    {
        if (sw_flag) {
            if (pin_direction == MODE_INPUT) {
                pin_direction = MODE_OUTPUT ;
                Pin_1_SetDriveMode(Pin_1_DM_STRONG) ;                
            } else { 
                pin_direction = MODE_INPUT ;
                Pin_1_SetDriveMode(Pin_1_DM_DIG_HIZ) ;
            }
            sw_flag = 0 ;
        }
    }
}

 

moto

Hi, Thanks for your feedback.I will check.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Although I hope that you have already got them, just in case you have not,

I would strongly recommend you to download the following documentations.

PSoC 4000 Family PSoC 4 Architecture Technical Reference Manual (TRM)

file:///C:/Users/700650/Documents/Cypress/Docs/PSoC/PSoC4/PSoC4000/001-89309_PSoC_4000_Family_PSoC_4...

PSoC 4000 Family PSoC 4 Register Technical Reference Manual (TRM)

https://www.infineon.com/dgdl/Infineon-PSoC_4000_Family_PSoC_4_Registers_Technical_Reference_Manual_...

 

For the controlling direction of a GPIO pin, please refer to the  Architecture TRM 7. I/O System.

Especially Figure 7-2. I/O Cell Architecture in PSoC 4000, will give us information about which register(s) we may need to modify when changing the behavior of the pin.

002-IO_Cell.JPG

But to begin with, please check if my sample was enough for your purpose or not 😉

moto

BiBi_1928986
Level 7
Level 7
First comment on blog 500 replies posted 250 replies posted

Hello.

I used a Control Register component to set the direction of GPIO pin.  The GPIO was configured in Creator as input/output so GPIO is controlled with normal function calls after setting the direction you desire with Control Register component.  No need to program low level registers.

That said, if the device is using Smart/IO, then ignore what I just suggested.

0 Likes

Dear , Thanks for your feedback. I  have no  control resister component  feedback. Can you pls share example?

0 Likes

Hi.

The Control Register component uses UDB blocks.  Does your PSoC have UDB blocks?  Please provide PSoC part number.

0 Likes

Hi, No,I havn't UDB block.My Psoc version numberr 4.2

0 Likes

Hello.

You'll need to follow advice from  Moto.

Good luck with your project.

0 Likes