I'm trying to use VScode for Arduino Uno early development. I'd like to use intellisense but in the "Problems tab" it shows me errors:
identifier "DDRD" is undefined
identifier "PIND" is undefined
identifier "PORTD" is undefined
identifier "PORTD" is undefined
I can compile and upload the code flawlessly and it works.
I read everywhere that the solution to this is adding at the very top of the code the macro definition of the microcontroller, but it seems that this doesn't work for me only.
This is my code
#define __AVR_ATmega328P__
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
int switchState = 0;
DDRD &= ~(1 << 2);
DDRD |= 1 << 3;
DDRD |= 1 << 4;
DDRD |= 1 << 5;
for (;;) {
switchState = 0x01 & (PIND >> 2);
if (!switchState) {
PORTD |= 1 << 3;
PORTD &= ~(1 << 4);
PORTD &= ~(1 << 5);
} else {
PORTD &= ~(1 << 3);
PORTD &= ~(1 << 4);
PORTD |= 1 << 5;
_delay_ms(250);
PORTD |= 1 << 4;
PORTD &= ~(1 << 5);
_delay_ms(250);
}
}
return 0;
}
If I right-click a DDRD underlined macro and select "Go to definition" it brings me to the DDRD macro definition in io76c711.h, while I expect been redirected in iom328p.h, because io.h contains
#elif defined (__AVR_ATmega328P__)
# include <avr/iom328p.h>
It seems that AVR_AT76C711 is defined somewhere else but I can't wonder where.
Do you have any suggestion? I also post my c_cpp_properties.json if there is something wrong in the one generated by the VScode Arduino extension
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\Program Files (x86)\\Arduino\\tools\\**",
"D:\\Arduino\\libraries\\**",
"C:\\Program Files (x86)\\Arduino\\libraries\\**",
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\**",
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**"
],
"forcedInclude": [
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
],
"defines": [
"USBCON"
],
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14"
}
],
"version": 4
}