请问各位大神
usart的代码按照usart1写的初始化代码如下
void uart2_init(u32 bound){
//GPIO¶Ë¿úéèÖÃ
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
//′®¿ú2òy½Å¸′óÃó3éä
GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_USART2); //GPIOA2¸′óÃÎaUSART2
GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_USART2); //GPIOA3¸′óÃÎaUSART2
//USART1¶Ë¿úÅäÖÃ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; //GPIOA2óëGPIOA3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸′óÃ1|Äü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Ëù¶è100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //íÆíì¸′óÃêä3ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //éÏà-
GPIO_Init(GPIOA,&GPIO_InitStructure); //3õê¼»ˉPA2£¬
A3
//USART2 3õê¼»ˉéèÖÃ
USART_InitStructure.USART_BaudRate = bound; //2¨ìØÂêéèÖÃ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //×Ö3¤Îa8λêy¾Y¸ñê½
USART_InitStructure.USART_StopBits = USART_StopBits_1; //ò»¸öí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No; //ÎTÆæżD£Ñéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //ÎTó2¼têy¾Yá÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //êÕ·¢Ä£ê½
USART_Init(USART2, &USART_InitStructure); //3õê¼»ˉ′®¿ú1
USART_Cmd(USART2, ENABLE); //ê1Äü′®¿ú2
USART_ClearFlag(USART2, USART_FLAG_TC);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //¿aÆôÏà1ØÖD¶Ï
//Usart2 NVIC ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //′®¿ú2ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2; //ÇàÕ¼óÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉVIC¼Ä′æÆ÷¡¢
}
usart2只用来发送,但是在主函数中,发送并没有在串口调试助手看到输出
int main(void)
{
u8 t;
u8 len;
u16 times=0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é2
delay_init(168); //Ñóê±3õê¼»ˉ
uart_init(115200); //′®¿ú23õê¼»ˉ2¨ìØÂêÎa115200
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
while(1)
{
u8 i=31;
USART_SendData(USART2,i); //Ïò′®¿ú1·¢Ëíêy¾Y
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)!=SET); //μè′y·¢Ëí½áêø
i++;
}
}
我是用两个杜邦线把PA2 PA3接到了usb232的txd和rxd 请问是哪里有问题,没有printf做重定向
我都试了
不是是总线1吗??
一周热门 更多>