Hey guys, I have a custom pcb with an ATSAMD21 device, and added the possibility to connect a debug header that allows to communicate with the microcontroller through a serial connection. So a RX, TX and GND pin are broken out.
When the header is connected to a serial to USB converter, everything works fine. But when the header is not connected, the device is susceptible to noise and probably receives garbage data (noise). Hard to see what it receives, because the debug header is not connected, also scoping grounds the thing, so the noise is gone.
I was wondering if I could solve the problem by enabling an internal pull-up (or down) resistor on the RX pin. I tried these pieces of code:
To set a pin to be pulled up (taken from ASF here):
struct system_pinmux_config config_pinmux;
system_pinmux_get_config_defaults(&config_pinmux);
config_pinmux.mux_position = SYSTEM_PINMUX_GPIO;
config_pinmux.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
config_pinmux.input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
system_pinmux_pin_set_config(PIN_PA23, &config_pinmux); // The RX pin
To initialize the USART module I use this code:
struct usart_config config_usart;
usart_get_config_defaults(&config_usart);
config_usart.baudrate = baud;
config_usart.mux_setting = USART_RX_1_TX_0_XCK_1;
config_usart.pinmux_pad0 = PINMUX_PA22C_SERCOM3_PAD0; // TX
config_usart.pinmux_pad1 = PINMUX_PA23C_SERCOM3_PAD1; // RX
config_usart.pinmux_pad2 = PINMUX_UNUSED;
config_usart.pinmux_pad3 = PINMUX_UNUSED;
while (usart_init(&usart_instance, SERCOM3, &config_usart) != STATUS_OK);
usart_enable(&usart_instance);
When I first do the pin pull up code, the pin is not pulled up and the USART still works. Also, it's still receptable to noise. And when I first do the USART init code, and then the pin pull-up code, the pin is pulled up, but USART does not work anymore...
Is it possible to combine the two pieces of code, or to achieve what I want in another way? The USART code references from ASF don't mention anything about pull-up or down resistors. Or is the only option to change the hardware and add a physical pull-up (or down) resistor?
Thanks in advance.