Arduino IDE 2.3.6
STM32duino 2.12.0
Hi have add the hal_conf_extra.h file with : #define HAL_COMP_MODULE_ENABLED
the code comes from CubeMX (HAL) :
hcomp1.Instance = COMP1;
hcomp1.Init.InputMinus = COMP_INPUT_MINUS_1_2VREFINT;
hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO3;
etc.
→ Compilation error: 'hcomp1' was not declared in this scope
had a look , but didn't find why ?
STM32H503CB : use comparator → compilator error
-
trimarco232
- Posts: 53
- Joined: Wed Jul 12, 2023 11:09 am
Re: STM32H503CB : use comparator → compilator error
Hcomp1 variable is not declared. It is probably defined globally in cubemx project.
-
trimarco232
- Posts: 53
- Joined: Wed Jul 12, 2023 11:09 am
Re: STM32H503CB : use comparator → compilator error
thanks , so what have I to do in order to make this thing to work ?
Re: STM32H503CB : use comparator → compilator error
Add the variable declaration in your sketch....
-
trimarco232
- Posts: 53
- Joined: Wed Jul 12, 2023 11:09 am
Re: STM32H503CB : use comparator → compilator error
well , it wasn't that simple , I had to :
- set manually the COMPEN bit in the APB1LENREN register
- declare hcomp1 as an COMP_HandleTypeDef
here is the code (it compiles and updates the registers , but I didn't check the comparator working yet)
- set manually the COMPEN bit in the APB1LENREN register
- declare hcomp1 as an COMP_HandleTypeDef
here is the code (it compiles and updates the registers , but I didn't check the comparator working yet)
Code: Select all
void comp_setup(void) { // PB1←in- ; PB2←in+ ; PB15→out
RCC->APB1LENR |= RCC_APB1LENR_COMPEN; // comparator clock enable
COMP_HandleTypeDef hcomp1; // déclaration expresse
hcomp1.Instance = COMP1;
hcomp1.Init.InputMinus = COMP_INPUT_MINUS_1_2VREFINT;
hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO3;
hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE;
hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
hcomp1.Init.Mode = COMP_POWERMODE_HIGHSPEED;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
HAL_COMP_Init(&hcomp1);
COMP1->CFGR1 |= 1; /// HAL_COMP_Start(&hcomp1); ← ne marche pas
Serial.print("RCC_APB1LENR:");
Serial.println(RCC->APB1LENR, BIN); /// debug : verify
Serial.print("COMP1_CFGR1:");
Serial.println(COMP1->CFGR1, BIN); /// debug : verify
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_2, LL_GPIO_MODE_ANALOG); // PB2 analog = COMP1_INP
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_9, LL_GPIO_MODE_ALTERNATE); // PB15 is alternate
LL_GPIO_SetAFPin_8_15(GPIOB, LL_GPIO_PIN_9, GPIO_AF12_COMP1); // PB15 is COMP1_OUT
}