新手入门
- 积分
- 15
- 金钱
- 15
- 注册时间
- 2018-5-18
- 在线时间
- 3 小时
|
1金钱
是用例程改的,但是无法进入中断,下面贴代码
usart1部分:
#include "bsp_usart1.h"
/**
* @brief USART1 GPIO ÅäÖÃ,1¤×÷Ä£ê½ÅäÖá£9600 8-N-1
* @param ÎT
* @retval ÎT
*/
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* USART1 GPIO config */
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USART1 mode config */
USART_InitStructure.USART_BaudRate = 4800;
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(USART1, &USART_InitStructure);
/* ê1Äü′®¿ú1½óêÕÖD¶Ï */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
}
/// ÅäÖÃUSART1½óêÕÖD¶Ï
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/// ÖØ¶¨Ïòc¿aoˉêyprintfμ½USART1
int fputc(int ch, FILE *f)
{
/* ·¢Ëíò»¸ö×Ö½úêy¾Yμ½USART1 */
USART_SendData(USART1, (uint8_t) ch);
/* μè′y·¢Ëííê±Ï */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return (ch);
}
int fgetc(FILE *f)
{
/* μè′y′®¿ú1êäèëêy¾Y */
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART1);
}
中断部分:
void USART1_IRQHandler(void)
{
uint8_t ch;
LED1_ON;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
//ch = USART1->DR;
ch = USART_ReceiveData(USART1);
printf( "%c", ch ); //½«½óêüμ½μÄêy¾YÖ±½ó·μ»Ø′òó¡
}
}
主函数部分:
USART1_Config();
NVIC_Configuration();
LED_GPIO_Config();
Delay(0x2FFFFF);
while(1)
{
for(t=0;t<8;t++)
{
USART_SendData(USART1, Rd[t]); //Ïò′®¿ú1·¢Ëíêy¾Y
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//μè′y·¢Ëí½áêø
}
}
求大神们指教
|
|