Code Freezing on accessing ADC BUffer
Posted: Fri Jan 29, 2016 12:12 pm
Hey Everyone,
So i am using an STM32F103RG, ADC1 IN0 & IN4.
Here's my ADC setup
And here's my thread.
I have another 2 Threads, 1 for a GPS Modem, ( decoding NMEA Packets, and another one taking care of a Cellular Modem.
If i run the battery thread alone, it runs fine. THe moment i run all 3 threads, it lands into an unhandled exception. So i went on commenting lines from below and found out that
is causing the freeze.
Can anyone point out what's going wrong here?
Thanks,
So i am using an STM32F103RG, ADC1 IN0 & IN4.
Here's my ADC setup
Code: Select all
#define ADC_BUF_DEPTH 8 // depth of buffer
#define ADC_CH_NUM 1 // number of used ADC channels
static adcsample_t samples_buf[ADC_BUF_DEPTH * ADC_CH_NUM]; // results array
// Fill ADCConversionGroup structure fields
static ADCConversionGroup adccg = {
circular : TRUE,
num_channels: 2,
end_cb : NULL,
error_cb : NULL,
cr1 : 0,
cr2 : 0,
smpr1 : 0,
smpr2 : 0,
sqr1 : ADC_SQR1_NUM_CH(2),
sqr2 : 0,
sqr3 : ADC_SQR3_SQ1_N(4) | ADC_SQR3_SQ1_N(0)
};
And here's my thread.
Code: Select all
//Battery Monitor
static WORKING_AREA(waThread4, 1024);
static msg_t Thread4(void) {
chRegSetThreadName("Battery");
int adc_value_a,adc_value_b;
int ia,ib;
while(1){
chThdSleepMilliseconds(5000);
ia = samples_buf[0];
ib = samples_buf[1];
adc_value_a = (((3.3)/4096) * ia) * 1000 ;
adc_value_b = (((3.3)/4096) * ib) * 1000 ;
sprintf(battery_global_a,"%d",(adc_value_a / 110));
sprintf(battery_global_b,"%d",(adc_value_b / 110));
}
return 0;
}I have another 2 Threads, 1 for a GPS Modem, ( decoding NMEA Packets, and another one taking care of a Cellular Modem.
If i run the battery thread alone, it runs fine. THe moment i run all 3 threads, it lands into an unhandled exception. So i went on commenting lines from below and found out that
Code: Select all
ia = samples_buf[0];
ib = samples_buf[1];is causing the freeze.
Can anyone point out what's going wrong here?
Thanks,