AnsweredAssumed Answered

STM32L152 EXTI problem

Question asked by mor.vic on Nov 27, 2011
Latest reply on Dec 1, 2011 by mor.vic

Hi all.

First of all excuse my english

I am trying to implement the EXTI library but I am doing something wrong.

The program starts and send 0 by the uart (at this point all ok), then whait for a external interrupt with PA0 falling edgue (checked with the oscilloscope and its ok)
I dont know if the flag is reset or not, after applying the external interrupt the program not answered.

This is the code:

#include "stm32l1xx.h"                 
#include <stdio.h>

GPIO_InitTypeDef  GPIO_InitStructure;
USART_InitTypeDef  USART_InitStructure;
EXTI_InitTypeDef  EXTI_InitStructure;
NVIC_InitTypeDef  NVIC_InitStructure;

uint8_t CONT=0x00;

int main (void){

///UART CONFIGURATION////////////////////////////////////

 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

 GPIO_PinAFConfig(GPIOA, 2, GPIO_AF_USART2);

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
 GPIO_Init(GPIOA, &GPIO_InitStructure);

 USART_InitStructure.USART_BaudRate = 115200;
 USART_InitStructure.USART_WordLength = USART_WordLength_8b;
 USART_InitStructure.USART_StopBits = USART_StopBits_1;
 USART_InitStructure.USART_Parity = USART_Parity_No ;
 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
 USART_Init(USART2, &USART_InitStructure);
 USART_Cmd(USART2, ENABLE);

///EXTI CONFIGURATION//////////////////////////////

 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 
 SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
 EXTI_InitStructure.EXTI_Line = EXTI_Line0;
 EXTI_InitStructure.EXTI_LineCmd = ENABLE;
 EXTI_Init(&EXTI_InitStructure);

 EXTI_ClearITPendingBit(EXTI_Line0);

 NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

 

 USART_SendData(USART2, 0x30);

 while (1)
  {

  if (EXTI_GetITStatus(EXTI_Line0)== SET){
   EXTI_ClearITPendingBit(EXTI_Line0);
   EXTI_ClearFlag(EXTI_Line0);
   USART_SendData(USART2, CONT);
   CONT++;
   }
  }

}

 

I hope you can help me.

Thanks in advance and best regards

Outcomes