AnalogComparator Interrupts
Posted: Wed Jul 12, 2023 11:33 am
Hi All,
I'm trying to utilize built-in comparator to resume from deepslep, but I'm currently failing on make comparator working. I Assume, that I'm doing something wrong, but I can't identify what.
Board is Generic STM32L051C8
Core is STM Core 2.6 ( but same issue was also in 2.5 )
Ide : Arduino IDE 1.18.16 or 2.1.1
I enabled HAL Comparator module by hal_conf_extra.h , but I can't assign interrupt handler.
Compilation is failing on lines with
In general, I found USE_HAL_COMP_REGISTER_CALLBACKS in STMicroelectronics\hardware\stm32\2.6.0\system\Drivers\STM32L0xx_HAL_Driver\Inc\stm32l0xx_hal_comp.h
I have made this sketch working only with modification of HAL Driver header file with removal of #if definitions, which is not ideal approach ( e.g. core upgrade will replace it) and this type of sketch was working on Nucleo L432
Any idea, where I'm doing something wrong ?
Vaclav
Test sketch is ( lot of serial debug messages
)
build_opt.h
hal_conf_extra.h
I'm trying to utilize built-in comparator to resume from deepslep, but I'm currently failing on make comparator working. I Assume, that I'm doing something wrong, but I can't identify what.
Board is Generic STM32L051C8
Core is STM Core 2.6 ( but same issue was also in 2.5 )
Ide : Arduino IDE 1.18.16 or 2.1.1
I enabled HAL Comparator module by hal_conf_extra.h , but I can't assign interrupt handler.
Compilation is failing on lines with
Code: Select all
if(HAL_COMP_RegisterCallback(&hcomp1, HAL_COMP_TRIGGER_CB_ID, HAL_COMP_TriggerCallback)!=HAL_OK)
I have made this sketch working only with modification of HAL Driver header file with removal of #if definitions, which is not ideal approach ( e.g. core upgrade will replace it) and this type of sketch was working on Nucleo L432
Any idea, where I'm doing something wrong ?
Vaclav
Test sketch is ( lot of serial debug messages

Code: Select all
#include "stm32l0xx_hal_comp.h"
COMP_HandleTypeDef hcomp1;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
hcomp1.Instance = COMP1;
hcomp1.Init.NonInvertingInput=COMP_INPUT_PLUS_IO3; // plus to PA1 (nucleo A1)
hcomp1.Init.InvertingInput=COMP_INPUT_MINUS_IO1; // minus to PA0 (nucleo A0 )
// hcomp1.Init.Output = COMP_OUTPUT_NONE;
hcomp1.Init.Mode=COMP_POWERMODE_MEDIUMSPEED;
// hcomp1.Init.Hysteresis=COMP_HYSTERESIS_NONE;
hcomp1.Init.OutputPol=COMP_OUTPUTPOL_NONINVERTED; /*!< Set comparator output polarity.
This parameter can be a value of @ref COMP_OutputPolarity */
// hcomp1.Init.BlankingSrce=COMP_BLANKINGSRC_NONE; /*!< Set comparator blanking source.
// This parameter can be a value of @ref COMP_BlankingSrce */
hcomp1.Init.TriggerMode=COMP_TRIGGERMODE_IT_RISING_FALLING;; /*!< Set the comparator output triggering External Interrupt Line (EXTI) */
// COMP_TRIGGERMODE_EVENT_RISING_FALLING
// hcomp1.Init.TriggerMode=COMP_TRIGGERMODE_EVENT_RISING_FALLING;; /*!< Set the comparator output triggering External Interrupt Line (EXTI) */
// HAL_COMP_MspInit(&hcomp1);
HAL_NVIC_SetPriority(ADC1_COMP_IRQn, 0, 3);
HAL_NVIC_EnableIRQ(ADC1_COMP_IRQn);
if(HAL_COMP_Init(&hcomp1) != HAL_OK)
{
/* Initialization Error */
Serial.println("COMP INIT Failed");
}
if(HAL_COMP_RegisterCallback(&hcomp1, HAL_COMP_TRIGGER_CB_ID, HAL_COMP_TriggerCallback)!=HAL_OK)
{
Serial.println("Callback Start failed");
}
/*##-2- Start teh COMP1 and enable the interrupt ###########################*/
if(HAL_COMP_Start_IT(&hcomp1) != HAL_OK)
{
/* Initialization Error */
Serial.println("COMP Start failed");
}
Serial.println("Full Init OK");
HAL_COMP_IRQHandler(&hcomp1);
Serial.println("Full Init OK2");
}
extern "C" void COMP_IRQHandler(void) {
HAL_COMP_IRQHandler(&hcomp1);
/* if(HAL_COMP_GetOutputLevel(&hcomp1)==1)
{
digitalWrite(LED_BUILTIN,HIGH);
}
else
digitalWrite(LED_BUILTIN,LOW);
*/
}
extern "C" void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
{
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
// Serial.println("T");
if(HAL_COMP_GetOutputLevel(&hcomp1)==1)
{
digitalWrite(LED_BUILTIN,HIGH);
}
else
digitalWrite(LED_BUILTIN,LOW);
}
void loop() {
// put your main code here, to run repeatedly:
}
Code: Select all
-DUSE_HAL_COMP_REGISTER_CALLBACKS=1
Code: Select all
#define HAL_COMP_MODULE_ENABLED
#define USE_HAL_COMP_REGISTER_CALLBACKS 1