ESP-C3 TWAI module on GPIO18 and GPIO19

marchino81
Posts: 2
Joined: Mon Jul 19, 2021 7:42 am

ESP-C3 TWAI module on GPIO18 and GPIO19

Postby marchino81 » Mon Jul 19, 2021 8:18 am

Hello,
We are developing an electronic control unit that integrates your ESP-C3 module and maps the TWAI module on GPIO18 and GPIO19.
If we use GPIO18 as Rx and GPIO19 as Tx all seems good, we are able to transmit and receive CAN messages to/from the bus.If we use GPIO18 as Tx and GPIO19 as Rx, we can only transmit, but we can't see any received messages.
In the reference manual there is a NOTE:"USB - GPIO18 and GPIO19 are USB pins. The pull-up value of the two pins are controlled by the pins’pull-up value together with USB pull-up value. If any one of the pull-up value is 1, the pin’s pull-up resistorwill be enabled. The pull-up resistors of USB pins are controlled by USB_SERIAL_JTAG_DP_PULLUP"
Do we need to add some extra code to control the pin pull-up value ?Can we have more information about USB_SERIAL_JTAG_DP_PULLUP register ?
In addition we have checked in the esp-idf code and in the gpio_ll.h file, we have found this:
/*
 * The following defines are used to disable USB JTAG when pins 18 and pins 19
 * are set to be used as GPIO.
 * See gpio_pad_select_gpio() below.
 *
 * TODO: Delete these definitions once the USB device registers definition is
 * merged.
 */
#define USB_DEVICE_CONF0_REG        (0x60043018)
#define USB_DEVICE_USB_PAD_ENABLE   (BIT(14))

/**
 * @brief  Select a function for the pin in the IOMUX
 *
 * @param  pin_name Pin name to configure
 * @param  func Function to assign to the pin
 */
static inline void gpio_ll_iomux_func_sel(uint32_t pin_name, uint32_t func)
{
    if (pin_name == IO_MUX_GPIO18_REG || pin_name == IO_MUX_GPIO19_REG) {
        CLEAR_PERI_REG_MASK(USB_DEVICE_CONF0_REG, USB_DEVICE_USB_PAD_ENABLE);
    }
    PIN_FUNC_SELECT(pin_name, func);
}

Adding gpio_hal_iomux_func_sel(IO_MUX_GPIO19_REG, PIN_FUNC_GPIO);before twai_driver_install(....) doesn't have an effect on the CAN.

Dazza0
Espressif staff
Espressif staff
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: ESP-C3 TWAI module on GPIO18 and GPIO19

Postby Dazza0 » Mon Jul 19, 2021 11:57 am

@marchino81

Try only calling

Code: Select all

CLEAR_PERI_REG_MASK(USB_DEVICE_CONF0_REG, USB_DEVICE_USB_PAD_ENABLE);
before calling

Code: Select all

twai_install()
.

marchino81
Posts: 2
Joined: Mon Jul 19, 2021 7:42 am

Re: ESP-C3 TWAI module on GPIO18 and GPIO19

Postby marchino81 » Mon Jul 19, 2021 1:46 pm

Hi,

I've tried updating esp-idf and adding

Code: Select all

CLEAR_PERI_REG_MASK(USB_DEVICE_CONF0_REG, USB_DEVICE_USB_PAD_ENABLE);
on twai self test example and I confirm that I'm able to receive on GPIO19.

But if I configure the TWAI as TWAI_MODE_NORMALMODE or TWAI_MODE_LISTEN_ONLY like:

Code: Select all

static const twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMALMODE);
static const twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_LISTEN_ONLY);
using a real physical tranceiver connected to the board, I'm NOT able to receive the messagges on GPIO19 (The CAN analyzer indicate a Stuff Error "CAN Error RxErr ECC: 10100010, Stuff Error, Segment = ID28-ID21 " and afeter a BUS-OFF)

NOTE: Configuring RX_GPIO_NUM as GPIO4, I'm able to receive all messagges from the CAN bus.

Who is online

Users browsing this forum: PerplexityBot, PetalBot, Semrush [Bot] and 4 guests