brabl2 / narcoleptic

Sleep library for Arduino (compatible with arduino-tiny core)
58 stars 19 forks source link

PRR not declared - ArduinoIDE 1.8.1 #12

Closed Cysign closed 3 years ago

Cysign commented 7 years ago

C:\ProgrammeKonsistent\arduino-1.8.1\libraries\narcoleptic-master\Narcoleptic.cpp: In member function 'void NarcolepticClass::disableWire()':

C:\ProgrammeKonsistent\arduino-1.8.1\libraries\narcoleptic-master\Narcoleptic.cpp:256:3: error: 'PRR' was not declared in this scope

PRR |= _BV(PRTWI);

vap0rtranz commented 7 years ago

I got this same error when switching to a Yun and rebuilding. I had not gotten the error for a Uno. Which board are you buliding for?

brabl2 commented 7 years ago

Hi, The narcoleptic library is not compatible with Arduino Yun/Leonardo at this moment. These new boards are based on ATmega32U4 chip. According to the ATmega16U4/32U4 Datasheet this chip has not PRR register. It has two registers PRR0 and PRR1. All bits defined in PRR0 looks to be compatible with PRR.

So as a quick hack you can add following code to the Narcoleptic.cpp file / line 26:

#if !defined(PRR) && defined(PRR0)
#define PRR PRR0
#endif

And, please let me know if it works for you.

The PRR0 register contains PRTWI, PRTIM0, PRTIM1, PRSPI, PRADC The PRR1 register contains PRUSB, PRTIM3, PRTIM4, PRUSART1

This is strange: It looks that this chip does not have TIMER2 and it has only one USART, which is named USART1

All power reduction features from PRR0 register should be fully functional in narcoleptic library. Power reduction features from PRR1 register are not supported, you can add them to the library by yourself or use some other power saving library which supports ATmega16U4/32U4.

vap0rtranz commented 7 years ago

I tried your code, adding PRR0 macro to my local Narcoleptic library, and yes -- it now builds against Yun. The library also still builds against Uno with the change (so no regression).

Cysign commented 7 years ago

I got this issue on an AtMega2560.

brabl2 commented 7 years ago

The ATmega640/1280/1281/2560/2561 case is similar as the previous one. It has two registers PRR0 and PRR1. All bits defined in PRR0 looks to be compatible with PRR. The PRR0 register contains PRTWI, PRTIM0, PRTIM1, PRTIM2, PRSPI, PRADC, PRUSART0 The PRR1 register contains PRTIM3, PRTIM4, PRTIM5, PRUSART1, PRUSART2, PRUSART3

You can also use the code from previous post.

Cysign commented 7 years ago

Any chance this could be automated depending on the µC somebody is using?

JonSilver commented 6 years ago

I've forked doc62's improved fork of this library to my company's account in order to extend its functionality to support AVRs with PRR0 & PRR1 registers and additional peripherals like PTC. For our purposes this means the ATmega328pb. If anyone else would like to contribute mods to support other MCUs, they'd be very welcome.

brabl2 commented 5 years ago

All PRR, PRR0 and PRR1 registers should be handled correctly now (commits c0e6853 and 61571d7).