Page 1 of 1
STM32G431CBU6 : comparator setting library
Posted: Tue Oct 03, 2023 12:49 pm
by trimarco232
I tried to make it work with HALL , LL (structure) , LL (no structure) , nothing worked
Code: Select all
#include <Arduino.h>
#include "stm32g4xx_hal_comp.h" // ?
COMP_HandleTypeDef hcomp1;
void setup() {
hcomp1.Instance = COMP1;
hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO2; //
HAL_COMP_Init(&hcomp1);
}
void loop() {
Serial.print("o"); /// à enlever pour laisser boot0 à high
delay(50) ;
}
thank you , again ...
Re: STM32G431CBU6 : comparator setting library
Posted: Tue Oct 10, 2023 12:43 pm
by fpiSTM
Did you enable HAL_COMP_MODULE_ENABLED?
Re: STM32G431CBU6 : comparator setting library
Posted: Wed Oct 11, 2023 8:36 pm
by trimarco232
Code: Select all
#include <Arduino.h>
#define HAL_COMP_MODULE_ENABLED
COMP_HandleTypeDef hcomp1;
void setup() { // comes from cube IDE
hcomp1.Instance = COMP1; // comes from cube IDE
hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO1;
hcomp1.Init.InputMinus = COMP_INPUT_MINUS_1_2VREFINT;
hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE;
hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
HAL_COMP_Init(&hcomp1);
}
void loop() {
}
error: 'COMP_HandleTypeDef' does not name a type; did you mean 'TIM_HandleTypeDef'?
... without a working example , I am lost ...
Re: STM32G431CBU6 : comparator setting library
Posted: Wed Oct 11, 2023 9:04 pm
by fpiSTM
See the wiki to know how define it properly.
Re: STM32G431CBU6 : comparator setting library
Posted: Fri Oct 13, 2023 6:57 pm
by trimarco232
ok , thanks , working code :
Code: Select all
#include <Arduino.h>
#include "hal_conf_extra.h" // adhoc creation
COMP_HandleTypeDef hcomp1;
void setup() {
Serial.begin(115200);
hcomp1.Instance = COMP1; // comes from cube IDE
hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO1;
hcomp1.Init.InputMinus = COMP_INPUT_MINUS_1_2VREFINT;
hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE;
hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
HAL_COMP_Init(&hcomp1);
HAL_COMP_Start(&hcomp1);
delay(4000) ; // monitor
Serial.print(COMP1->CSR) ; // debug : verify
}
void loop() {
}
Extra HAL configuration can be enabled/disabled in variant.h (if required)
or in a file named (at sketch level):
hal_conf_extra.h
Code: Select all
//For information on installing libraries, see: ttp://www.arduino.cc/en/Guide/Libraries
#define HAL_COMP_MODULE_ENABLED