Pages: [1]   Go Down
Author Topic: using parts of gpio registers to access data  (Read 629 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 18, 2014, 10:18:30 am by doors666 » Logged

0
Offline Offline
Shannon Member
****
Karma: 214
Posts: 12424
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The datasheet says something about this, grep for "Address alignment"
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: