PORTD

I have found reference to PORTD and DDRD which allow direct access to the port registers.
Are these defined in an accessible file?
Is it possible to locate a variable at a specific hardware address?

Thanks

Search the Arduino installation directory using e.g. grep. Can't help at this stage, but whatever you want to do, don't fiddle with the files that you found.

What do you want to achieve with a variable at a specific address?

You should read the Atmel (now Microchip) datasheet for the relevant Atmega chip - the Atmega 328 if you are using an Uno or Nano.

The registers are all detailed in the datasheet. The Arduino IDE recognizes them all. I can't recall which file that is in, but I know it does not explain anything about the registers.

...R

In the first instance I can use PORTD etc for fast access to the ports.
It would also be useful to directly access other peripheral registers such as the timer control registers, again to have fast code without using the sketch function calls.

OK, on my Windows system, I think it's this file for the 328: C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\iom328p.h

As Robin said, read the datasheet :wink: And do a search on your system for the register names in the Arduino installation directory; the names used in the Arduino environment are the same as those in the datasheet. That way you can get a feel how Arduino does it; I myself learn most from examples so digging through the standard libraries is a good exercise for me (and can be for you).

It may also be useful to refer to the Uno pin mapping.

...R

NevilleC:
In the first instance I can use PORTD etc for fast access to the ports.
It would also be useful to directly access other peripheral registers such as the timer control registers, again to have fast code without using the sketch function calls.

You don't need to see the header file, just read the datasheet. All of the names in the io header match the names in the datasheet.

Each section in the datasheet has a Register Description subsection. I like to look at that first because it gives you a sort of executive summary of the capabilities of what that section is describing. Once I've got a good idea around that I start reading the earlier sections to learn more about the exact setup procedure and limitations of the peripheral.

NevilleC:
I have found reference to PORTD and DDRD which allow direct access to the port registers.
Are these defined in an accessible file?
Is it possible to locate a variable at a specific hardware address?

Yes, &PORTD, &DDRD give the addresses of the registers, just like anything else in C++. I think
that's what you're after.

C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\iom328p.h

This is correct, but including this file would NOT be the correct way to get those definitions.
Atmel has a "standard" where programs should use "#include <avr/io.h>", and that file then figures out the correct ioXXXX.h file based on compile-command switches (specifically -mmcu=YYYY)
But you don't even have to do that in arduino sketches; they already include "Arduino.h" and Arduino.h already includes io.h, so all of the symbols mentioned in the datasheet should be available to an Arduino sketch with no additional effort.

Is it possible to locate a variable at a specific hardware address?

Yep. That's what io.h ends up doing for the SFR registers, after all. You can examine the iom328p.h file to see how they do it.

Google

arduino direct port manipulation

and pick out the tutorial for the in's and out's and caveats explained.

Yes, &PORTD, &DDRD give the addresses of the registers, just like anything else in C++. I think
that's what you're after.

The above quote could have the following expansions:

1. The actual addresses of PORTD and DDRD regsiters are 0x002B and 0x002A respectively. You can get these values from:
(a) mdef328.inc file of Atmel Studio 7 package

(b) By executing the following instructions in the Arduino IDE

(1) unsigned int adr1 = &PORTD;
(2) unsigned int adr2 = &DDRD;

(c) Now, you can write values at these addresses without using the symbolic names - PORTD, DDRD. Say, we wish to place 8Fh into PORTD without using its symbolic name.

byte *adr3;
adr3 = 0x002B;
*adr3 = 0x8F;                   //use address to store value 0x8F into PORTD
Serial.println(PORTD, HEX); //Shows: 8F

The worrying part is that OP is/was talking about variables. And that is risky business.

All the more reason for anyone to learn the whole lesson and not play ad-hoc with pieces picked up from comments.

Sometimes the order of setting data direction and port pins can lead to damaged pins depending on wiring.

Thanks for all these replies.
What I was unaware of is that the definitions for all the registers are already included, I'd not come across any documentation that mentioned that, I just happened to come across the reference to PORTD and DDRD in a book.

Reply #9 tells you how to find all of that on the Arduino site. The Arduino site has a book worth of such pages.