To print address of pheripheral registers of AVR2560

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
int main(void)
{
	UART_Init0();
	uint8_t a ;
	uint8_t *p;
	p = &PORTB;

    
    while (1) 
    {
    }
}

I want to access the address of GPIO peripheral Registers, for that, I have written these lines of code. 

But on building the solution it shows error:       invalid conversion from 'volatile uint8_t* {aka volatile unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]   

 

I am not able to make out what wrong am I doing, as PORTB corresponds to _SFR_IO8(0x05). 

the main thing which I want to do is to access the peripheral GPIO register by address instead of its naming Convention

Kunal Gupta

github.com/gkunalupta

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>as PORTB corresponds to _SFR_IO8(0x05)

 

Follow that define all the way to its conclusion and you eventually get a volatile uint8_t*

 

The compiler doesn't like you taking a uint8_t* (p) and assigning it to a value from a volatile uint8_t* because you lose its volatile property. 

 

https://godbolt.org/z/Mzv4a5

Last Edited: Sat. Sep 12, 2020 - 07:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got my answer for this.

But i got another question that how should i print the address of pointers without using sprint (%p) thing

Kunal Gupta

github.com/gkunalupta

Last Edited: Sat. Sep 12, 2020 - 07:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kunalgupta wrote:
I want to do is to access the peripheral GPIO register by address instead of its naming Convention

*((volatile uint8_t *)0x05) = PORTB_value;

(which is pretty much what "PORTB" expands to anyway as you'll see if you --save-files and look at the .i preprocessed file.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your help and the website link which u mentioned is awesome, is it like an online ide for AVR GCC

Kunal Gupta

github.com/gkunalupta