STM32G431CBU6 : comparator setting library

Post Reply
trimarco232
Posts: 13
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

STM32G431CBU6 : comparator setting library

Post 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 ...
by trimarco232 » Fri Oct 13, 2023 6:57 pm
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
Go to full post
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32G431CBU6 : comparator setting library

Post by fpiSTM »

Did you enable HAL_COMP_MODULE_ENABLED?
trimarco232
Posts: 13
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

Re: STM32G431CBU6 : comparator setting library

Post 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 ...
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32G431CBU6 : comparator setting library

Post by fpiSTM »

See the wiki to know how define it properly.
trimarco232
Posts: 13
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

Re: STM32G431CBU6 : comparator setting library

Post 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
Post Reply

Return to “PR's bugs and enhancements”