3 Replies Latest reply on Feb 21, 2017 4:50 AM by l.bertelli_1513841

    How set UART TX as an Open Drain with Pull-up output in BCM94343W?

    l.bertelli_1513841

      Hi,

      I am working with a combo BCM94343W module, and I would like to use the USART#6 port to interface with a device which has RX and TX shared on the same pin (with half-duplex communication).

      To do this, I need to set the BCM USART#6 TX pin as an output in Open-Drain with pull-up, so I can short it with the RX pin.

      Is there a way to initialize the UART with TX as Open-Drain? I saw that it is possible with GPIO, but I can't find a solution for function pins.

       

      Thanks,

      Lorenzo

        • 1. Re: How set UART TX as an Open Drain with Pull-up output in BCM94343W?
          grsr

          You can modify the parameters output type and pull up/down type in the function platform_gpio_set_alternate_function() in platform_uart.c. We could not test any modifications because we do not have a UART device with RX and TX shared on the same pin. Test the modifications and let us know the results.

          2 of 2 people found this helpful
          • 2. Re: How set UART TX as an Open Drain with Pull-up output in BCM94343W?
            rash

            Hello Lorenzo Bertelli

             

            In addition to Gaurav response, it is very difficult to achieve USART to UART communication where their both operations are different. Shorting the Tx and Rx will create some problems, like reverting the data back to the same controller.

            Please make sure that your requirement is feasible to do so. We don't have any such device to test. 

            1 of 1 people found this helpful
            • 3. Re: How set UART TX as an Open Drain with Pull-up output in BCM94343W?
              l.bertelli_1513841

              Thanks for the info.

              I found the function platform_gpio_set_alternate_function() and I confirm it is the right way. Briefly this is what I did:

               

              // empty the RX buffer

              expected_data_size = ring_buffer_used_space(&rx2_buffer);

              if (expected_data_size > 0)

              {

                wiced_uart_receive_bytes(uart, rxDataBuffer, &expected_data_size,RX_TIMEOUT );

              }

              // configure the UART pin as TX Opend Drain and RX with push-pull

              wiced_uart_reinit(uart);

              // transmit the bytes

              wiced_uart_transmit_bytes(uart, &MemType, 1);

              wiced_uart_transmit_bytes(uart, &Register, 1);

              // configure the TX as a GPIO input, to avoid any interference during the RX phase

              if (uart == WICED_UART_1)

              {

                wiced_gpio_init( WICED_GPIO_9, INPUT_PULL_UP );  // USART6 TX

              }

              else if (uart == WICED_UART_2)

              {

                wiced_gpio_init( WICED_GPIO_13, INPUT_PULL_UP );  // USART6 TX

              }

              // receive the bytes

              expected_data_size = READ_RX_EXPECTED_SIZE;

              wiced_uart_receive_bytes(uart, rxDataBuffer, &expected_data_size, RX_TIMEOUT );

               

              The wiced_uart_reinit function is necessary to restore he TX and RX functionality after having declared the TX pin as GPIO Input during the reception. Here's the code:

               

              platform_result_t platform_uart_reinit( platform_uart_driver_t* driver, const platform_uart_t* peripheral)

              {

                  uint32_t          uart_number;

                  platform_mcu_powersave_disable();

                  uart_number = platform_uart_get_port_number( peripheral->port );

               

                  /* Configure TX and RX pin_mapping */

                  platform_gpio_set_alternate_function( peripheral->tx_pin->port, peripheral->tx_pin->pin_number, GPIO_OType_OD, GPIO_PuPd_UP, uart_alternate_functions[ uart_number ] );

                  platform_gpio_set_alternate_function( peripheral->rx_pin->port, peripheral->rx_pin->pin_number, GPIO_OType_PP, GPIO_PuPd_UP, uart_alternate_functions[ uart_number ] );

               

                  /* Enable both transmit and receive */

                peripheral->port->CR1 |= USART_CR1_TE;

                peripheral->port->CR1 |= USART_CR1_RE;

               

                platform_mcu_powersave_enable();

                  return PLATFORM_SUCCESS;

              }

               

              Obviously as reported by rash the RX buffer will contain also the echo of TX bytes, but it is easy to suppress them and start parsing the answer from the right byte.

              2 of 2 people found this helpful