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

Switching between UART and MUX functionality on the same pins - KBA233908

Switching between UART and MUX functionality on the same pins - KBA233908

Community Manager
Community Manager
Community Manager
250 sign-ins First comment on KBA 250 replies posted

Switching between UART and MUX functionality on the same pins - KBA233908

Community Translation: 同じピンでUARTとMUX機能を切り替える – KBA233908

Version: **

  • Implementation

In this project, the MUX functionality is implemented with a MUX Component in TopDesign.cysch in PSoC™ Creator while for the UART functionality, it is done without the use of the UART Component. The PDL version used is 3.1.4. The necessary source files have been included (see the following) and reused from another project that had the UART Component in TopDesign.cysch.


The program is tested on CY8CKIT-062-WiFi-BT  kit. The P5[0] and P5[1] pins that are UART Rx and Tx pins for SCB_5 respectively are assigned as MUX input and output pins. To keep the design simple, constant 1 was added to the select line to ensure that only these two pins are checked. A GPIO interrupt is used because the switching between UART and MUX functionality is done with the help of the onboard switch P0[4] (SW2) of the CY8CKIT-062-WiFi-BT kit. The implementation is shown in Figure 1.


Figure 1. Switching between UART and MUX

  • Main program flow
    The switching between functionalities takes place through the high-speed input output matrix (HSIOM). With the help of the HSIOM,  Port 5 is configured for the MUX functionality and then switched to connect to the SCB block for the UART functionality. This is handled with the help of code snippets as explained below. See the attached project for details.

    Note: For more information on the configuration of the HSIOM for different component functionalities, see the “Multiple alternate functions” table in the device datasheet and the architecture TRM to learn about HSIOM connections through DSI. Also see the register TRM for the values of HSIOM registers.

    The code snippet for MUX configuration for Port 5 is –

    void reconfigure_MUX_and_DEMUX_to_Port5(){

          /* Connect MUX functionality to pins P5[0] and P5[1] through HSIOM */

          /*            .sel0Active = 0x00000318u */




    The code for UART configuration to Port 5 is –

    void reconfigure_UART1_to_Port5(){   

          /* Connect SCB5 UART function to pins */

          /* Configure pins for UART operation */

          /* Configure clocks for UART operation */
          Cy_SysClk_PeriphAssignDivider(PCLK_SCB5_CLOCK, UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER);

          /* Configure Baudrate for UART operation */
          Cy_SysClk_PeriphSetDivider   (UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER, 35UL);
          Cy_SysClk_PeriphEnableDivider(UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER);


    The toggling of the interrupt flag inside the ISR handles the switching between UART and MUX. Initially, it is set to false, which implies that pins P5[0] and P5[1] are connected to the HSIOM for the MUX functionality. When the onboard switch (SW2) is pressed, the interrupt flag toggles and is set to true, reconfiguring the pins to be connected to the SCB5 block through the HSIOM.

    Interrupt service routine for the GPIO interrupt

    void GPIO0_4_isr_handler ()

         Cy_GPIO_ClearInterrupt(Pin0_4_PORT, Pin0_4_NUM);
         //Your application code
         interrupt_flag = !(interrupt_flag);


  • Testing

    The setup used for testing is shown in Figure 2.

    Initially, the LED is glowing on CY8CKIT-147 kit. The serial terminal is configured for the USB-UART Kitprog3 bridge with the baud rate set to 115200 bps.

    After the device is programmed, the MUX functionality is active because the interrupt flag is initialised to false. To check this, LED at P0[2] on the CY8CKIT-147 is used and is connected to P5[1] i.e., the output pin of the CY8CKIT-062-WiFi-BT kit. The P5[0] pin, being the input pin, is connected to ground. This turns OFF the LED. It clearly implies that ground is being transmitted to P5[1] with the MUX functioning. During this time, no printing takes place on serial terminal.


    Figure 2. Initial setup for testing

    When switch SW2 on the CY8CKIT-062-WiFi-BT board is pressed, “Working in UART mode” is displayed on the serial terminal as shown in Figure 3. This shows that the UART functionality is active. During this time, grounding the P5[0] pin does not stop the LED from glowing, which means that ground is not transmitted to P5[1] and that the MUX is not functional.


    Figure 3. Serial terminal output for UART functionality

    When the switch is pressed again, the printing on serial terminal stops. You can check the MUX functionality as mentioned previously to verify that the pins again behave as input and output pins for the MUX.