我的usart 串口 使用串口助手 收不到数据

2019-03-23 20:17发布

配置如下
        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IPD;                                                                         //上拉输入
        GPIO_Init(GPIOB, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;                                                               // 复用推挽输出
        GPIO_Init(GPIOB, &GPIO_InitStructure);

        // 串口通信参数配置
        USART_InitStructure.USART_BaudRate            = USART3_BAUDRATE;                                // 波特率
        USART_InitStructure.USART_WordLength          = USART_WordLength_8b;                // 数据位数8位
        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_SendData(USARTx,0x26 /*data*/); 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
ly_hell
1楼-- · 2019-03-24 00:10
 精彩回答 2  元偷偷看……
乱起东城
2楼-- · 2019-03-24 00:38
USART_SendData(USARTx,0x26 /*data*/)其中 usartx=USART1|USART2|USART3就是 在调用的时候利用指针赋值了
jiaxinhui2011
3楼-- · 2019-03-24 05:29
void UART1Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_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_Tx | USART_Mode_Rx;
USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, ENABLE);
}




void UART1SendByte(unsigned char SendData)
{
USART_SendData(USART1,SendData);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

}

一周热门 更多>