2017-03-28 03:59 AM
I'm trying to use stm32f301 comparator 2, but the output is always 0 no matter if the two inputs are higher or lower. I guess the configuration is wrong.
The main code is here. Thanks for the help in advance!
void ConfigureComp2(vod)
{ GPIO_InitTypeDef GPIO_InitStruct;//init A7, A2 as analog
GPIO_InitStruct.Pin = GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; //COMP2->CSR |= COMP_CSR_COMPxOUTSEL_0;printf('after reset out %d\n', COMP2->CSR);
COMP2->CSR |= COMP_CSR_COMPxINSEL_2;
COMP2->CSR |= COMP_CSR_COMPxINSEL_1; printf('after input selection out %d\n', COMP2->CSR);//COMP2->CSR |= COMP_CSR_COMPxPOL;
//printf('after pol out %d\n', COMP2->CSR);COMP2->CSR |= COMP_CSR_COMPxEN;
printf('after enable, out %d\n', COMP2->CSR);for (int i=0; i<5; i++)
{ printf('comp2 i %d out %d\n', i, COMP2->CSR); printf('comp2 i %d out %d\n', i, COMP2->CSR & COMP2_CSR_COMP2OUT); }}2017-03-28 05:57 AM
Hi
nealjing@eptco.com
,I suggest, as a first step, to run one of the COMP working example available inthe STM32CubeF3 firmware package with a similar type of your project, it will help you to configure and develop your project:
STM32Cube_FW_F3_V1.7.0\Projects\STM32303C_EVAL\Examples\COMP
Imen