STM32F0 Discovery, double buffering
As the topic says i want to implement double buffer for my ADC on DMA interruption to save data on SD card.
I've done two buffors. I am saving data to two of them in sequence. If one gets to it's limits the other one is taking the data. To point the cell of my buffer, I am using iterator. The problem is my iterator doesn't reset despite of code that does that. Whole two buffors are filled with data in first loop, then iterator gets stuck. Here is code.
uint32_t measurementADC;
uint16_t buff1[256];
uint16_t buff2[256];
int buff_iterator = 0;
bool flag_active_buff = true;
bool flag_to_save = false;
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){
if(buff_iterator==255)
{
flag_active_buff = !flag_active_buff;
flag_to_save = true;
buff_iterator=0;
}
else
{
flag_to_save = false;
}
if(flag_active_buff == true)
{
save_to_buff(buff1, measurementADC);
}
else
{
save_to_buff(buff2, measurementADC);
}
}
void save_to_buff(uint16_t table[], uint16_t value)
{
table[buff_iterator] = value;
buff_iterator++;
}
while (1)
{
if(flag_to_save ==true)
{
if(flag_active_buff == true)
{
update_file(buff1);
}
else
{
update_file(buff2);
}
}
}Any ideas what's wrong?