0

I want to run my 32u4 in 2MHz. According to gammon I will gain 4mA in runtime. To my understanding this changes all the buses speed like UART, USB?, I2C?** and SPI?*. Probably I will have problems to solve since I have connected devices on all buses. Most importantly I am afraid that I will loose the connection to re-program it via USB (adafruit feather 32u4).

So, the bootloader will be fine if clock_prescale_set(clock_div_4); after reset of the device or I need ISP programming to re-gain access?

I don't want - currently - to play with fuses.

* for example SPI currently works with SPISettings(4000000,...) so I suppose I will have to use 1Mhz since 2Mhz would be on the limit?

** I2C is at 100Khz in arduino. So my 2Mhz μCU should be fine?

asked Jan 19 at 18:01
2
  • 1) USB needs a clock of 48MHz, if you want to maintain the access to the USB, the PLL prescaler (see Figure 6-1. Clock Distribution of ATmega32U4 datasheet) must be either 8MHz or 16MHz, so you can only have clock_prescale_set(clock_div_2) if you need USB port. 2) The max speed of SPI is F_CPU/2 or F_CPU/4 for SPI slave. All those information are available in the datasheet. Commented Jan 20 at 1:04
  • Indeed only _div_2 is suitable. But mind you this is 4Mhz, not 8Mhz. SPI just works, I didn't changed anything. I went down to _div_32 Commented Mar 16 at 9:09

1 Answer 1

1

If I use clock_prescale_set in my sketch I will loose access to adafruit feather 32u4?

TL;DR: The answer is "no."


All data sheet references base on this version. You need to study it and to do some careful experiments to learn how it works actually.

To my understanding this changes all the buses speed like UART, USB?, I2C? and SPI?.

This is only true for all named peripherals but USB. Figure 6.1 shows the clock system.

The USB module needs a clock of 48 MHz (chapter 21.2) that is generated via a PLL from an 8 MHz input clock.

As figure 6.1 shows, the PLL taps the clock before the prescaler for the system clock. Therefore, you can use any prescaler divider you want, it does not change the USB clock. (If you use USB in your application at all.)

Most importantly I am afraid that I will loose the connection to re-program it via USB (adafruit feather 32u4).

As the bootloader runs before your application, the latter does not change clock settings of the former. So, no, your bootloader will continue to work.

So, the bootloader will be fine if clock_prescale_set(clock_div_4); after reset of the device or I need ISP programming to re-gain access?

A reset will also reset registers, specifically CLKPS[3..0] will be 0000 or 0011, depending on fuse CKDIV8 (chapter 6.11.4).

See above, the bootloader will be fine. It will set its own values where necessary.

for example SPI currently works with SPISettings(4000000,...) so I suppose I will have to use 1Mhz since 2Mhz would be on the limit?

The SPI uses a prescaler that divides at least by 2. If you want to use a system clock of 2 MHz, the fastest SPI clock will be 1 MHz (fOSC/2) if you use SPI master mode. In SPI slave mode, the SPI clock can be at max 500 kHz (fOSC/4).

Chapter 17 has all the details.

I2C is at 100Khz in arduino. So my 2Mhz μCU should be fine?

According to chapter 20.5.2, the maximum SCL frequency is fOSC/16. So 100 kHz is possible.


Note: In the first version of my answer I was under the impression that the questioner planned to swap the external crystal. That was my mistake.

answered Jan 20 at 11:01
4
  • Thank you for the analytical answer and the references to datasheet. Wow, it seems it's a master game that. Sorry, I didn't realized that those info are on datasheet although I read it for other reasons. I had the hope that bootloader had his own divider command for defaults to not loose access. Thank you again. Commented Jan 21 at 4:42
  • 1
    @krg Sorry for the inconvenience, I misread your question. Actually it is the other way, so just go ahead and save some current. Commented Jan 21 at 7:33
  • No worries. You where very helpful even with wrong assumption. So no risks involved, since the bootloader will reset the clock_divider. Great! The problem I see is that I have to change UART bps speed - one used for debugging and other for GPS - and possibly SPI and I2C for other peripherals. Maybe the modules don't support different speeds. THANK YOU! Commented Jan 22 at 9:37
  • Today I managed to test and everything went almost fine. In adafruit feather 32u4 I loose debuging serial with all dividers except _div_2. I also loose UART connection. I tried 9600 * 2 baud rate but the connection is not reliable. But with another device with FTDI serial I went down to _div_32. UART not tested. But SPI is working without any modification. I2C untested. I went from 12mA to 1.6mA. That's great. @the busybee: THANK YOU! Commented Mar 16 at 9:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.