3

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
  • 6,678
  • 8
  • 30
  • 58

2 Answers2

3

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
  • 25,666
  • 1
  • 39
  • 73
3

If you don't want to paste this definition into almost every file:

  1. press f1
  2. find C/C++; Edit configurations (UI)
  3. paste your mcu name in Defines section e.g __AVR_ATmega32U4__

It worked for me in vs code.

gicher
  • 61
  • 4