AnsweredAssumed Answered

Interrupt problem and UART problem

Question asked by yao.randy.001 on Dec 5, 2014
Latest reply on Dec 12, 2014 by yao.randy.001
Hi ST forum,

I have two separate problems: 1. How do I configure an interrupt to do X on rising edge and Y on falling edge? Currently, I can only do rising edge: (Solved, see below)

/*********************************************************************************************************
** Function name:           EXTI_PA0_Config
** Descriptions:            Configures interrupt for PA0
** Parameters:                    None
*********************************************************************************************************/


void EXTI_PA0_Config(void)
{
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);


     GPIO_main.GPIO_Mode = GPIO_Mode_IN;
     GPIO_main.GPIO_Speed = GPIO_Speed_25MHz;
     GPIO_main.GPIO_PuPd = GPIO_PuPd_NOPULL;
     GPIO_main.GPIO_Pin = GPIO_Pin_0; //Output PA0
     GPIO_Init(GPIOA,&GPIO_main);


     EXTI_main.EXTI_Line = EXTI_Line0;
     EXTI_main.EXTI_Mode = EXTI_Mode_Interrupt;
     EXTI_main.EXTI_Trigger = EXTI_Trigger_Rising; //need raising falling
     EXTI_main.EXTI_LineCmd = ENABLE;
     EXTI_Init(&EXTI_main);


     SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);


     NVIC_main.NVIC_IRQChannel = EXTI0_IRQn; //connect EXTI to line 0
     NVIC_main.NVIC_IRQChannelPreemptionPriority = 0x01;  //set both preemptive priority and sub-priority to lowest
     NVIC_main.NVIC_IRQChannelSubPriority = 0x01;
     NVIC_main.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_main);
}


void EXTI0_IRQHandler(void){
    NVIC_ClearPendingIRQ(EXTI0_IRQn);


    if(flag==0)
    {
         flag=1;
    }
    else if(flag==1)
    {
         flag=0;
    }
    EXTI->PR|=(1<<0); //write 1 to PR to clear - write 1 at bit 0?
}

Problem 2: I want to be able to receive UART. Currently I can only transmit UART. (Partially solved with bugs, see below)

/*********************************************************************************************************
** Function name:           UART1_Init
** Descriptions:            Initializes UART2_TX at PA2
** Parameters:                    None
*********************************************************************************************************/


void UART1_Init(void)
{
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);


    GPIO_main.GPIO_Pin = GPIO_Pin_2;
     GPIO_main.GPIO_Mode = GPIO_Mode_AF;
     GPIO_main.GPIO_PuPd = GPIO_PuPd_UP;
     GPIO_main.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_main.GPIO_OType = GPIO_OType_PP;
     GPIO_Init(GPIOA, &GPIO_main);


     GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_USART2);


     USART_main.USART_Mode = USART_Mode_Tx; //Transmit Mode, Receiver mode not currently required
     USART_main.USART_BaudRate = 115200; //This is right
     USART_main.USART_WordLength = USART_WordLength_8b; //8 bit data transmit
     USART_main.USART_Parity = USART_Parity_No; //
     USART_main.USART_StopBits = USART_StopBits_1; // 1 stop bit
     USART_main.USART_HardwareFlowControl =     USART_HardwareFlowControl_None;
     USART_Init(USART2,&USART_main);
        USART_Cmd(USART2,ENABLE);
}

Outcomes