How to enable multiple USART module in samL21 series

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

Is there any way to enable two serial port in saml21 MCU?

 

My application needed two uart ports one for communicating with PC and another one for display, and both need RX and TX pins requirement. So I done the following in my code in order to enable two USART module

 

 

struct usart_module usart_instance;
enum usart_callback callback_type;

 

void uart2_init(void)
{
    struct usart_config config_usart;
    usart_get_config_defaults(&config_usart);
    config_usart.baudrate    = 9600;
    config_usart.mux_setting = USART_RX_3_TX_2_XCK_3;
    config_usart.pinmux_pad0 = PINMUX_UNUSED;    
    config_usart.pinmux_pad1 = PINMUX_UNUSED;       
    config_usart.pinmux_pad2 = PINMUX_PA18C_SERCOM1_PAD2;    //Tx
    config_usart.pinmux_pad3 = PINMUX_PA19C_SERCOM1_PAD3;    //Rx
//    usart_instance.callback = true;
    
    
    while (usart_serial_init(&usart_instance,
    EXT3_UART_MODULE, &config_usart) != true) {
    }
    usart_enable(&usart_instance);
}

 

void configure_usart(void)
{
//! [setup_config]
    struct usart_config config_usart;
//! [setup_config]
//! [setup_config_defaults]
    usart_get_config_defaults(&config_usart);
//! [setup_config_defaults]

//! [setup_change_config]
    config_usart.baudrate    = 9600;
    config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
    config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;    //Tx
    config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;       //Rx            
    config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
    config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
    
//! [setup_change_config]

//! [setup_set_config]
    while (usart_init(&usart_instance,
            EDBG_CDC_MODULE, &config_usart) != STATUS_OK) {
    }
//! [setup_set_config]

//! [setup_enable]
    usart_enable(&usart_instance);
//! [setup_enable]
}

 

 

But above code not work. it only enable one serial port which I call lately..!

 

please guide me to the right path to use two USART module..

 

Regards,

Mathan JB

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
struct usart_module usart_instance;

You need two instances.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

The L21s have six SERCOMs - they'd be pretty pointless if you could only use one!

 

As always, the secret is to break the problem down into manageable steps - don't try to do everything all at once.

 

Before trying to do two at once, can you get each one working separately?

 

Note that one of them is "special":

 

 

Please see Tip #1 in my signature, below, for how to properly post source code:

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...