1

I am getting the following error when using the identifier DDRB:

identifier "DDRB" is undefined

But, when I click “go to definition”, the IDE does shows that it can find them. The code also compiles without any problem. I was using VScode first and setting intellisense to "tag parser" did work, but it also got rid of the error checking. So, I switched over to Visual Studio, but the issue remains. In both cases I included the AVR library.

I have googled quite a bit and found some solutions, but most were outdated or did not work. What can I do to resolve this issue?

"minimal reproducible example:"

#include <avr\io.h>

int main() {

    DDRB |= (1 << DD3);

}
Luuk Wuijster
  • 5,668
  • 6
  • 23
  • 49

1 Answers1

1

I can reproduce same issue in VS2017, and this one can be resolved by adding the #define __AVR_ATmega32U4__ above the #include <avr\io.h> like this:

#define __AVR_ATmega32U4__ 
#include <iostream>
#include <avr/io.h>
int main()
{
    DDRB |= (1 << DD3);
}

After adding the macro definition, VS Intellisense option can recognize them well and the issue goes away. More details refer to Kissiel's reply. Thanks to him!

LoLance
  • 18,434
  • 1
  • 12
  • 39