Display Register Addresses?

Hello,

Is it possible to display the value being used for a given register? For example can I send the address being used for PORTB or SPDR to the Serial port for display?

Not looking for the value of that register but the address of the register.

Thanks,
Todd

For example can I send the address being used for PORTB or SPDR to the Serial port for display?

Why would you want to? Those addresses are fixed and are not meant for you to muck with.

Look at the data sheet - it gives ALL of the register addresses...

Regards,
Ray L.

I'm not looking to change it. I'm looking to verify it is what the datasheet says it should be.

Is there a way to do that?

In the PIC processor world with the CCS compiler, we have "getenv()" that will return that, but not that I am aware of here unless you were to look at the assembly language file if it gets created by the compiler (you may have to turn on a compile option). It makes sense with the PIC processors so you can make your code portable between processors (the CCS compiler works with a whole bunch of the different PIC processors and Port B for example may be at different addresses in the map for different processors). Is there a hidden .h file somewhere the compiler is using? Somehow it knows about the register map - it may be in the board descriptions.

Is there a way to do that?

Serial.print("Address of PORTB: ");
Serial.println(&PORTB);

Though you can be CERTAIN that the datasheet IS correct.

tbriley:
I'm not looking to change it. I'm looking to verify it is what the datasheet says it should be.

Is there a way to do that?

Why?

@LarryD, great question. I'm seeing some very odd behavior the last 2 days where before everything was fine. Even a simple SPI master isn't working as expected. I want to make sure I don't have something going on in a header file or compiler issue. I'd like to verify the address being used is what the datasheet says it should be.

I had already tried Serial.println(&PORTB); but get an error "call of overloaded 'println(volatile uint8_t*)' is ambiguous".

PaulS:

Serial.print("Address of PORTB: ");

Serial.println(&PORTB);



Though you can be CERTAIN that the datasheet IS correct.

The datasheet might be correct, Paul, but is the define in the include file? Anyway:

void setup ()
{
  Serial.begin (115200);
  Serial.print("Address of PORTB: ");
  Serial.println((int) &PORTB, HEX);
}  // end of setup
void loop () { }

Output:

Address of PORTB: 25

Which agrees with the datasheet. :slight_smile:

Thanks Nick. Very helpful.

The datasheet might be correct, Paul, but is the define in the include file?

Yes. Look at the files in \arduino-\hardware\tools\avr\avr\include\avr. Each of the files for various avr chips defines a value for PORTB (in terms of something else).

PaulS:
Yes. Look at the files in \arduino-\hardware\tools\avr\avr\include\avr. Each of the files for various avr chips defines a value for PORTB (in terms of something else).

That was what I was getting at back in #4, I just wasn't sure where it was defined. Over in the PIC forums we have seen cases where the Compiler writers got the definitions wrong (they soon fixed it, but not before people ran into it).