I am doing simple ADC test with potentiometer on STM32F103C8, it seems to work fine for 5 seconds or so, but then the whole uC just stops - even while loop stops doing what it is supposed to do(so I guess it doesn't even leave interrupt routine when it fails).
It probably has to do something with ADC initialization, but I can't see what exactly is wrong.
Below is my ADC.c with ADC initialization and my main.c(note that I outputting "1" and "2" just to monitor if it is still doing while loop stuff - and it doesn't, everything freezes)
If it is not initialization, then maybe it is hardware problem, but with such circuit I can't think of anything that can go wrong, board has capacitor for ADC and I even tried to put another one between signal and ground, nothing...

UPD
OK, Now I look like a total idiot... It turned out that it was not microcontroller that got stuck, but the LCD. I tried to change it to different LCD (it was 4x20, changed to 2x16) and it not halting now. I noticed that it is if I would fiddle the wires a little bit it would halt with bigger probability, so probably if the connection is not solid 100% of time LCD encounters some kind of internal error and got stuck, it does not happen with other LCD for some reason. Apparently vibration from me touching breadboard did something to connection and LCD freaked out. So whoever encounters same problem - try using different LCD, check the wiring(try to fiddle it to see if it affects anything), check if driver code is good, etc.


{

///
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

////

////
////

// specify channel we want to use

// enable interrupts on the end of conversion

}


main.c


#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "HD44780.h"
#include

{
{

LCD_GoTo(0,0);
LCD_SendText("   ");
}
}

int main (void)
{
RCC_Configuration(); // Configure the system clocks.
LCD_Init();          // Initialize the LCD.
LCD_Clear();         //Clear the LCD.
delay_ms(1000);

while(1)
{
delay_ms(10);
LCD_GoTo(0,0);
LCD_SendText ("1");
delay_ms(100);
LCD_GoTo(0,0);
LCD_SendText ("2");
delay_ms(50);
}

}


• You will need to restart the ADC to start again a conversion.You are doing this by disable and enable the ADC. Oct 11, 2015 at 3:30
• Sprintf inside an ISR ain't advisable. Your stack could overflow triggering a hard fault. Put a breakpoint in your hardfault handler and see if the control is transferred to your hardfault handler. I am guessing your hard fault handler has an infinite loop running causing the controller to halt Oct 11, 2015 at 10:06
• @Adithya, I tried outputting without using sprintf - same stuff, it freezes. And even if sprintf was the problem - it is not usual, sure it is not optimal output method, but it is used in countless examples and it does not causes the entire uC to halt for everyone who tries it. Oct 11, 2015 at 11:55
• Your string "ADC = %d" will always be greater than 4 characters won't it? Try increasing the size of your ADC array? I am not sure if sprintf truncates the extra characters or tries to store it in addresses that aren't a part of your array. Oct 11, 2015 at 12:01
• @Adithya, even if I completely delete sprintf line and just output some random commands(directly sending them to lcd without any sprintf conversion) it halts, sprintf is not the stuff to look at here since even if it does not exist in code uC freezes. And yes, char array is smaller than sprintf conversion, thanks, haven't noticed... but that's beside the point Oct 11, 2015 at 12:08

Try only getting the ADC value in the IRQ handler and letting the main loop do the LCD processing which may be triggering an interrupt that is preempted by the ADC interrupt you are already in, causing a lock.

    ADC_SoftwareStartConvCmd(ADC1, ENABLE);