2020-09-30 12:49 PM
Hello, I'm having a trouble to read or write bits on registers, for example I would like to change the comparator input minus pin, according to the RM I have to change the INMSEL bits in the COMP1_CSR register, but when I write this line code:
COMP1_CSR = 0xF7854876 // just an example
the IDE tells me that "COMP1_CSR is not declared", and it's the same thing with other registers, I cannot directly manipulate them...
I'm using STM32 Nucleo L476.
Solved! Go to Solution.
2020-09-30 01:02 PM
COMP1->CSR |= COMP_CSR_INMSEL_0;
or such works. The componentes are pointer to structures, the registers are struct members. This is favorable considering the generated machine code.
2020-09-30 01:02 PM
COMP1->CSR |= COMP_CSR_INMSEL_0;
or such works. The componentes are pointer to structures, the registers are struct members. This is favorable considering the generated machine code.
2020-09-30 01:12 PM
Thank you for help, how can I check for example if the pin number 5 is set to 0 or 1 without alternating the other register bits?
2020-09-30 01:21 PM
You can check for a single bit set by
if( COMP1->CSR & COMP_CSR_INMSEL_0 ) {
...
}
or extract one or more bits by using the Pos and Msk
int inmsel = (COMP1->CSR & COMP_CSR_INMSEL_Msk) >> COMP_CSR_INMSEL_Pos; // yields 0..7
In STM32CubeIDE press F3 (open declaration) to see the header file with all of its defines.
2020-10-02 02:39 PM
CMSIS has a macros for this:
int inmsel = _FLD2VAL(COMP_CSR_INMSEL, COMP1->CSR);