cancel
Showing results for 
Search instead for 
Did you mean: 

ADC+UART+DMA interrupt question

MCava.1
Associate

Hello, I am a beginner in embedded systems,

I would like to build the following project on my STM32F102 bluepill board.

I have configured TIM 2 timer for 1 sec period and it blinks the LED. (working)

I also want to collect data through ADC and send it over USART DMA. (Not working)

And when button is cklicked LED starts blinking faster 20 times. (not working)

Please advice whats i am doing wrong in my code.

volatile unsigned fast_flash_count = 0;

uint8_t tx_buff[10]="Hello \r\n"; //Greeting message

uint8_t rx_buff[10];

uint8_t ADC_buff[2];

uint8_t voltage;

//TIM2 callback function

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

  if(htim->Instance==TIM2)

  {

    HAL_GPIO_TogglePin(GPIOB, LED_Pin); //blinkk led 1sec period

 voltage = (uint8_t)ADC_buff * (3.3/4095); //convert adc value to voltage

 HAL_UART_Transmit_DMA(&huart3, (uint8_t*)voltage, sizeof(voltage)); //transmit voltage value over uart

    if( fast_flash_count > 0 ) //if button is clicked exti interrupt is thrown and this value is set to 20 for fast blinking

    {

      // Set TIM2 reload to fast-flash period

      htim2.Init.Period = 299;

for(volatile int x = fast_flash_count; x>0; x-- ){

HAL_GPIO_TogglePin(GPIOB, LED_Pin);

}

fast_flash_count =0;

htim2.Init.Period = 499;

    }

  }

}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){

__NOP();

}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){

if(GPIO_Pin == BT_Pin)

  {

 fast_flash_count = 20 ;

  }

}

0 REPLIES 0