MCUdude / MiniCore

Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB
Other
983 stars 243 forks source link

Incorrect sleep management constants #317

Open ElectricWater96 opened 2 weeks ago

ElectricWater96 commented 2 weeks ago

When attempting to use sleepMode() with an ATmega328P I found that the SLEEP_... macros are defined with incorrect values in the arduino.h file. The values defined range from 0 through 5, but they should be double what they are, due to a missing left bitshift that is required to align their bits with the SM[2:0] bits in the SMCR register. For example, sleepMode(SLEEP_POWER_DOWN) should pass a binary value of 0100 to SMCR, setting the sleep mode to "Power-down", but it passes 0010, which sets the sleep mode to "ADC Noise Reduction".