教你手写串口收发数据(看完这篇你就会手动写啦,保姆级讲解)

您所在的位置:网站首页 串口收发数据的基本过程是什么 教你手写串口收发数据(看完这篇你就会手动写啦,保姆级讲解)

教你手写串口收发数据(看完这篇你就会手动写啦,保姆级讲解)

2024-07-11 03:50| 来源: 网络整理| 查看: 265

关于串口通信原理方面的文章:

嵌入式stm32 复习(工作用)— USART(串口)通信原理知识 2020.3.23 添加链接描述

先上完整串口收发部分代码!!! #include "usart1.h" #include "stdio.h" #include "string.h" #define CR1_OVER8_Set ((u16)0x8000) u16 USART_GetBound(USART_TypeDef* USARTx, int bound) { uint32_t integerdivider = 0x00, apbclock = 0x00; uint32_t tmpreg = 0x00; uint32_t fractionaldivider = 0x00; apbclock = 72000000; //如是USART1是72M,否则是36M /* Determine the integer part */ if ((USARTx->CR1 & CR1_OVER8_Set) != 0) { /* Integer part computing in case Oversampling mode is 8 Samples */ integerdivider = ((25 * apbclock) / (2 * bound)); } else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */ { /* Integer part computing in case Oversampling mode is 16 Samples */ integerdivider = ((25 * apbclock) / (4 * bound)); } tmpreg = (integerdivider / 100) 4)); /* Implement the fractional part in the register */ if ((USARTx->CR1 & CR1_OVER8_Set) != 0) { tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t) 0x07); } else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */ { tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t) 0x0F); } return tmpreg; } /** * @brief USART1 初始化 * @param None * @retval None */ void USART1_Init(int bound) { //1.使能时钟 RCC->APB2ENR |= 1 APB2ENR |= 1


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3