cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault When I enable the USART3_8_IRQn interrupt.

stenasc
Senior
Posted on April 18, 2017 at 23:07

Hi Forum,

I'm using the stm32f091, but when I enable the USART3 interrupt, the system hard faults. I already use USARTS1 and 2 without any problem. Not sure what else is required, so I'd be grateful for some assistance. One thing I;d like to know is  how do you distinguish between interrupts from USARTS3 up to USART8.

Kind Regards

Bob

  USART_InitTypeDef USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

  // Enable GPIOC clock

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

 

  // Enable USART3 APB clock

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

    

 

  // Connect pin to Periph

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_1);   //  USART3 TX

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_1);   //  USART3 RX

 

  // Configure pins as AF pushpull

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

      

  USART_InitStructure.USART_BaudRate = 9600;

  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(USART3, &USART_InitStructure);

    

  USART_Cmd(USART3, ENABLE);

      

//  Enable the COM3 Receive interrupt: this interrupt is generated when the

//  COM3 receive data register is not empty

  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

  // USART3 IRQ Channel configuration

  NVIC_InitStructure.NVIC_IRQChannel = USART3_8_IRQn;   

  NVIC_InitStructure.NVIC_IRQChannelPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);
5 REPLIES 5
Posted on April 19, 2017 at 00:23

You check the status registers of the USART you plan to service. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stenasc
Senior
Posted on April 19, 2017 at 01:17

Fair enough regarding the usart article status register but any idea why the hard fault occurs.

Bob

Posted on April 19, 2017 at 01:25

Make sure the ISR's name matches that in the vector table, typically located with startup code.

JW

Posted on April 19, 2017 at 02:17

Are you sure it is getting a Hard Fault, and not just entering the Default Handler, which is also a while(1) loop?

Check the naming of your IRQHandler, and that it matches, and links properly with the entry in the Vector Table.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stenasc
Senior
Posted on April 19, 2017 at 14:38

Thanks very much. The interrupt was missing from the vector table. Adding it fixed the issue. Once again many thanks to the forum.

Kind Regards

Bob