cancel
Showing results for 
Search instead for 
Did you mean: 

I'm trying to read an ADC(channel 7) which is the internal reference voltage channel for stm8s903f3, to print the adc value read on uart terminal. But for some reason its not continuously printing the adc value that is being updated.

PMoop.1
Associate II

It updates if I manually reset the board. I'm setting my baudrate as 11400, but it works only if I select the baudrate as 115200 on hyperterminal. Here is a snippet of what Im working on. (EDIT) It even works when I step through the code, not when I run it

void main(void)

{

 Serial_begin(14400);

 CLK_Config();

 GPIO_Setting();

 SYS_EXTI_Setting();

 ADC_Setting();

 PWM_Setting();

 /* Infinite loop */

 while (1)

 {

  if(!adc_start){

  adc_start = FALSE ;

  ADC1_ScanModeCmd(ENABLE);

  ADC1_StartConversion();

  while(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == 0);

  ADC1_ClearFlag(ADC1_FLAG_EOC);

  // Battery voltage calculation

  uint16_t adc_recorded = ADC1_GetBufferValue(7);

  Serial_print_int(adc_recorded);

}

void Serial_print_int (int number) //Funtion to print int

 {

char count = 0;

char digit[5] = {0};

while (number != 0) //split the int to char array 

{

digit[count] = number%10;

count++;

number = number/10;

}

while (count !=0) //print char array in correct direction 

{

UART1_SendData8(digit[count-1] + 0x30);

while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET); //wait for sending 

count--; 

}

    count = 0;

 }

0 REPLIES 0