第一范文网 - 专业文章范例文档资料分享平台

STM32f407 一个串口收传给另一个串口再发送出去串口收发设置

来源:用户分享 时间:2025/7/2 5:03:18 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

/* Includes ------------------------------------------------------------------*/ #include \ #include

void Delay(__IO uint32_t nCount);

//*********************************************** //函数功能:延时ms //入口参数:延时长度 //出口参数:无 //备注:

//************************************************ voidDelay_ms(u16 ms) {

u32 j;

for(;ms>0;ms--)

for(j=0;j<9700;j++); }

//*********************************************** //函数功能:IO配置 //入口参数:无

//出口参数:无 //备注:

//************************************************ voidGPIO_Configuration(void) {

GPIO_InitTypeDefGPIO_InitStructure;

/* GPIOD Periph clock enable */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

/* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure);

/* Configure PA0 pin as input floating */

//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //GPIO_Init(GPIOA, &GPIO_InitStructure);

}

//*********************************************** //函数功能:UART配置 //入口参数:无 //出口参数:无 //备注:

//************************************************ voidUSART_Configuration(void) {

USART_InitTypeDefUSART_InitStructure;

USART_InitStructure.USART_BaudRate =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; // 发送/接收使能

GPIO_StructInit(&GPIO_InitStructure);

/* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

/* Enable GPIO clock */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

/* Enable UART clock */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /* Connect PXx to USARTx_Tx*/

GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3); /* Connect PXx to USARTx_Rx*/

GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure);

/* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOC, &GPIO_InitStructure); /* USART configuration */

USART_Init(USART3,&USART_InitStructure); USART_ITConfig(USART3,USART_IT_RXNE,ENABLE); USART_ITConfig(USART3,USART_IT_TXE,ENABLE); /* Enable USART */

USART_Cmd(USART3, ENABLE); /* Enable UART clock */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); /* Connect PXx to USARTx_Tx*/

GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); /* Connect PXx to USARTx_Rx*/

GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6); GPIO_StructInit(&GPIO_InitStructure);

/* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure);

/* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOC, &GPIO_InitStructure);

/* USART configuration */

USART_Init(USART6,&USART_InitStructure); USART_ITConfig(USART6,USART_IT_RXNE,ENABLE); //USART_ITConfig(USART6,USART_IT_TXE,ENABLE); /* Enable USART */

USART_Cmd(USART6, ENABLE);

}

voidNVIC_Config(void) {

NVIC_InitTypeDefNVIC_InitStructure;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //嵌套优先级分组为1

NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; //嵌套通道为USART3_IRQn NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级为 0 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级为 0 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能 NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn; //嵌套通道为USART6_IRQn NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0; //抢占优先级为 0 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级为 0 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能 NVIC_Init(&NVIC_InitStructure); }

/**

* @brief Main program * @param None * @retvalNone

**

* @brief Delay Function.

* @paramnCount:specifies the Delay time length. * @retvalNone

*/

void Delay(__IO uint32_t nCount) {

while(nCount--) { } } /**

STM32f407 一个串口收传给另一个串口再发送出去串口收发设置.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c8pvyo1kkz3721et5igxe_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top