Go Down

Topic: using parts of gpio registers to access data (Read 1 time) previous topic - next topic


Jan 18, 2014, 04:14 pm Last Edit: Jan 18, 2014, 04:18 pm by doors666 Reason: 1
instead of mucking around with 32 bit variables and bit masks and shifting etc, if my gpio is aligned with byte boundaries, can i access the registers using shorter variables..

i.e. if I want to use say PA8-PA23, the middle 16 bits, can i use it like this -

// point to the required 16 bits, skip the first 8
odsr16_address = address of REG_PIOA_ODSR register + 1;

// use short to access just the required 16 bits, skip the fist 8 bits
unsigned short volatile * const my_odsr = (unsigned short *) (odsr16_address);

// set all 16 bits high
my_odsr = 0xFFFF;

// to read data
short a = *my_odsr;

similarly use char to access 8 bits...

PS: is there a restriction on the shorts (or ints for that matter) starting on odd or even address boundaries, or can they start anywhere.


The datasheet says something about this, grep for "Address alignment"
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

Go Up