帮我写个用GD32F103rct6芯片实现rs232串口通信的程序
时间: 2023-03-02 13:57:08 浏览: 190
STM32(F103)RS232串口通信.rar
5星 · 资源好评率100%
我可以为你提供一个GD32F103rct6芯片实现RS232串口通信的示例程序,它是基于STM32CubeMX框架,使用Keil MDK-ARM开发环境:/* Includes ------------------------------------------------------------------*/
#include "main.h"/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
USART_InitTypeDef USART_InitStructure;/* Private function prototypes -----------------------------------------------*/
void USART_Config(void);/* Private functions ---------------------------------------------------------*//**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* USART configuration */
USART_Config(); /* Enable the USART */
USART_Cmd(USART1, ENABLE); /* Infinite loop */
while (1)
{ }
}/**
* @brief Configure the USART Peripheral
* @param None
* @retval None
*/
void USART_Config(void)
{
/* USART resources configuration (Clock, GPIO pins and USART registers) ----*/
/* USART configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
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; /* Configure and enable the USART */
STM_EVAL_COMInit(COM1, &USART_InitStructure);}#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 %d\r\n", file, line) */ /* Infinite loop */
while (1)
{
}
}
#endif
阅读全文