STM32f407 一个串口收传给另一个串口再发送出去串口收发设置.docx_第1页
STM32f407 一个串口收传给另一个串口再发送出去串口收发设置.docx_第2页
STM32f407 一个串口收传给另一个串口再发送出去串口收发设置.docx_第3页
STM32f407 一个串口收传给另一个串口再发送出去串口收发设置.docx_第4页
STM32f407 一个串口收传给另一个串口再发送出去串口收发设置.docx_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/* Includes -*/ #include stm32f4xx_conf.h #include void Delay(_IO uint32_t nCount);/*/函数功能:延时ms/入口参数:延时长度/出口参数:无/备 注:/*void Delay_ms(u16 ms)u32 j;for(;ms0;ms-)for(j=0;j9700;j+); /*/函数功能:IO配置/入口参数:无/出口参数:无/备 注:/*void GPIO_Configuration(void)GPIO_InitTypeDef GPIO_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配置/入口参数:无/出口参数:无/备 注:/*void USART_Configuration(void)USART_InitTypeDef USART_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; / 发送/接收使能/* 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_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_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);void NVIC_Config(void) NVIC_InitTypeDef NVIC_InitStructure;NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);/嵌套优先级分组为1NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; /嵌套通道为USART3_IRQnNVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /抢占优先级为 0NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /响应优先级为 0NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /通道中断使能NVIC_Init(&NVIC_InitStructure);NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn; /嵌套通道为USART6_IRQnNVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0; /抢占优先级为 0NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /响应优先级为 0NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /通道中断使能NVIC_Init(&NVIC_InitStructure);/* * brief Main program * param None * retval None* * brief Delay Function. * param nCount:specifies the Delay time length. * retval None */void Delay(_IO uint32_t nCount) while(nCount-) /*int fputc(int ch, FILE *f) /* Place your implementation of fputc here */ /* e.g. write a character to the USART */ USART_SendData(USART6, (uint8_t) ch); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART6, USART_FLAG_TC) = RESET) return ch;#ifdef USE_FULL_ASSERT/* * brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * param file: pointer to the source file name * param line: assert_param error line source number * retval None */void assert_failed(uint8_t* file, uint32_t line) /* User can add his own implementation to report the file name and line number, ex: printf(Wrong parameters value: file %s on line %drn, file, line) */ /* Infinite loop */ while (1) #endif/* * */ /* * */ /*中断*/uint8_t Uart3_Buffer255;uint8_t temp;uint8_t Flag=0;int RxCounter=0;int i=0;void USART3_IRQHandler(void) if(USART_GetITStatus(USART3,USART_IT_RXNE)!= RESET) /中断产生 USART_ClearITPendingBit(USART3,USART_IT_RXNE); /清除中断标志if(RxCounter=0) temp=USART_ReceiveData(USART3); if(temp=FRAMEHEAD) /*FRAMEHEAD*/ Uart3_BufferRxCounter+=temp; else Uart3_BufferRxCounter+=USART_ReceiveData(USART3); if(RxCounter=FRAMELEN) /*FRAMELEN*/ Flag=1; RxCounter=0; if(USART_GetFlagStatus(USART3,USART_FLAG_ORE) = SET) USART_ClearFlag(USART3,USART_FLAG_ORE); USART_ReceiveData(USART3); if(USART_GetITStatus(USART3,USART_IT_TXE)!= RESET) USART_ClearITPendingBit(USART3,USART_IT_TXE); if(Flag) for(i=0;iFRAMELEN;i+) USART_SendData(USART3,Uart3_Bufferi); /发送数据 while(USART_GetFlagStatus(USART3,USART_FLAG_TC)=RESET); Flag=0; u

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论