LPC11xx ADCInit confusion

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC11xx ADCInit confusion

440 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by corwinb on Tue Feb 12 10:01:01 MST 2013
The below code snippet is from the ADCInit function in the adc example.  Don't understand why the first two instructions (&=, |=) exist.  Why not just do the =?  Is this just a copy and paste issue?

  LPC_IOCON->R_PIO0_11 &= ~0x8F; /*  ADC I/O config */
  LPC_IOCON->R_PIO0_11 |= 0x02;  /* ADC IN0 */
  ...
  ...
  ...
  LPC_IOCON->R_PIO0_11   = 0x02;// Select AD0 pin function

Labels (1)
0 Kudos
3 Replies

420 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by corwinb on Sat Feb 16 09:32:47 MST 2013
Of course I understand specific bit manipulation.  My original query was to question why the the example code cleared the range (&= ~), set specific bits (|=), and then did an assignment (=) all on the same register.  I am new to the M0 and didn't know if there was some magical order things needed to be done.  I can see clearly now.  Thanks for the replies.
0 Kudos

420 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by avass on Sat Feb 16 00:42:14 MST 2013
"|=" makes sure you are only touching the bits you are setting.
"=" touches ALL the bits.

I personally use the |= to avoid accidental bit overwriting... It's a good practice and can save you tons of debugging...
0 Kudos

420 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tha on Tue Feb 12 13:54:37 MST 2013
This is mainly a coding choice.  Some people like to clear all the bits first before setting them.  This usually done for a just in case scenario.
0 Kudos