cancel
Showing results for 
Search instead for 
Did you mean: 

ODR IDR question

xtian
Associate II
Posted on January 21, 2013 at 00:35

Hi guys,

I have this question,

/* GPIOA Periph clock enable */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

  /* Configure PA0 .. PA7 in output pushpull mode */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure PA8 .. PA15 in input, pulled up mode */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIOA->ODR = GPIOA->IDR >> 8; // Mirror high ordered inputs to low ordered outputs

could you explain to me the bold one especially ''8'' and IDR

for example I want to mirror only the first four bits from high ordered to low ordered

or last four bits from high ordered to low ordered.

Thank you very much!
This discussion is locked. Please start a new topic to ask your question.
7 REPLIES 7
Posted on January 21, 2013 at 00:54

It's a shift right by 8 bits, So bit 8 goes to bit 0, and bit 15 to bit 7. In all A[8..15] to A[0..7]. It is a basic C operator.

So reading IDR as  XXXXXXXX--------

And writing ODR as 00000000XXXXXXXX

So A[12..15] reflected to A[0..3]

GPIOA->ODR = (GPIOA->ODR & 0x00F0) | ((GPIOA->IDR >> 8) & 0x000F);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
xtian
Associate II
Posted on January 21, 2013 at 01:44

Thanks clive... sorry for my ignorance but im reading books in c now but in parallel

So A[12..15] reflected to A[0..3]

GPIOA->ODR = (GPIOA->ODR & 0x00F0) | ((GPIOA->IDR >> 8) & 0x000F);

-> means?

the value of GPIOA is pointed to the value of ODR,

where ODR is equal to (GPIOA pointed to the values of 0000XXXX <12-15>) of (GPIOA pointed to the values of XXXX0000 <0-3>)

correct?

Posted on January 21, 2013 at 03:18

Sorry that should have read

''So A[8..11] reflected to A[0..3]''

Whereas A[12..15] reflected to A[0..3] would be

GPIOA->ODR = (GPIOA->ODR & 0x00F0) | ((GPIOA->IDR >> 12) & 0x000F);
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
xtian
Associate II
Posted on January 21, 2013 at 03:24

Thanks clive >> 12 to apply the mirror on the 12 bit.. OK.. thanks much

xtian
Associate II
Posted on January 21, 2013 at 03:26

just to finalize my questions.. hmm what does | do..

xtian
Associate II
Posted on January 21, 2013 at 03:35

ahh clive is this what implements the pipeline in the ARM M series architecture?

Posted on January 21, 2013 at 04:14

ahh clive is this what implements the pipeline in the ARM M series architecture?

No, logical OR.

The & is a logical AND

You really need to get a decent text on the C language, like K&R
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..