UART在STM32L0中设置
2019-07-14 17:30发布
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
我想在两块板之间建立UART通信(B-L072Z-LRWAN1和8PYA00-SIMCOM-EVB_V1.02)。我是嵌入式系统的新手,我需要一些帮助。我查看了ST提供的一些示例,但我的主板只有SPI示例。我尝试制作一个UART通信版本,查看所有可用的示例:- static USART_HandleTypeDef huart;
- huart.Instance = USART1;
- huart.Init.BaudRate = 115200;
- huart.Init.WordLength = UART_WORDLENGTH_8B;
- huart.Init.StopBits = UART_STOPBITS_1;
- huart.Init.Parity = UART_PARITY_NONE;
- huart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart.Init.Mode = UART_MODE_TX_RX;
- huart.Init.OverSampling = UART_OVERSAMPLING_16;
- huart.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if(HAL_UART_Init(&huart) != HAL_OK)
- {
- Error_Handler();
- }
- GPIO_InitTypeDef initStruct = {0};
- initStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- initStruct.Alternate = USART1_AF ;
- // TX
- initStruct.Mode = GPIO_MODE_AF_PP;
- initStruct.Pull = GPIO_NOPULL ;
- HW_GPIO_Init( txport, txpin, &initStruct);
- // RX
- initStruct.Mode = GPIO_MODE_INPUT;
- initStruct.Pull = GPIO_PULLUP;
- HW_GPIO_Init( rxport, rxpin, &initStruct );
复制代码请问缺少什么?
一周热门 更多>