大家帮忙看看我这段串口代码·····总是不行,串口助手设置没错。。。。。

2019-07-21 02:51发布

[mw_shl_code=c,true]#include"stm32f10x.h" int main() { NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); USART_DeInit(USART1); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &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(USART1,&USART_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_Cmd(USART1,ENABLE); while(1); } void USART1_IRQHandler (void) { uint16_t a; if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET) { a=USART_ReceiveData(USART1); USART_SendData(USART1,a); } } [/mw_shl_code]

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
11条回答
xuande
1楼-- · 2019-07-21 14:13
 精彩回答 2  元偷偷看……
逆袭
2楼-- · 2019-07-21 16:58
 精彩回答 2  元偷偷看……
逆袭
3楼-- · 2019-07-21 19:09
回复【7楼】xuande:
---------------------------------
在串口助手那里,一直发送数据,没有接收,程序不知道有没有问题
jermy_z
4楼-- · 2019-07-22 00:00
回复【8楼】逆袭:
---------------------------------
自己debug看到底有没有进中断
逆袭
5楼-- · 2019-07-22 00:56
回复【11楼】逆袭:
---------------------------------
当初贪方便去网上复制代码没注意

一周热门 更多>