I am trying to implement the following scenario on STM32F103C8 Microcontroller.
On PB11 and PB10 I've LED and Button connected respectively. LED is blinking continuously 500ms, but when button is pressed it blinks with 100ms delay 20 times.
I have also connected UART (PA3-PA2) and Potentiometer on ADC (PA0). My task is to transfer ADC reading to UART in DMA mode.
LED and Button interrupt worked well, but as soon as i have added the code for ADC and USART handling it stopped working.
Could you please advice, where is my mistake in ADC-DMA-UART processing and how can i fix it?
Snippets from Main.c
//Buffer for ADC.
uint16_t buffer[5];
huart2.Instance->CR3 |= USART_CR3_DMAT;
//Transfer ADC reading to Buffer in DMA.
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)buffer, 5);
while (1)
{
//LED blinking
HAL_GPIO_TogglePin(GPIOB, LED_Pin);
HAL_Delay(500);
}
//ADC callback function - When buffer is full transfer to UART.
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
HAL_DMA_Start_IT(&hdma_usart2_tx, (uint32_t)buffer, (uint32_t)&huart2.Instance->DR, sizeof(buffer));
}
//Interrupt handler for Button.
void EXTI15_10_IRQHandler(void) {
HAL_GPIO_EXTI_IRQHandler(BT_Pin);
}
//Callback function for Button.
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
if(GPIO_Pin == BT_Pin){
for(volatile int i=20; i>0; i--){
HAL_GPIO_TogglePin(GPIOB, LED_Pin);
HAL_Delay(100);
}
}
//Transfer ADC reading to Buffer in DMA. HAL_ADC_Start_DMA(&hadc1, (uint32_t*)buffer, 5);
you couldnt interrupt the LED anymore ? – Ali Ben Zarrouk