修改不同串口的程序,要怎么做

1)第一步先要看原理图明确串口4对应PC10,PC11的引脚

以及使能GPIOC的时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

stm32有mipi接口吗(stme32板子串口4MINIUART4)(1)

2)在重定义fputc函数里面对应好串口4

int fputc(int ch, FILE *f)

{

while((USART4->SR&0X40)==0);//循环发送,直到发送完毕

USART4->DR = (u8) ch;

return ch;

}

3)串口4需要用两根杜邦线对应连接

串口4 UART4_TX PC10对应RXD

串口4 UART4_RX PC11对应TXD

4)其它的对照串口1例程修改成串口4就行

[C] 纯文本查看 复制代码

void uart_init(u32 bound){ //GPIO端口设置 GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE); //使能UART4时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //使能GPIOC时钟 //UART4_TX GPIOC.10 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PC10接RXD GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出 GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC.10 //UART4_RX GPIOC.11初始化0 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//PC11接TXD GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入 GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC.11 //Uart4 NVIC 配置 NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器 //UART 初始化设置 USART_InitStructure.USART_BaudRate = bound;//串口波特率 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 USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);//开启串口接受中断 USART_Cmd(UART4, ENABLE); //使能串口4 }

其它串口几的方法修改也是类似的,喜欢就点个赞

,