cancel
Showing results for 
Search instead for 
Did you mean: 

I am using the STM32L051K8U6 and I have set up to use EXTI interrupt on PA0. I also have EXTI interrupts enabled on PA3, PA10 and PA11. PA3, PA10 and PA11 do generate interrupts but not PA0. I include the MX project. Is there any possible reason for this?

fgeldenh
Associate II
 
7 REPLIES 7
Jaroslav JANOS
ST Employee

Hi @fgeldenh​,

you have not activated pull-up on PA0, like you did on the other EXTI pins. Is the switch pulled-up externally?

BR,

Jaroslav

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi – This one has an external pullup. See attached.

Regards

Francois Geldenhuys

[edit: contact details removed from this public thread]

I can see only the CubeMX project, no schematics. Could you please upload it, or at least some clipping with the pin wiring and the pull-up? Also, have you changed anything in the generated code?

BR,

Jaroslav

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

fgeldenh
Associate II

Here are the schematics. I have not modified the generated code except for adding the main entrypoint and hooks that allow calls to  MX_GPIO_Init() andMX_I2C1_Init();

This is my code for going to sleep and restoring from sleep

/** EXTERNALS ********************************************************/

extern FLAGS sysStat;         // state flags

extern I2C_HandleTypeDef hi2c1;

/** P R I V A T E P R O T O T Y P E S & CODE ***************************************/

void fixGpio(void);  // call to reinit gpio

void SwitchTo32MHz(void);

void SwitchTo32kHz(void);

void fixI2C(void);  // call to reinit I2C

void doSleep(void)

{

 HAL_Delay(1000);  

  

 // turn off radio

 sysStat.rfsleep = 1;        // say we have disabled RF

  

 HAL_I2C_DeInit(&hi2c1);

 HAL_GPIO_DeInit(GPIOA, 0x93f2);  

 HAL_GPIO_DeInit(GPIOB, 0xffee);

 HAL_SuspendTick();

 SwitchTo32kHz();

 HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);

 SwitchTo32MHz();

 fixGpio();

 fixI2C();  

 HAL_ResumeTick();

 PWR->CR |= PWR_CR_CWUF;

}

void SwitchTo32MHz(void)

{

/* (1) Select Vcore voltage range 1 (1.8V) */

/* (2) Enable 1 read WS on FLASH */

/* (3) Enable prefetch buffer */

/* (4) Enable HSI */

 /* (5) Wait for HSI ready flag and HSIDIV flag */

 /* (6) Set PLL on HSI, multiply by 4 and divided by 2 */

 /* (7) Enable the PLL */

 /* (8) Wait for PLL ready flag */

 /* (9) Select PLL as system clock */

 /* (10) Wait for clock switched on PLL */

/* (11) Disable MSI (unused) */

/* (12) Set SYSCLK prescaler to 1 */

 PWR->CR = (PWR->CR & ~(PWR_CR_VOS)) | PWR_CR_VOS_0; /* (1) */

 FLASH->ACR |= FLASH_ACR_LATENCY; /* (2) */

FLASH->ACR |= FLASH_ACR_PRFTEN; /* (3) */

 RCC->CR |= RCC_CR_HSION; /* (4) */

 while ((RCC->CR & RCC_CR_HSIRDY) != RCC_CR_HSIRDY) /* (5) */

 {

 }

 RCC->CFGR |= RCC_CFGR_PLLSRC_HSI | RCC_CFGR_PLLMUL4 | RCC_CFGR_PLLDIV2; /* (6) */

 RCC->CR |= RCC_CR_PLLON; /* (7) */

 while ((RCC->CR & RCC_CR_PLLRDY) == 0) /* (8) */

 {

 }

 RCC->CFGR = ((RCC->CFGR & ~(RCC_CFGR_SW)) | RCC_CFGR_SW_PLL); /* (9) */

 while ((RCC->CFGR & RCC_CFGR_SWS_PLL) != RCC_CFGR_SWS_PLL) /* (10) */

 {

 }

RCC->CR &= ~RCC_CR_MSION; /* (11) */

RCC->CFGR = ((RCC->CFGR & ~(RCC_CFGR_HPRE)) | RCC_CFGR_HPRE_DIV1); /* (12) */

}

void SwitchTo32kHz(void)

{

/* (1) Enable MSI */

/* (2) Wait for MSI ready flag */

/* (3) Select MSI Range 0 (65kHz) */

/* (4) Select MSI as system clock */

/* (5) Wait for clock switched on MSI */

 /* (6) Set SYSCLK prescaler to 2 */

/* (7) Disable HSI (unused) */

/* (8) Disable PLL (unused) */

/* (9) Disable prefetch buffer (not needed) */

/* (10) Disable 1 read WS on FLASH (not needed) */

/* (11) Select Vcore voltage range 3 (1.2V) */

 RCC->CR |= RCC_CR_MSION; /* (1) */

 while ((RCC->CR & RCC_CR_MSIRDY) != RCC_CR_MSIRDY) /* (2) */

 {

 }

RCC->ICSCR = ((RCC->ICSCR & ~(RCC_ICSCR_MSIRANGE)) | RCC_ICSCR_MSIRANGE_0); /* (3) */

 RCC->CFGR = ((RCC->CFGR & ~(RCC_CFGR_SW)) | RCC_CFGR_SW_MSI); /* (4) */

 while ((RCC->CFGR & RCC_CFGR_SWS_MSI) != RCC_CFGR_SWS_MSI) /* (5) */

 {

 }

RCC->CFGR = ((RCC->CFGR & ~(RCC_CFGR_HPRE)) | RCC_CFGR_HPRE_DIV2); /* (6) */

RCC->CR &= ~RCC_CR_PLLON; /* (7) */

RCC->CR &= ~RCC_CR_HSION; /* (8) */

FLASH->ACR &= ~FLASH_ACR_PRFTEN; /* (9) */

FLASH->ACR &= ~FLASH_ACR_LATENCY; /* (10) */

PWR->CR = (PWR->CR & ~(PWR_CR_VOS)); /* (11) */

}

Hi again,

I don't see any issue with your schematics. I even tested your code on Nucleo L053R8 and the interrupt was raised properly.

Please try to debug your application and check that the pin & the interrupt are configured properly before entering the sleep mode.

BR,

Jaroslav

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

fgeldenh
Associate II

Thank you for your help. I am sure I will find the issue. You can close this case now.

I just wanted to add, that a common theme we see here is "I have it in code but it doesn't work" and "I have it in schematics but it doesn't work". While one is SW and other HW, the point is the same: source code and schematics are detached from reality by the implementation.

In HW, the reality check is continuity measurement, or, if possible, turning the mcu pin to GPIO output and wiggling it in software while measuring on the outermost point of the whole path.

SW is usually much more complicated and there are more possible points of failure. The starting point is always reading out related registers' content and checking against expectation (according to RM). For interrupts, a (possibly incomplete) checklist is here. You can also simplify on the observation side, by toggling a pin in the ISR.

JW