中级会员
 
- 积分
- 316
- 金钱
- 316
- 注册时间
- 2018-4-4
- 在线时间
- 30 小时
|
10金钱
本帖最后由 肥油玉帝 于 2018-7-17 10:31 编辑
在使用USART进行两个单片机之间的通信时,发送方遇到了如下问题:
使用
[mw_shl_code=c,true]USART_SendData(USART3, 0x0f);[/mw_shl_code]后查看,USART3_DR的内容,发现仍然为0
问题更进一步,当把Debug方式设置为“Use Simulator”时,一切正常,但是当设置为“J-LINK”是就出现问题了
USART3的配置如下:
[mw_shl_code=c,true]void Usart3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3,ENABLE);
/* USART3_TX -> PB10 , USART3_RX -> PB11 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Usart3 NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
//USART 初始化设置
USART_InitStructure.USART_BaudRate = 115200; //串口波特率
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_Init(USART3, &USART_InitStructure); //初始化串口3
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //开启串口接受中断
USART_ITConfig(USART3, USART_IT_TC, ENABLE); //开启串口发送完成中断
USART_Cmd(USART3, ENABLE); //使能串口3
}
[/mw_shl_code]
|
|