8 Replies Latest reply on Jan 21, 2019 5:28 PM by JuMo_1762556

    How to use RTS of UART0 as GPIO

    JuMo_1762556

      I am using WICED-Studio-6.1 on CYW943907AEVAL1F platform.

      We want to use RTS of UART0 (UART0_RTS_OUT:A53) as GPIO.

      For example, please teach me how RTS is fixed to high during transmission in apps/snip/uart/uart.c .

        • 1. Re: How to use RTS of UART0 as GPIO
          GauravS_31

          If you want to use RTS of UART0 as GPIO, first check in the datasheet the pin multiplexing of UART0_RTS. It is multiplexed with GPIO_11, GPIO_7 and GPIO_15. If we select GPIO_11 for instance, check the platform pin mapping table in platform.c. The GPIO_11 is mapped to WICED_GPIO_7. In your application code, initialize the GPIO using wiced_gpio_init(WICED_GPIO_7, OUTPUT_PUSH_PULL). The second parameter in the API is pin configuration which you can modify based on your requirement.

          • 2. Re: How to use RTS of UART0 as GPIO
            JuMo_1762556

            Thank you for answer.

            I changed the code as follows but I couldn't see the results.

            I monitored J6 pin24 (UART0_RTS_OUT) of CYW943907AEVAL1F by oscilloscope.

            I appreciate any helps.

             

            /******************************************************

            *               Variable Definitions

            ******************************************************/

             

            wiced_uart_config_t uart_config =

            {

                .baud_rate    = 115200,

                .data_width   = DATA_WIDTH_8BIT,

                .parity       = NO_PARITY,

                .stop_bits    = STOP_BITS_1,

                .flow_control = FLOW_CONTROL_DISABLED,

            };

             

            wiced_ring_buffer_t rx_buffer;

            uint8_t             rx_data[RX_BUFFER_SIZE];

             

            /******************************************************

            *               Function Definitions

            ******************************************************/

             

            void application_start( )

            {

                 char c;

                 uint32_t expected_data_size = 1;

             

                 /* Initialise ring buffer */

                 ring_buffer_init(&rx_buffer, rx_data, RX_BUFFER_SIZE );

             

                 /* Initialise UART. A ring buffer is used to hold received characters */

                 wiced_uart_init( WICED_UART_2, &uart_config, &rx_buffer );

             

                 wiced_gpio_init( WICED_GPIO_7, OUTPUT_PUSH_PULL ); /* RTS GPIO init */

             

                 /* Send a test string to the terminal */

                 wiced_gpio_output_high( WICED_GPIO_7 ); /* RTS High */

                 wiced_uart_transmit_bytes( WICED_UART_2, TEST_STR, sizeof( TEST_STR ) - 1 );

                 wiced_gpio_output_low( WICED_GPIO_7 ); /* RTS Low */

             

                 /* Wait for user input. If received, echo it back to the terminal */

                 while ( wiced_uart_receive_bytes( WICED_UART_2, &c, &expected_data_size, WICED_NEVER_TIMEOUT ) == WICED_SUCCESS )

                 {

                     wiced_gpio_output_high( WICED_GPIO_7 ); /* RTS High */

                     wiced_uart_transmit_bytes( WICED_UART_2, &c, 1 );

                     wiced_gpio_output_low( WICED_GPIO_7 ); /* RTS Low */

                     expected_data_size = 1;

                 }

            }

            1 of 1 people found this helpful
            • 3. Re: How to use RTS of UART0 as GPIO
              GauravS_31

              Since UART0_RTS is to be used as GPIO, the RTS function must be disabled. Go to platform.c, [WICED_UART_2] and assign .rts_pin=NULL and .cts_pin=NULL.

              • 4. Re: How to use RTS of UART0 as GPIO
                JuMo_1762556

                Thank you again for your input.

                I tried as you wrote but RTS didn't show High.

                Any other modification is needed ?

                • 5. Re: How to use RTS of UART0 as GPIO
                  GauravS_31

                  Can you create a separate application to test only WICED_GPIO_7? You can output the pin high in this application for testing purpose. We need to ensure that the GPIO operation works in isolation.

                  1 of 1 people found this helpful
                  • 6. Re: How to use RTS of UART0 as GPIO
                    JuMo_1762556

                      I made a program only of WICED_GPIO_7 but RTS doesn't change.

                      The program is as follows;

                     

                    /******************************************************

                    *               Function Definitions

                    ******************************************************/

                    #define UART_RTS     (WICED_GPIO_7)

                     

                    void application_start( )

                    {

                    #if 0

                        char c;

                        uint32_t expected_data_size = 1;

                     

                        /* Initialise ring buffer */

                        ring_buffer_init(&rx_buffer, rx_data, RX_BUFFER_SIZE );

                     

                        /* Initialise UART. A ring buffer is used to hold received characters */

                        wiced_uart_init( WICED_UART_2, &uart_config, &rx_buffer );

                     

                        wiced_gpio_init( UART_RTS, OUTPUT_PUSH_PULL ); /* RTS GPIO init */

                     

                        /* Send a test string to the terminal */

                        wiced_gpio_output_high( UART_RTS ); /* RTS High */

                        wiced_uart_transmit_bytes( WICED_UART_2, TEST_STR, sizeof( TEST_STR ) - 1 );

                        wiced_gpio_output_low( UART_RTS ); /* RTS Low */

                     

                        /* Wait for user input. If received, echo it back to the terminal */

                        while ( wiced_uart_receive_bytes( WICED_UART_2, &c, &expected_data_size, WICED_NEVER_TIMEOUT ) == WICED_SUCCESS )

                        {

                            wiced_gpio_output_high( UART_RTS ); /* RTS High */

                            wiced_uart_transmit_bytes( WICED_UART_2, &c, 1 );

                            wiced_gpio_output_low( UART_RTS ); /* RTS Low */

                            expected_data_size = 1;

                        }

                    #else /* temp */

                        wiced_gpio_init( UART_RTS, OUTPUT_PUSH_PULL ); /* RTS GPIO init */

                     

                        while ( 1 )

                        {

                            wiced_gpio_output_high( UART_RTS ); /* RTS High */

                            wiced_rtos_delay_milliseconds( 1000 );

                            wiced_gpio_output_low( UART_RTS ); /* RTS Low */

                        }

                    #endif

                     

                    }

                    • 7. Re: How to use RTS of UART0 as GPIO
                      GauravS_31

                      On analysing further, it is found that the UART0_RTS pin can be either mapped to RTS function or disabled. But it cannot be used as GPIO. You can use any other GPIO pin such as GPIO_15 as GPIO function using the GPIO APIs discussed earlier. Ensure that the GPIO pin is not being used for any other dedicated function in the eval board.

                      1 of 1 people found this helpful
                      • 8. Re: How to use RTS of UART0 as GPIO
                        JuMo_1762556

                        Thank you for the answer.

                        I understood that J6 pin24 (UART0_RTS_OUT) can't be used as GPIO.