STM32F103C8T6 DMA ADC not working
Posted: Thu Apr 09, 2020 9:14 am
i am using stm32f103c8t6. i am working on osciloscope project the input frequency is 2KHz Square wave. the problem i getting is not showing proper square wave on arduino Serial plotter but when i change 2KHz into 99Khz the Serial Plotter showing Square Wave. is Arduino Code is Wrong ?
Code: Select all
#include <STM32ADC.h>
#include <HardwareTimer.h>
STM32ADC myADC(ADC1);
uint8 pin = PA7;
volatile static bool dma1_ch1_Active; //flag for interrupt
float usPeriod,timer_freq,ary[320];
uint16_t timPeriod_c;
#define maxSamples 1000
uint16_t buffer[maxSamples];
void setup() {
Serial.begin(115200);
pinMode(pin, INPUT_ANALOG);//AD pin.
usPeriod = 250;
timer_freq = 1000000/usPeriod;
timPeriod_c = 72000000/timer_freq;
}
void loop() {
// Take our samples
DMA();
if(dma1_ch1_Active == 0){
for(int x=0; x<maxSamples; x++){
Serial.println(buffer[x]);
}
}
}
void DMA(){
Timer3.setPrescaleFactor(1);
Timer3.setOverflow(timPeriod_c);
// timer_set_period(Timer3, usPeriod);
Timer3.setMasterModeTrGo(TIMER_CR2_MMS_UPDATE);
// myADC.calibrate();
myADC.setSampleRate(ADC_SMPR_1_5); //default - myADC.setSampleRate(ADC_SMPR_1_5);
myADC.setPins(&pin, 1);
dma1_ch1_Active = 1;
myADC.setTrigger(ADC_EXT_EV_TIM3_TRGO);
myADC.setDMA(buffer, maxSamples, (DMA_MINC_MODE | DMA_TRNS_CMPLT), DMA1_CH1_Event);
// myADC.setDMA(buffer, maxSamples, (DMA_MINC_MODE | DMA_TRNS_CMPLT), DmaIRQ);
while (dma1_ch1_Active >= 1){}; //wait for DMA to complete.
// dma1_ch1_Active = 0;
// myADC.startConversion();
// myADC.setTrigger(ADC_EXT_EV_SWSTART);
dma_disable(DMA1, DMA_CH1); //End of trasfer, disable DMA and Continuous mode.
}
static void DMA1_CH1_Event() {
dma1_ch1_Active = 0;
}