0

On Arduino I can set digital pins by setting special variables PORTB and PORTD (or maybe they are not variables?). Where are those variables defined? I grepped /usr/share/arduino, but found nothing.

grep -r 'PORTB' /usr/share/arduino/
3

PORTB is defined by the "toolchain". It is not defined by Arduino. For instance in my setup the Arduino Uno uses "toolchain" avr-gcc\4.9.2-amtel3.5.3-arduino2\avr.

If you grep that folder (location dependent on tool and installation options) you will find a file called iom328p.h that defines

#define PORTB _SFR_IO8(0x05)

This is a mapping to a physical address of the cpu.

  • Thank you. And how does this file gets included when my program is compiled and linked? Is it included by Arduino.h? – user983447 Feb 15 '17 at 14:04
  • 1
    Arduino.h includes avr/io.h, which in turn includes the ioXXX.h file relevant to your specific MCU. – Edgar Bonet Feb 15 '17 at 14:24
-1

. Where are those variables defined?

In the device header file. Like other device specific macros.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.