AnsweredAssumed Answered

Problems with active interrupt of USART2 with GPIOD

Question asked by henrique.willian on May 21, 2012
Latest reply on May 21, 2012 by henrique.willian
firstly sorry by my bad english...

I'm with a problem when i active the NVIC_InitTypeDef of USART2 it disable the GPIOD( I think it because my LCD use the /* PD.11(RST), PD.12(WR), PD.13(RD) , PD.14(CS), PD.15(RS)*/ and it stop of work when I active NVIC_InitTypeDef of USART2 ).

below there are the description of the PD0 - PD15

PD0<>CAN1_RX
PD1<>CAN1_TX
PD2/TIM3_ETR/UART5_RX
PD3<>USART2_CTS
PD4<>USART2_RTS
PD5<>USART2_TX
PD6<>USART2_RX
PD7<>USART2_CK
PD8<>USART3_TX/ETH_MII_RX_DV/ETH_RMII_CRS_DV
PD9<>USART3_RX/ETH_MII_RXD0/ETH_RMII_RXD0
PD10<>USART3_CK/ETH_MII_RXD1/ETH_RMII_RXD1
PD11<>USART3_CTS/ETH_MII_RXD2
PD12<>TIM4_CH1/USART3_RTS/ETH_MII_RXD3
PD13<>TIM4_CH2
PD14<>TIM4_CH3
PD15<>TIM4_CH4

My code:
 
CODE OF LCD:

GPIO_InitTypeDef GPIO_InitStructure;
    
    /* Enable GPIOC and GPIOE clocks */
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE);  
                        
    /* PE.00(D0), PE.01(D1), PE.02(D2), PE.03(D3), PE.04(D4), PE.05(D5), PE.06(D6), PE.07(D7), PE.08(D8)
     PE.09(D9), PE.10(D10), PE.11(D11), PE.12(D12), PE.13(D13), PE.14(D14), PE.15(D15)   */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOE, &GPIO_InitStructure);

    /* PD.11(RST), PD.12(WR), PD.13(RD) , PD.14(CS), PD.15(RS)*/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    
    /* PA.00(BL_PWM)*/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);


USART CODE:

    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOD  , ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); // 2.


    GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);

    GPIO_PinAFConfig  ( GPIOD, GPIO_PinSource5 , GPIO_AF_USART2) ;
    GPIO_PinAFConfig  ( GPIOD, GPIO_PinSource6 , GPIO_AF_USART2) ;

    NVIC_InitTypeDef NVIC_InitStructure;

    // * Enable the USART Interrupt * /
    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);


    // USART1_TX -> PB6 , USART1_RX -> PB7
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5  ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &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_ClockInitTypeDef USART_ClockInitStructure;
    USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
    USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
    USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
    USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
    USART_ClockInit(USART2, &USART_ClockInitStructure);

    /* Enable USART2 DMA Rx request */
    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
    USART_Init(USART2, &USART_InitStructure);
    USART_ClearFlag(USART2,USART_FLAG_TC);
    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
    USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
    USART_Cmd(USART2, ENABLE);


When I comment this line:
NVIC_Init(&NVIC_InitStructure);  the send of data and LCD works, but the interrupt handler not :( ..

When I don't comment this line:
NVIC_Init(&NVIC_InitStructure);  the send of data and interrupt handler works, but the LCD not :( ..

and I call the functions in this order:
USART_Configuration();
    RTC_Initialization();
    GPIO_Configuration();
    LCD_Initializtion(); 

Anyone know why it happen?

Thanks I'm using the STM32F107VC

Outcomes