用STM32F103RCT6串口4能发数据。
改成
STM32F103RET6(管脚兼容,容量大些)
同样的程序就发不出数据了。这是为啥?(相同的程序RCT6就能发送)
卡死在
_INT32 UART4_SendChar(_UINT8 chr)
{
while((UART4->SR&0X40)==0)
;
UART4->DR = chr;
return OK;
}
UART4->SR = 0x0080, 怪了不?有没有高手帮忙分析一下啊。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
void UART4_Init(_UINT32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); // GPIOB时钟
//USART_DeInit(UART4); //复位串口4
//USART4_TX PB.C0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PA.2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOC, &GPIO_InitStructure);
//USART4_RX PC.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = bound;//一般设置为9600;
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(UART4, &USART_InitStructure); //初始化串口 4
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
//使能接收中断
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);//开启中断
USART_Cmd(UART4, ENABLE); //开中断
USART_ClearFlag(UART4, USART_FLAG_TC); //清除标志
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
}
_INT32 UART4_SendChar(_UINT8 chr)
{
while((UART4->SR&0X40)==0)
;
UART4->DR = chr;
return OK;
}
_INT32 UART4_SendData(_UINT8 *data, int len)
{
int i = 0;
for(i=0; i<len; i++)
{
UART4_SendChar(data[i]);
}
while(USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET);
while(USART_GetFlagStatus(UART4, USART_FLAG_TXE)==RESET)
{
USART_ClearITPendingBit(UART4 ,USART_IT_TXE);
}
return OK;
}
一周热门 更多>