本帖最后由 181wh 于 2015-1-30 17:10 编辑
求助_Nucleo_F411RE_如何进入串口中断
现象是:进不了串口中断(使用Uart2)
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
如下是main.c
#include "stm32f4xx_hal.h"
#include "usart.h"
#include "gpio.h"
void SystemClock_Config(void);
int main(void)
{
uint8_t Receive_data[100] ;
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
while (1)
{
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5); //ÉÁ˸LED2
HAL_Delay(50);
HAL_UART_Receive(&huart2,Receive_data,10,1); //½ÓÊÕÊý¾Ý
HAL_UART_Transmit(&huart2,Receive_data,10,2); //»Ø´«ÊÕµ½µÄÊý¾Ý
}
}
/** System Clock Configuration
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 6;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
}
#endif
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
如下是:stm32f4XX_it.c
#include "stm32f4xx_hal.h"
#include "stm32f4xx.h"
#include "stm32f4xx_it.h"
extern UART_HandleTypeDef huart2;
void SysTick_Handler(void)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}
//USART2ÖжÏÈë¿Ú
void USART2_IRQHandler(void)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); //Èç¹û±¾ÌõÖ¸ÁîÖ´ÐУ¬PA10Öøß
HAL_UART_IRQHandler(&huart2);
}
void NMI_Handler(void)
{
HAL_RCC_NMI_IRQHandler();
}
工程文件:
STM32F411_test.rar
(3.09 MB)
|