I had a little confusing regarding the address of GPIO_PortA As mentioned in datasheet:
- Based address of GPIO PortA:0x40004000
- and GIOP_DATA has Offset : 0x000
- which mean the address of GPIO_PortA = 0x40004000;
Problem starts from here:
- why this code is not working as expected: (Using datasheet addresses)
#define porta_data (*(volatile unsigned long*)0x40004000)
- and why this code is working with wrong address (saw during edX online lec)
#define porta_data (*(volatile unsigned long*)0x400043fc)
- there is another problem.
- when I use bit binding method and use the formula.
bit_word_addr = bit_band_base + (byte_offset * 32) + (bit_number * 4)
#define bit_word_addr (0x40004000+(0x0000*32)+(1*4+4)) #define porta_pin0 (*(volatile unsigned long*)bit_word_addr)
- using the base address and offset as mentioned in datasheet
- I could toggle the individual bit as expected.
- But using the same address I couldn't toggle the whole port (GPIO_PORTA).