Arduino_STM32
Arduino_STM32 copied to clipboard
STM32F1 EOC Interupt
any end of conversion interrupt for stm32f1 examples available? i'm trying to implement it but it doesnt seem to work:
* This is an example how to use the analog watchdog functionality of the ADC.
*
* The analog watchdog has two limits and will generate an IRQ if
* the input voltage is below the lower limit OR higher than the upper limit.
*
* Continuous or single conversion can be used.
* In continuous mode the interrupts will be coninuously generated in very
* short time intervals as long as the trigger condition is satisfied.
* This will cause the ADC interrupts to be nested and leads to hang-up.
* In order to avoid this, the AWD interrupt is disabled whithin the first IRQ.
*
*/
#include <STM32ADC.h>
STM32ADC myADC(ADC1);
const int maxSamples = 2; // 2 channels
uint8 pins[] = {PA0,PA1};
uint16_t dataPoints[maxSamples];
volatile static bool triggered;
// the AWD interrupt will be re-enabled 3 seconds after the last trigger
//-----------------------------------------------------------------------------
// This function will be called when the AWD interrupt is triggered
//-----------------------------------------------------------------------------
void adc_int()
{
myADC.attachInterrupt(NULL);
//myADC.disableAnalogWatchdog(); // to avoid ISR nesting
// a second IRQ will be triggered while we process the first ISR even before we disable the AWD
//Serial.println("*** AWD triggered! ***");
// Serial.print("ADC = "); Serial.println(myADC.getData());
// Print the data to the serial monitor
Serial.write((dataPoints[0] >> 8) & 0xFF); // MSB of dataPoints[0]
Serial.write(dataPoints[0] & 0xFF); // LSB of dataPoints[0]
// Transmit dataPoints[1] in big-endian format
Serial.write((dataPoints[1] >> 8) & 0xFF); // MSB of dataPoints[1]
Serial.write(dataPoints[1] & 0xFF); // LSB of dataPoints[1]
//myADC.enableAnalogWatchdog();
myADC.attachInterrupt(adc_int);
}
//-----------------------------------------------------------------------------
void setup()
{
//Serial.print("START");
//Serial.begin(1000000); // useless for USB serial
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // off
triggered = false;
// disable the following line if you use a COM interface different from USB serial
while (!Serial); delay(10);
//Serial.print("Setup...");
myADC.calibrate();
myADC.setSampleRate(ADC_SMPR_1_5);
// this will trigger an IRQ if the input is set to 3.3V
//myADC.setAnalogWatchdog(0, 0, 4095); // channel of PA0 = 0, high limit, low limit
//myADC.attachAnalogWatchdogInterrupt(adc_int);
//myADC.enableAnalogWatchdog();
for (unsigned int j = 0; j <2; j++)
pinMode(pins[j], INPUT_ANALOG);
myADC.setSampleRate(ADC_SMPR_1_5);//set the Sample Rate
myADC.setScanMode(); //set the ADC in Scan mode.
myADC.setPins(pins, 2); //set how many and which pins to convert.
myADC.setContinuous(); //set the ADC in continuous mode.
myADC.setDMA(dataPoints, 2, (DMA_MINC_MODE | DMA_CIRC_MODE), NULL);
myADC.attachInterrupt(adc_int);
myADC.startConversion();
//Serial.println("done.");
//Serial.println("Waiting for AWD interrupt...");
}
//-----------------------------------------------------------------------------
void loop()
{
}```
You can find many examples here: https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/STM32F1/libraries/STM32ADC/examples