cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with active interrupt of USART2 with GPIOD

willian2005
Associate II
Posted on May 21, 2012 at 01:25

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
3 REPLIES 3
Posted on May 21, 2012 at 02:23

What version of the FW library are you using?

I ask because you're using an extraordinarily bizarre pin/remapping sequence, and enabling GPIO clocks on different APB/AHB buses. GPIOD is on APB2, and PinAFConfig is not supported by STM32F1xx libraries.

Also you don't want to be enabling interrupts you can't service. For example if you have the TXE enabled, you'd better have some data to send, otherwise you will continually tail-chain back into the interrupt service routine and never execute foreground code again. This is sometimes called an interrupt storm. If you have no data to send you must disable the TXE interrupt until you do.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 21, 2012 at 02:36

Using the V3.5.0 FW library from here

http://www.st.com/internet/mcu/product/221jsp

http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/stm32f10x_stdperiph_lib.zip

Something like this would make more sense :

GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); // Move USART2 to PD5/6, et al
// * Enable the USART Interrupt * /
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// USART2_TX -> PD5 , USART2_RX -> PD6
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_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_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
willian2005
Associate II
Posted on May 21, 2012 at 04:16

Thanks for help : )

only changing my code by yours the software works.

the code looks like this:

void USART_Configuration(void)

{

    GPIO_InitTypeDef GPIO_InitStructure;

    USART_InitTypeDef USART_InitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOD, ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

    GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); // Move USART2 to PD5/6, et al

    // * Enable the USART Interrupt * /

    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    // USART2_TX -> PD5 , USART2_RX -> PD6

    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_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_Init(USART2, &USART_InitStructure);

    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

    USART_Cmd(USART2, ENABLE);

}

//this part is only test, and works

void USART2_IRQHandler(void)

{

    if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)

    {

        USART_ClearFlag(USART2,USART_FLAG_RXNE);

        sendData(''Come in Here HEHEHEHEHEHEH'');

    }

}

thanks for your attention