USART issue, ATSAMd51G19A, no data being transmitted

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


Hello All,

I am stuck sending a message from my ATSAMD51G19A from TX to RX. As shown in snippet below, it warns (with yellow) when I assign pins ( after line 60).I am certain about the rx and tx pins as shown at the end of the question. Please help me why there is no data being transmitted?

#include <sam.h>

#include <stdio.h>

#define baud_rate 9600

char* string = "Hello World";

int i=0,length = 11;

 

//#define LED

#define LED_BIT 22  

#define LED_PIN (1 << LED_BIT)

#define LED_PORT 0

//#define RX

#define RX_BIT 16

#define RX_PIN (1 << RX_BIT)

#define RX_PORT 0

//#define TX

#define TX_BIT 17

#define TX_PIN (1 << TX_BIT)

#define TX_PORT 0

static volatile int ticks = 0;

extern "C" void SysTick_Handler(void)

{

  ticks++;

  if (ticks == 1000)

    {

      // Turn LED on

      PORT->Group[LED_PORT].OUTCLR.reg = LED_PIN;

    

    }

  else if (ticks == 2009)

    {

      // Turn LED off

       

       PORT->Group[LED_PORT].OUTSET.reg = LED_PIN;

      ticks = 0;

    }}

int main(int argc, char *argv[])

{  // Configure LED

//SystemInit();

  SERCOM3->USART.CTRLA.bit.ENABLE=0;

 // SERCOM0->USART.DATA.bit=1;

  PORT->Group[LED_PORT].OUTSET.reg = LED_PIN;

  PORT->Group[LED_PORT].DIRSET.reg = LED_PIN;

  PORT->Group[LED_PORT].PINCFG[LED_BIT].reg = 0;



  // Enable SysTick timer interrupt

  //SysTick->LOAD = (SystemCoreClock / 1000) - 1;

  //SysTick->VAL = 0;

  //SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;



 //config SERCOM to USART

     SERCOM3->USART.CTRLA.bit.ENABLE = 0; // disable USART

     

     SERCOM3->USART.CTRLA.bit.MODE =1; // set clock mode to internal clock

     SERCOM3->USART.CTRLA.bit.CMODE = 0; // set clock to be Asynchronous with bus clk 

    

     SERCOM3->USART.CTRLA.bit.RXPO = 25; // select Rx pin to be PAD[1]

     SERCOM3->USART.CTRLA.bit.TXPO = 26; // select Tx pin to be PAD[0]

     SERCOM3->USART.CTRLA.bit.DORD = 0; // set data order (MSB first) /i changed from 1 to 0

     SERCOM3->USART.CTRLA.bit.FORM = 1; //frame settings enable

     

     SERCOM3->USART.CTRLB.bit.CHSIZE = 1; // config the char size field to 8 bit

     SERCOM3->USART.CTRLB.bit.PMODE = 1; // set parity mode to odd

     SERCOM3->USART.CTRLB.bit.SBMODE = 0; // config the number of stop bits to 1

     

     SERCOM3->USART.BAUD.bit.BAUD =  SystemCoreClock/baud_rate;

     SERCOM3->USART.INTENSET.bit.TXC = 1; // enable Transmit complete interrupt

     SERCOM3->USART.CTRLB.bit.RXEN = 1; // enable Receiver

     SERCOM3->USART.CTRLB.bit.TXEN = 1; // enable transmitter

     SERCOM3->USART.CTRLA.bit.ENABLE = 1; // enable USART module



     SERCOM3->USART.CTRLC.bit.DATA32B= 1; // 32 bit extension

      

     while (SERCOM3->USART.SYNCBUSY.bit.ENABLE == 1); // wait for USART to be enabled

     //SERCOM3->USART.DATA.bit.DATA = string[i];// send first char

  while (1)

 {

      SERCOM3->USART.DATA.bit.DATA = string[i];// send next char

//printf("%d", string[i]);

     

     

printf("%d", SERCOM3->USART.INTFLAG.bit.RXS);

//printf("%d", SERCOM3->USART.DATA.bit.DATA);

      i++; // increment byte count

      //printf(" not here!*");

      if(i == length) // if it is the last char - reset count

      {

          i = 0; // reset byte count

          printf("done/n");

      }

      SERCOM3->USART.INTENSET.bit.TXC = 1; // enable Transmit complete interrupt

       

     // printf("done");

  }

  

}

 

 

 

RX/TX pins:

 

 

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

You need to learn about pad vs pin when it comes to assigning a pin for use with a peripheral such as SERCOM. You could start by looking at "6.1 Multiplexed Signals" and then how PA16/17 are described in "Table 6-1. Multiplexed Peripheral Signals".

Then check how RXPO and TXPO are described (a good hint about your problem is that both the RXPO and the TXPO field are only 2 bits).

/Lars

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


Thank you very much!

 

However, I already was using correct PADs.

 

 

 

PA16 is pin 25 of QFN48, and PA17 is pin 26 of QFN48 (my architecture). Note that I am using sercom3 and also, for my board there are specialized pins for RX and TX.

Last Edited: Wed. Jun 12, 2019 - 08:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, compare the assignment here

     SERCOM3->USART.CTRLA.bit.RXPO = 25; // select Rx pin to be PAD[1]

     SERCOM3->USART.CTRLA.bit.TXPO = 26; // select Tx pin to be PAD[0]

with the description (and possible values) of RXPO and TXPO.

/Lars

 

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

Lars, thank you ;)

 

I used your advice and that problem is solved, however, there is an issue related to the clock. In the watch window I see that GCLK or MCLK are not changing ( lots of 0s!). I am trying reading relevant chapter (14, GCLK) to add proper enabling code to this (from first comments of this thread) but since my chip is different, I think I need to do some digging into the data sheet. None of lines A,B,C, D were working so I had to comment them out.

 

 // enable GCLK for SERCOM3
    REG_GCLK_PCHCTRL22= GCLK_PCHCTRL_GEN_GCLK0 | GCLK_PCHCTRL_CHEN;
   // NVIC_EnableIRQ(SERCOM3_IRQn); // enable interrupt    line A
   //  MCLK->APBCMASK.bit.SERCOM3_ = 1;                          line B
  //  MCLK->APBAMASK.bit.OSCCTRL_ = 1;                               line C
//MCLK->APBCMASK.bit.SERCOM3_ = 1;                             line D
     MCLK->APBAMASK.bit.OSCCTRL_ = 1;

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

Everyone,

 

Please let me know the proper way to activate/ setup mu GCLK for ATSAMD51G19A.

 

Thank you!

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

Thanks. Problem is solved.

Last Edited: Mon. Jun 24, 2019 - 07:17 PM