Reduce ATSAMD21 MCU clock Speed from 48Mhz to 2Mhz

Dear all , hope you are doing fine ,

in most of my projects I always look for low power MCU , the ATSAMD21 great MCU , my main issue is to switching 48Mhz to 2Mhz , I don't want to use USB communication ,(USB good for me for just Uploading FW)

when I use this code

GCLK->GENDIV.reg = GCLK_GENDIV_DIV(24) |         // Divide the 48MHz clock source by divisor 24: 48MHz/24=2MHz
                   GCLK_GENDIV_ID(0);            // Select Generic Clock (GCLK) 0

yes the clock speed go down and power consumption go down :slight_smile: , but the main issue all other Communication protocols effected with this change such as SPI , I2C and UART and it not work properly :expressionless: , any advices her will apricated

thank you all

regards

any help please her

Hi @dhddhd2017

It's possible to change the SAMD21's clock frequency, however the Arduino core code is designed to function at 48MHz. As you mention, if you change the main clock frequency all associated peripherals such as SPI, I2C and Serial are affected. In addition, the timing functions delay(), millis() and micros() are adversely affected as well.

If you need to save power, it's easier to run the microcontroller as full speed while active then activate sleep mode when the processor isn't required. This can be achieved using a library, such as Adafruit's Watchdog Timer (WDT) based Adafruit_SleepyDog, or Arduino's Real Time Clock (RTC) based RTCZero.

apricate you replay

thank you