Create an USART communication between SAML21J <=> Arduino

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

Hi, I am currently fighting for getting to work an USART communication between the SAML21J and the Arduino, however the only exemple shown of the SERCOM USART is with the USB cable, not with the pin, so I don't really know how to configure the pins to be able to communicate with the Arduino. So here's my code that configures an USART to debug via USB (the config_usart_usb), which works, and also the code that configures the USART pins to communicate with the arduino, which doesn't work :

 

struct usart_module usart_instance_usb;
struct usart_module usart_instance_arduino;

void configure_usart(void)
{

    struct usart_config config_usart_usb;
    struct usart_config config_usart_arduino;
    
    usart_get_config_defaults(&config_usart_usb);
    usart_get_config_defaults(&config_usart_arduino);

    // usb usart (for debug)
    config_usart_usb.baudrate    = 9600;
    config_usart_usb.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
    config_usart_usb.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
    config_usart_usb.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
    config_usart_usb.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
    config_usart_usb.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
    
    // arduino usart
    config_usart_arduino.baudrate    = 9600;
    config_usart_arduino.mux_setting = USART_RX_1_TX_0_XCK_1;
    config_usart_arduino.receiver_enable = true;
    config_usart_arduino.transmitter_enable = true;
    config_usart_arduino.pinmux_pad0 = PINMUX_PB08D_SERCOM4_PAD0;
    config_usart_arduino.pinmux_pad1 = PINMUX_PB09D_SERCOM4_PAD1;
    config_usart_arduino.pinmux_pad2 = PINMUX_UNUSED;
    config_usart_arduino.pinmux_pad3 = PINMUX_UNUSED;

    while (usart_init(&usart_instance_usb,
    EDBG_CDC_MODULE, &config_usart_usb) != STATUS_OK) {
    }

    while (usart_init(&usart_instance_arduino,
    SERCOM4, &config_usart_arduino) != STATUS_OK) {
    }

    usart_enable(&usart_instance_usb);
    usart_enable(&config_usart_arduino);
}

 

This is how I do so that my TX pin is the PB08, and my RX pin is the PB09, but it doesn't work. What dit I miss in my configuration ?

And BTW, why some pins (like the PA08 and PA09) are multiple times on the board ?

 

Anyway, thanks for reading this, I hope that someone will be able to enlighten me on this one.

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

Hi there! The USART that you are trying to use is connected to USB Debugger! Try using other SERCOM pins to interface it with your arduino...

Salman Ali

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

Hi, thanks for the replay, you are talking about "config_usart_usb", but what about my config_usart_arduino ? Is it connected to the debugger too ?

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

Looks okay. But if you are trying to receive the data via interrupt mode then you need to enable interrupts too.

Salman Ali

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

Well, I am not trying to receive the data with the interrupt. I managed to get it to work not, but there is a remaining problem : I figured out that it works only with SERCOM3, which happens to also be the SERCOM of the debugger. So I guess i'm missing something, like... there's is a way to activate the SERCOM's, or maybe two SERCOM's can't work at the same time...

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

can I know what exactly you wanna do ? 

Salman Ali

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

I wanna be able to communicate with my debugger AND an Arduino at the same time, on 2 different Sercom interfaces, but first of all I wanna know if this is possible.

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

You mean like this ?

-------------       USART          ------------
- SAML21 <--------------------> Arduino -
-------------                         -------------

Salman Ali

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

Exactly. But it doesn't work any other SERCOM interface than the SERCOM 3.

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

If USB is must then you can  go for only SERCOM3 ! Otherwise you have plenty of options. 

Salman Ali

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

I know, but unfortunately I can't get it to work on SERCOM1 or SERCOM0. Is there like a special line to activate them ? Can we even make 2 SERCOMs interfaces work at the same time ? Like the SERCOM0 and the SERCOM3 ?

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

I have used 4 sercoms parallely ! There is no problem in running separate SERCOM channels parallely. May be you can try changing configuration for USB-UART bridge (this is the place where we are configuring SERCOM3 as UART)

Salman Ali

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

If you still have the code of the configuration and use of those 4 Sercoms, I would be very interested to take a look at it. :)

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

That is company proprietary so I can't share the code. But ill show you the use of four SERCOM channels.

SERCOM 3 - USB-UART Bridge
SERCOM 4 - UART Logger
SERCOM 1 - Bluetooth UART
SERCOM 2 - GPRS Module  

Salman Ali

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

All I need is really just the configuration of the pins, you know. :p

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

It's fine, I just found my problem : I was configuring the 2 usarts at the same time whereas I should have configured the 1st one, then the other one. Here's the working code, for those who might have the same problem in the future :

 

void configure_usart(void)
{

    // ##### USART ATMEL <===> USB #####

    struct usart_config config_usart_usb;
    usart_get_config_defaults(&config_usart_usb);

    config_usart_usb.baudrate    = 9600;
    config_usart_usb.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
    config_usart_usb.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
    config_usart_usb.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
    config_usart_usb.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
    config_usart_usb.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;

    while (usart_init(&usart_instance_usb,
    EDBG_CDC_MODULE, &config_usart_usb) != STATUS_OK) {
    }

    usart_enable(&usart_instance_usb);
    
    
    // ##### USART ATMEL <===> ARDUINO #####
    
    struct usart_config config_usart_arduino;
    usart_get_config_defaults(&config_usart_arduino);

    config_usart_arduino.baudrate    = 9600;
    config_usart_arduino.mux_setting = USART_RX_1_TX_0_XCK_1;
    config_usart_arduino.pinmux_pad0 = PINMUX_PA08C_SERCOM0_PAD0;
    config_usart_arduino.pinmux_pad1 = PINMUX_PA09C_SERCOM0_PAD1;
    config_usart_arduino.pinmux_pad2 = PINMUX_UNUSED;
    config_usart_arduino.pinmux_pad3 = PINMUX_UNUSED;

    while (usart_init(&usart_instance_arduino,
    SERCOM0, &config_usart_arduino) != STATUS_OK) {
    }

    usart_enable(&usart_instance_arduino);
}

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

Hello,

 

I would like to create an UART communication beetwen ATSAML21 and ATSAMB11. I started followuing the usart quick start callback (to realize the UART communication on SAML21) and Find Me example (on BLE module). Could you help me with this project?
Thanks,

Gennaro