3.2.2 Register Initialization Using Bit Positions
The same configuration, as presented above, can be done by using the bit position macros, as follows.
ADC0.CTRLA = (1 << ADC_ENABLE_bp) /* Enable the ADC */ | (1 << ADC_CONVMODE_bp) /* Select Differential Conversion mode */ | (1 << ADC_RESSEL0_bp) /* 10-bit conversion */ | (0 << ADC_RESSEL1_bp);
Note: The
(0 <<
ADC_RESSEL0_bp)
line is added simply for readability, but it can be
removed.ADC0.CTRLA = (1 << ADC_ENABLE_bp) /* Enable the ADC */ | (1 << ADC_CONVMODE_bp) /* Select Differential Conversion mode */ | (1 << ADC_RESSEL0_bp); /* 10-bit conversion */
Other position masks that can be used to configure bit fields are group position masks. They can be used as presented below. The desired configuration value must be shifted with the bit field position (group position).
ADC0.CTRLA = (1 << ADC_ENABLE_bp) /* Enable the ADC */ | (1 << ADC_CONVMODE_bp) /* Select Differential Conversion mode */ | (0x01 << ADC_RESSEL_gp); /* 10-bit conversion */