Enable/Disable an Input Pin In Firmware - KBA230122

Version 2

    Version: **

     

    Translation - Japanese: ファームウェアの入力ピンを有効/無効にする - KBA230122 - Community Translated (JA)

     

    Each port has an associated GPIO_PRTx_PC2 register. Individual bits of the register correspond to one of the pins of the port. Setting and unsetting the particular bit can be used for enabling or disabling the input buffer associated with that pin. Disabling the input buffer is one of the methods to disable the input pin.

    See the PSoC 4000S Register TRM for details of the port configuration register.

    The following example demonstrates this:

    In this example, you disable the Rx pin of an SCB Component configured as UART. While transmitting data, disabling the pin disables the reception of data as follows:

    1. Double-click on the UART Component to open the configuration box and configure the direction as TX+RX as shown in Figure 1. Attach the digital input pin (RX) to rx_in of the Component.

     

    Figure 1. Configurator Settings for the UART Component

      

    2.    Look for the UART_RX pin of the device being used. In this case, you have used P3[0]. To disable the input buffer, you need to clear Bit 0 of the GPIO_PRT3_PC2 register. Figure 2 shows the functionality of different bits of GPIO_PRTx_PC2.

    Figure 2. Functionality of Different Bits of the GPIO_PRTx_PC2 Register

     

     

    3.    Disable the input buffer of the UART_RX pin during runtime by clearing Bit 0 of Port 3 in firmware using the following code:

        uint32 temp_reg_val;                                                                                                        // initialize a variable.

        temp_reg_val  =  CY_GET_REG32(CYREG_GPIO_PRT3_PC2);                // to disable the input buffer OF P3[0], RX_PC2 is used.

        uint32 temp_reg_original  =  temp_reg_val;                                                     // storing the initial value of register.

        temp_reg_val  =  temp_reg_val | (0x01<<RX_SHIFT);                                   // disabling the PIN 3[0] which is the RX pin for UART.

    //  RX_SHIFT corresponds to the pin number(here, pin 0) of port.

        CY_SET_REG32(CYREG_GPIO_PRT3_PC2, temp_reg_val);               // setting the register with disable condition for RX pin.

     

    4.    Enable the input buffer by loading the GPIO_PRT3_PC2 register with its initial value as follows:

     

    CY_SET_REG32(CYREG_GPIO_PRT3_PC2, temp_reg_original);                                   //restoring the original value of register.

     

    Figure 3 shows the detailed code snippet.

    Figure 3. Code snippet to disable and enable a pin in firmware