Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


Interrupt Handler Setup

Hello,

I just got an STM32f4 discovery board and I seem to be having trouble making the interrupts work. I was able to get the button to work on the external interrupt and timer 4 to work similar to the demo code, however I cannot get the ADC EOC interrupt to work.

I have it set so then LED5 on the discovort board turns on if the ADC_IRQHandler is entered and then it should start a new conversion. My main initializes the LEDs, the Button, timer4 and the ADC as seen below. After the ADC is initialized, I start a conversion then sit in an empty while(1).

This first conversion complietes, I can see the value in the ADC_DR register, however I only get the one conversion and as I said I don’t enter the IRQ handler.

Can anyone with a little more experiance please point out what I might have missed with respect to setting up my interrupts?

Thank you.

Here is my ADC init function, incase I missed something.

void ADC3_CH12_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

// Enable ADC3, DMA2 and GPIO clocks ****************************************
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);

// Configure ADC3 Channel12 pin as analog input ******************************
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);

// ADC Common Init **********************************************************
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);

// ADC3 Init ****************************************************************
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC3, &ADC_InitStructure);

// ADC3 regular channel12 configuration *************************************
ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);

ADC_ITConfig(ADC3, ADC_IT_EOC, ENABLE);

// Enable ADC3
ADC_Cmd(ADC3, ENABLE);

}

Then this is my IRQ Handler

void ADC_IRQHandler(void)
{
//Turn on LED if IRQ is entered
GPIO_PinOn(GPIOD, LED5_PIN);

if(ADC_GetITStatus(ADC3, ADC_FLAG_EOC) != RESET)
{
ADCvalue = ADC_GetConversionValue(ADC3);

ADC_ClearITPendingBit(ADC3, ADC_FLAG_EOC);
}
ADC_SoftwareStartConv(ADC3);
}

My startup_stm32f4xx.s file has these entries in it and it was generated when I created my project.

.word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */

.weak ADC_IRQHandler
.thumb_set ADC_IRQHandler,Default_Handler

Figured it out.

I was missing the NVIC config for the ADC and for some unknow reason, the ADC_InitStructure was making the conversion left justified and turning on the DMA, DDS, CONT and EOCS bits in ADC3->CR2 register. So I stopped using that code and set up the registers manually.

The other issue was it was getting stuck in the default interrupt handler, so I copied in the STM32F4xx_it.c file from on of the demo projects and that seemed to fix it.


 

Newest Forum Posts

  1. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  2. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  3. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  5. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  6. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  8. Build a project in "release" mode by tang, 2025-02-20 10:36
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35
  10. Fail to debug in Win 11 C/C++ by mortenlund, 2024-12-26 20:27

Last-Modified Blogs