|
Hierodule 1.6.2
Utility module set for STM32 MCUs
|
The module lets you easily assign an ISR to handle the data received at the ADC peripheral.
HIERODULE_ADC_Wrapper is the main item in the module, with which you can access the variables related to the data received to implement your EOC ISR.
The module does not address peripheral configuration and initialization, it is assumed those are performed beforehand. Enable continuous conversion mode for the ADC channel you intend to use for exactly one conversion/rank.
Also notice that the ADC IRQs are defined in the module's source file. The compiler will throw a multiple definition error if an IRQ is defined somewhere else.
Create a double pointer to HIERODULE_ADC_Wrapper to create an instance for the ADC peripheral.
It has to be a double pointer, since the wrapper initializer passes you the wrapper pointer defined in the module by reference. The wrapper instance is handled in the module with a pointer and not with a variable of type HIERODULE_ADC_Wrapper, since you use pointers for dynamic memory allocation.
Secondly, you need a void function with a uint16_t parameter for the EOC ISR. You might as well just pass NULL if you intend to use the received data somewhere else. Or you can even maintain an array for the function pointers (i.e. void (*)(uint16_t)) to switch between ISRs on the fly.
Here's a simple example that assigns a task to the ISR that accumulates the data received at the ADC peripheral and initializes the wrapper for ADC1 with a filter weight of 0.75.
If you do not want your data filtered, simply comment out the macro constant definition HIERODULE_ADC_SMOOTHENING_FILTER in the header file, like so:
ADC conversion and ISR action will start once you enable the peripheral:
Likewise, you can halt the process via:
You can "release" the instance of your wrapper to free memory:
Keep in mind this only frees the wrapper pointer in the module and not your double pointer that points to it. It's best to free and nullify that, as well:
Notice that trying to access a freed memory address might turn out ugly for your run-time. However, you can reuse your double pointer to re-initialize the ADC peripheral after releasing it.