刚接触这个,用的NUCLEO-F030R8的板子,我现在能做的都改了,板子就是接收不到数据,我把小程序图了,哪位大哥有时间帮我看一下的,万分感谢
#include "main.h"
/** @addtogroup IO_Toggle
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static __IO uint32_t TimingDelay;
uint8_t __IO BlinkSpeed = 0;
/* Private function prototypes -----------------------------------------------*/
RCC_ClocksTypeDef RCC_Clocks;
USART_InitTypeDef USART2_InitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
void USART2_IRQHandler (void)//Öжϴ¦Àíº¯Êý
{
if (USART_GetFlagStatus(USART2,USART_FLAG_RXNE) ==SET)
{
USART_SendData(USART2,USART_ReceiveData(USART2));
while (!USART_GetFlagStatus(USART2,USART_FLAG_TC));
}
USART_ClearITPendingBit(USART2,USART_IT_RXNE);//Öжϱê־λ
}
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f030.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f0xx.c file
*/
/* SysTick end of count event each 1ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
/* Initialize LED2 */
STM_EVAL_LEDInit(LED2);
/* Initialize User_Button on STM32NUCLEO */
STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);
/* Initiate Blink Speed variable */
BlinkSpeed = 0;
USART_StructInit(&USART2_InitStruct);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
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_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//
GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_1);
//nvic
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
//NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPriority= 0x03;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_DeInit(USART2);
USART_Init(USART2, &USART2_InitStruct);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
USART_ClearFlag (USART2,USART_FLAG_TC);
USART_Cmd(USART2, ENABLE);
/* Infinite loop */
while (1)
{
/* Test on blink speed */
if(BlinkSpeed == 0)
{
/*LED2 Toggle each 50ms*/
STM_EVAL_LEDToggle(LED2);
Delay(50);
}
else if(BlinkSpeed == 1)
{
STM_EVAL_LEDToggle(LED2);
/*LED2 Toggle each 200ms */
Delay(200);
}
//USART_SendData(USART2, 0x5555);
}
}
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 1 ms.
* @retval None
*/
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/**
* @brief Decrements the TimingDelay variable.
* @param None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
|