uart malfunction when 'OR'ing CLKCTRL register

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

Hi

I was writing a program for SAMD21J18 mcu(xplained pro) where I had to initialize the value for General Clock control register.

In my config,48MHz clock is output of GCLK0.Now I am feeding the GCLK0 output to peripheral(for pin 22Tx/23Rx under Sercom3).Now everything is working fine when I am assigning the value like this:

GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN| //Clock enable bit high
						GCLK_CLKCTRL_GEN_GCLK0| //GCLK0 as Clock source
						GCLK_CLKCTRL_ID(GCLK_CLKCTRL_ID_SERCOM3_CORE_Val);//Clock for Sercom3

But whenever I am assigning using 'OR' operator like this below

GCLK->CLKCTRL.reg |= GCLK_CLKCTRL_CLKEN| //Clock enable bit high
						GCLK_CLKCTRL_GEN_GCLK0| //GCLK0 as Clock source
						GCLK_CLKCTRL_ID(GCLK_CLKCTRL_ID_SERCOM3_CORE_Val);//Clock for Sercom3

the output in the Terminal changes into Garbage.....Why this is happening??

This topic has a solution.
Last Edited: Wed. Jul 24, 2019 - 01:57 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The register can't be read like "normal" registers can (reading is needed for |=).

For example, the sequence to read the GENCTRL register of generic clock generator i is:
1. Do an 8-bit write of the i value to GENCTRL.ID
2. Read the value of GENCTRL

/Lars 

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

Thanks a lot for the nice explanation.....

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

Can you please tell me where i can find some good quality bare metal programming info for SAMD21(without using ASF/Arduino code)?

My primary AIM is to to use it as a DIY wristwatch's main chip.It will drive a 128x64 OLED & tell time when a switch is pressed(either connected to reset/external interrupt pin).Also,it should communicate with Serial over USB to set Time from any Terminal software.

Normally,the chip will be in deep sleep mode & should wake up only when USB is plugged or when external interrupt switch/reset switch pressed!

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

SHARANYADAS wrote:
Can you please tell me where i can find some good quality bare metal programming info for SAMD21(without using ASF/Arduino code)?

 

I dare say most of us would just work from the datasheet.