2021-12-8 14:35:44
1.串口发送函数
static void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* ÅäÖÃÖжÏÔ´ */ NVIC_InitStructure.NVIC_IRQChannel = RS232_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /** * @brief RS232_USART GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖá£115200 8-N-1 £¬ÖжϽÓÊÕģʽ * @param ÎÞ * @retval ÎÞ */ void Debug_USART_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_AHB1PeriphClockCmd( RS232_USART_RX_GPIO_CLK|RS232_USART_TX_GPIO_CLK, ENABLE); /* ʹÄÜ UART ʱÖÓ */ RCC_APB1PeriphClockCmd(RS232_USART_CLK, ENABLE); /* Á¬½Ó PXx µ½ USARTx_Tx*/ GPIO_PinAFConfig(RS232_USART_RX_GPIO_PORT,RS232_USART_RX_SOURCE, RS232_USART_RX_AF); /* Á¬½Ó PXx µ½ USARTx__Rx*/ GPIO_PinAFConfig(RS232_USART_TX_GPIO_PORT,RS232_USART_TX_SOURCE,RS232_USART_TX_AF); /* ÅäÖÃTxÒý½ÅΪ¸´Óù¦ÄÜ */ 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 = RS232_USART_TX_PIN ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(RS232_USART_TX_GPIO_PORT, &GPIO_InitStructure); /* ÅäÖÃRxÒý½ÅΪ¸´Óù¦ÄÜ */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = RS232_USART_RX_PIN; GPIO_Init(RS232_USART_RX_GPIO_PORT, &GPIO_InitStructure); /* ÅäÖô®¿ÚRS232_USART ģʽ */ USART_InitStructure.USART_BaudRate = RS232_USART_BAUDRATE; 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; USART_Init(RS232_USART, &USART_InitStructure); NVIC_Configuration(); /*ÅäÖô®¿Ú½ÓÊÕÖжÏ*/ USART_ITConfig(RS232_USART, USART_IT_RXNE, ENABLE); USART_Cmd(RS232_USART, ENABLE); } /***************** ·¢ËÍÒ»¸ö×Ö·û **********************/ static void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch ) { /* ·¢ËÍÒ»¸ö×Ö½ÚÊý¾Ýµ½USART1 */ USART_SendData(pUSARTx,ch); /* µÈ´ý·¢ËÍÍê±Ï */ while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET); } /***************** Ö¸¶¨³¤¶ÈµÄ·¢ËÍ×Ö·û´® **********************/ void Usart_SendStr_length( USART_TypeDef * pUSARTx, uint8_t *str,uint32_t strlen ) { unsigned int k=0; do { Usart_SendByte( pUSARTx, *(str + k) ); k++; } while(k < strlen); } /***************** ·¢ËÍ×Ö·û´® **********************/ void Usart_SendString( USART_TypeDef * pUSARTx, uint8_t *str) { unsigned int k=0; do { Usart_SendByte( pUSARTx, *(str + k) ); k++; } while(*(str + k)!='