2026-02-08 17:48:22 +08:00
# include "sys.h"
# include "usart.h"
//////////////////////////////////////////////////////////////////////////////////
//<2F> <> <EFBFBD> <EFBFBD> ʹ <EFBFBD> <CAB9> ucos,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͷ<EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD> <EFBFBD> <EFBFBD> .
# if SYSTEM_SUPPORT_OS
# include "includes.h" //ucos ʹ <> <CAB9>
# endif
//////////////////////////////////////////////////////////////////////////////////
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֻ<EFBFBD> <D6BB> ѧϰʹ <CFB0> ã<EFBFBD> δ<EFBFBD> <CEB4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɣ <EFBFBD> <C9A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> κ<EFBFBD> <CEBA> <EFBFBD> ;
//ALIENTEK STM32F4̽<34> <CCBD> <EFBFBD> ߿<EFBFBD> <DFBF> <EFBFBD> <EFBFBD> <EFBFBD>
//<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> <31> ʼ <EFBFBD> <CABC>
//<2F> <> <EFBFBD> <EFBFBD> ԭ<EFBFBD> <D4AD> @ALIENTEK
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ̳:www.openedv.com
//<2F> <EFBFBD> <DEB8> <EFBFBD> <EFBFBD> <EFBFBD> :2014/6/10
//<2F> 汾<EFBFBD> <E6B1BE> V1.5
//<2F> <> Ȩ<EFBFBD> <C8A8> <EFBFBD> У <EFBFBD> <D0A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ؾ<EFBFBD> <D8BE> <EFBFBD>
//Copyright(C) <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӿƼ <D3BF> <C6BC> <EFBFBD> <EFBFBD> <EFBFBD> ˾ 2009-2019
//All rights reserved
//********************************************************************************
//V1.3<EFBFBD> <EFBFBD> ˵<EFBFBD> <EFBFBD>
//֧<> <D6A7> <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <D3A6> ͬƵ<CDAC> <C6B5> <EFBFBD> µĴ<C2B5> <C4B4> ڲ<EFBFBD> <DAB2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ˶<EFBFBD> printf<74> <66> ֧<EFBFBD> <D6A7>
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ˴ <EFBFBD> <CBB4> ڽ<EFBFBD> <DABD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EEB9A6> .
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> printf<74> <66> һ <EFBFBD> <D2BB> <EFBFBD> ַ<EFBFBD> <D6B7> <EFBFBD> ʧ<EFBFBD> <CAA7> bug
//V1.4<EFBFBD> <EFBFBD> ˵<EFBFBD> <EFBFBD>
//1,<2C> Ĵ<DEB8> <C4B4> ڳ<EFBFBD> ʼ <EFBFBD> <CABC> IO<49> <4F> bug
//2,<2C> <EFBFBD> <DEB8> <EFBFBD> USART_RX_STA,ʹ <> ô<EFBFBD> <C3B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֽ<EFBFBD> <D6BD> <EFBFBD> Ϊ2<CEAA> <32> 14<31> η<EFBFBD>
//3,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> USART_REC_LEN,<2C> <> <EFBFBD> ڶ<EFBFBD> <DAB6> 崮<EFBFBD> <E5B4AE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> յ<EFBFBD> <D5B5> ֽ<EFBFBD> <D6BD> <EFBFBD> (<28> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 2<EFBFBD> <32> 14<31> η<EFBFBD> )
//4,<2C> <EFBFBD> <DEB8> <EFBFBD> EN_USART1_RX<52> <58> ʹ <EFBFBD> ܷ<EFBFBD> ʽ
//V1.5<EFBFBD> <EFBFBD> ˵<EFBFBD> <EFBFBD>
//1,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> ˶<EFBFBD> UCOSII<49> <49> ֧<EFBFBD> <D6A7>
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ´ <EFBFBD> <C2B4> <EFBFBD> ,֧<> <D6A7> printf<74> <66> <EFBFBD> <EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫѡ <D2AA> <D1A1> use MicroLIB
# if 1
# pragma import(__use_no_semihosting)
//<2F> <> <EFBFBD> <D7BC> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> <D2AA> ֧<EFBFBD> ֺ<EFBFBD> <D6BA> <EFBFBD>
struct __FILE
{
int handle ;
} ;
FILE __stdout ;
//<2F> <> <EFBFBD> <EFBFBD> _sys_exit()<29> Ա<EFBFBD> <D4B1> <EFBFBD> ʹ <EFBFBD> ð<EFBFBD> <C3B0> <EFBFBD> <EFBFBD> <EFBFBD> ģʽ
void _sys_exit ( int x )
{
x = x ;
}
//<2F> ض<EFBFBD> <D8B6> <EFBFBD> fputc<74> <63> <EFBFBD> <EFBFBD>
int fputc ( int ch , FILE * f )
{
2026-02-09 17:29:30 +08:00
while ( ( UART4 - > SR & 0 X40 ) = = 0 ) ; //ѭ<> <D1AD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,ֱ<> <D6B1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
UART4 - > DR = ( u8 ) ch ;
2026-02-08 17:48:22 +08:00
return ch ;
}
# endif
//<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> жϷ<D0B6> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
//ע<> <D7A2> ,<2C> <> ȡUSARTx->SR<53> ܱ<EFBFBD> <DCB1> <EFBFBD> Ī<EFBFBD> <C4AA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ĵ<EFBFBD> <C4B4> <EFBFBD>
u8 USART_RX_BUF [ USART_REC_LEN ] ; //<2F> <> <EFBFBD> ջ<EFBFBD> <D5BB> <EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> USART_REC_LEN<45> <4E> <EFBFBD> ֽ<EFBFBD> .
//<2F> <> <EFBFBD> <EFBFBD> ״̬
//bit15<31> <35> <09> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɱ<EFBFBD> ־
//bit14<31> <34> <09> <> <EFBFBD> յ<EFBFBD> 0x0d
//bit13~0<> <30> <09> <> <EFBFBD> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> Ч<EFBFBD> ֽ<EFBFBD> <D6BD> <EFBFBD> Ŀ
u16 USART_RX_STA = 0 ; //<2F> <> <EFBFBD> <EFBFBD> ״̬<D7B4> <CCAC> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
/* <20> <> <EFBFBD> ջ<EFBFBD> <D5BB> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> USART_REC_LEN<45> <4E> <EFBFBD> ֽ<EFBFBD> . */
uint8_t g_usart1_rx_buf [ USART_REC_LEN ] ;
uint16_t g_usart1_rx_sta = 0 ;
uint16_t g_usart1_rx_state = 0 ;
uint16_t g_usart2_rx_state = 0 ;
uint16_t g_usart3_rx_state = 0 ;
uint16_t g_usart4_rx_state = 0 ;
uint16_t g_usart5_rx_state = 0 ;
uint16_t g_usart6_rx_state = 0 ;
uint8_t g_rx1_buffer [ RXBUFFERSIZE ] ; /* HAL<41> <4C> ʹ <EFBFBD> õĴ<C3B5> <C4B4> ڽ<EFBFBD> <DABD> ջ<EFBFBD> <D5BB> <EFBFBD> */
/* <20> <> <EFBFBD> ջ<EFBFBD> <D5BB> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> USART_REC_LEN<45> <4E> <EFBFBD> ֽ<EFBFBD> . */
uint8_t g_usart2_rx_buf [ USART_REC_LEN ] ;
uint16_t g_usart2_rx_sta = 0 ;
uint8_t g_rx2_buffer [ RXBUFFERSIZE ] ; /* HAL<41> <4C> ʹ <EFBFBD> õĴ<C3B5> <C4B4> ڽ<EFBFBD> <DABD> ջ<EFBFBD> <D5BB> <EFBFBD> */
/* <20> <> <EFBFBD> ջ<EFBFBD> <D5BB> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> USART_REC_LEN<45> <4E> <EFBFBD> ֽ<EFBFBD> . */
uint8_t g_usart3_rx_buf [ USART_REC_LEN ] ;
uint16_t g_usart3_rx_sta = 0 ;
uint8_t g_rx3_buffer [ RXBUFFERSIZE ] ; /* HAL<41> <4C> ʹ <EFBFBD> õĴ<C3B5> <C4B4> ڽ<EFBFBD> <DABD> ջ<EFBFBD> <D5BB> <EFBFBD> */
/* <20> <> <EFBFBD> ջ<EFBFBD> <D5BB> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> USART_REC_LEN<45> <4E> <EFBFBD> ֽ<EFBFBD> . */
uint8_t g_usart4_rx_buf [ USART_REC_LEN ] ;
uint16_t g_usart4_rx_sta = 0 ;
uint8_t g_rx4_buffer [ RXBUFFERSIZE ] ; /* HAL<41> <4C> ʹ <EFBFBD> õĴ<C3B5> <C4B4> ڽ<EFBFBD> <DABD> ջ<EFBFBD> <D5BB> <EFBFBD> */
/* <20> <> <EFBFBD> ջ<EFBFBD> <D5BB> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> USART_REC_LEN<45> <4E> <EFBFBD> ֽ<EFBFBD> . */
uint8_t g_usart5_rx_buf [ USART_REC_LEN ] ;
uint16_t g_usart5_rx_sta = 0 ;
uint8_t g_rx5_buffer [ RXBUFFERSIZE ] ; /* HAL<41> <4C> ʹ <EFBFBD> õĴ<C3B5> <C4B4> ڽ<EFBFBD> <DABD> ջ<EFBFBD> <D5BB> <EFBFBD> */
/* <20> <> <EFBFBD> ջ<EFBFBD> <D5BB> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> USART_REC_LEN<45> <4E> <EFBFBD> ֽ<EFBFBD> . */
uint8_t g_usart6_rx_buf [ USART_REC_LEN ] ;
uint16_t g_usart6_rx_sta = 0 ;
uint8_t g_rx6_buffer [ RXBUFFERSIZE ] ; /* HAL<41> <4C> ʹ <EFBFBD> õĴ<C3B5> <C4B4> ڽ<EFBFBD> <DABD> ջ<EFBFBD> <D5BB> <EFBFBD> */
char receive_buffer1 [ RXBUFFERSIZE ] = { 0 } ;
char receive_buffer2 [ RXBUFFERSIZE ] = { 0 } ;
char receive_buffer3 [ RXBUFFERSIZE ] = { 0 } ;
2026-02-08 17:48:22 +08:00
//<2F> <> ʼ <EFBFBD> <CABC> IO <20> <> <EFBFBD> <EFBFBD> 1
//bound:<3A> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2026-02-09 11:14:38 +08:00
void uart1_init ( u32 bound ) {
2026-02-08 17:48:22 +08:00
//GPIO<49> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure ;
USART_InitTypeDef USART_InitStructure ;
NVIC_InitTypeDef NVIC_InitStructure ;
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOA , ENABLE ) ; //ʹ <> <CAB9> GPIOAʱ<41> <CAB1>
RCC_APB2PeriphClockCmd ( RCC_APB2Periph_USART1 , ENABLE ) ; //ʹ <> <CAB9> USART1ʱ<31> <CAB1>
//<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> <31> Ӧ<EFBFBD> <D3A6> <EFBFBD> Ÿ<EFBFBD> <C5B8> <EFBFBD> ӳ<EFBFBD> <D3B3>
GPIO_PinAFConfig ( GPIOA , GPIO_PinSource9 , GPIO_AF_USART1 ) ; //GPIOA9<41> <39> <EFBFBD> <EFBFBD> ΪUSART1
GPIO_PinAFConfig ( GPIOA , GPIO_PinSource10 , GPIO_AF_USART1 ) ; //GPIOA10<31> <30> <EFBFBD> <EFBFBD> ΪUSART1
//USART1<54> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 ; //GPIOA9<41> <39> GPIOA10
GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ; //<2F> <> <EFBFBD> ù<EFBFBD> <C3B9> <EFBFBD>
GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ; //<2F> ٶ<EFBFBD> 50MHz
GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ; //<2F> <> <EFBFBD> 츴<EFBFBD> <ECB8B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_UP ; //<2F> <> <EFBFBD> <EFBFBD>
GPIO_Init ( GPIOA , & GPIO_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> PA9<41> <39> PA10
//USART1 <20> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_BaudRate = bound ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_WordLength = USART_WordLength_8b ; //<2F> ֳ<EFBFBD> Ϊ8λ<38> <CEBB> <EFBFBD> ݸ<EFBFBD> ʽ
USART_InitStructure . USART_StopBits = USART_StopBits_1 ; //һ <> <D2BB> ֹͣλ
USART_InitStructure . USART_Parity = USART_Parity_No ; //<2F> <> <EFBFBD> <EFBFBD> żУ <C5BC> <D0A3> λ
USART_InitStructure . USART_HardwareFlowControl = USART_HardwareFlowControl_None ; //<2F> <> Ӳ<EFBFBD> <D3B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_Mode = USART_Mode_Rx | USART_Mode_Tx ; //<2F> շ<EFBFBD> ģʽ
USART_Init ( USART1 , & USART_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 1
USART_Cmd ( USART1 , ENABLE ) ; //ʹ <> ܴ<EFBFBD> <DCB4> <EFBFBD> 1
//USART_ClearFlag(USART1, USART_FLAG_TC);
2026-02-09 11:14:38 +08:00
2026-02-08 17:48:22 +08:00
USART_ITConfig ( USART1 , USART_IT_RXNE , ENABLE ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
//Usart1 NVIC <20> <> <EFBFBD> <EFBFBD>
NVIC_InitStructure . NVIC_IRQChannel = USART1_IRQn ; //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> ж<EFBFBD> ͨ<EFBFBD> <CDA8>
NVIC_InitStructure . NVIC_IRQChannelPreemptionPriority = 3 ; //<2F> <> ռ <EFBFBD> <D5BC> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelSubPriority = 3 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelCmd = ENABLE ; //IRQͨ<51> <CDA8> ʹ <EFBFBD> <CAB9>
NVIC_Init ( & NVIC_InitStructure ) ; //<2F> <> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> IJ<EFBFBD> <C4B2> <EFBFBD> <EFBFBD> <EFBFBD> ʼ <EFBFBD> <CABC> VIC<49> Ĵ<EFBFBD> <C4B4> <EFBFBD> <EFBFBD> <EFBFBD>
}
void USART1_IRQHandler ( void ) //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> жϷ<D0B6> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
{
2026-02-09 17:29:30 +08:00
u8 uart1_data ;
if ( USART_GetITStatus ( USART1 , USART_IT_RXNE ) ! = RESET ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
{
USART_ClearITPendingBit ( USART1 , USART_IT_RXNE ) ;
uart1_data = USART_ReceiveData ( USART1 ) ; //<2F> <> ȡ<EFBFBD> <C8A1> <EFBFBD> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
g_rx1_buffer [ 0 ] = uart1_data ;
2026-02-10 01:35:53 +08:00
2026-02-10 01:46:09 +08:00
//Uart6_Send_data(g_rx1_buffer,1);
2026-02-10 01:35:53 +08:00
if ( g_usart1_rx_sta = = 0 & & g_rx1_buffer [ 0 ] = = 0xBB )
2026-02-09 17:29:30 +08:00
{
g_usart1_rx_buf [ 0 ] = g_rx1_buffer [ 0 ] ;
g_usart1_rx_sta = 1 ;
}
else if ( g_usart1_rx_sta ! = 0 )
{
g_usart1_rx_buf [ g_usart1_rx_sta & 0 X3FFF ] = g_rx1_buffer [ 0 ] ;
g_usart1_rx_sta + + ;
if ( g_usart1_rx_sta > ( USART_REC_LEN - 1 ) )
{
g_usart1_rx_sta = 0 ;
g_usart1_rx_state = 1 ;
// memset(g_usart1_rx_buf, 0x0, 6);
// g_rx1_buffer[0] = 0x0;
}
}
}
else if ( USART_GetITStatus ( USART1 , USART_IT_TXE ) ! = RESET )
{
USART_ClearITPendingBit ( USART1 , USART_IT_TXE ) ;
}
2026-02-08 17:48:22 +08:00
}
2026-02-09 11:14:38 +08:00
void uart2_init ( u32 bound ) {
//GPIO<49> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure ;
USART_InitTypeDef USART_InitStructure ;
NVIC_InitTypeDef NVIC_InitStructure ;
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOA , ENABLE ) ; //ʹ <> <CAB9> GPIOAʱ<41> <CAB1>
2026-02-10 09:08:03 +08:00
RCC_APB1PeriphClockCmd ( RCC_APB1Periph_USART2 , ENABLE ) ; //ʹ <> <CAB9> USART1ʱ<31> <CAB1>
2026-02-09 11:14:38 +08:00
2026-02-10 09:08:03 +08:00
//<2F> <> <EFBFBD> <EFBFBD> 2<EFBFBD> <32> Ӧ<EFBFBD> <D3A6> <EFBFBD> Ÿ<EFBFBD> <C5B8> <EFBFBD> ӳ<EFBFBD> <D3B3>
GPIO_PinAFConfig ( GPIOA , GPIO_PinSource2 , GPIO_AF_USART2 ) ; //GPIOA2<41> <32> <EFBFBD> <EFBFBD> ΪUSART2
GPIO_PinAFConfig ( GPIOA , GPIO_PinSource3 , GPIO_AF_USART2 ) ; //GPIOA3<41> <33> <EFBFBD> <EFBFBD> ΪUSART3
2026-02-09 11:14:38 +08:00
//USART1<54> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
GPIO_InitStructure . GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 ; //GPIOA9<41> <39> GPIOA10
2026-02-09 11:14:38 +08:00
GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ; //<2F> <> <EFBFBD> ù<EFBFBD> <C3B9> <EFBFBD>
GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ; //<2F> ٶ<EFBFBD> 50MHz
GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ; //<2F> <> <EFBFBD> 츴<EFBFBD> <ECB8B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_UP ; //<2F> <> <EFBFBD> <EFBFBD>
GPIO_Init ( GPIOA , & GPIO_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> PA9<41> <39> PA10
//USART1 <20> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_BaudRate = bound ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_WordLength = USART_WordLength_8b ; //<2F> ֳ<EFBFBD> Ϊ8λ<38> <CEBB> <EFBFBD> ݸ<EFBFBD> ʽ
USART_InitStructure . USART_StopBits = USART_StopBits_1 ; //һ <> <D2BB> ֹͣλ
USART_InitStructure . USART_Parity = USART_Parity_No ; //<2F> <> <EFBFBD> <EFBFBD> żУ <C5BC> <D0A3> λ
USART_InitStructure . USART_HardwareFlowControl = USART_HardwareFlowControl_None ; //<2F> <> Ӳ<EFBFBD> <D3B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_Mode = USART_Mode_Rx | USART_Mode_Tx ; //<2F> շ<EFBFBD> ģʽ
USART_Init ( USART2 , & USART_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 1
USART_Cmd ( USART2 , ENABLE ) ; //ʹ <> ܴ<EFBFBD> <DCB4> <EFBFBD> 1
//USART_ClearFlag(USART1, USART_FLAG_TC);
2026-02-09 17:29:30 +08:00
USART_ITConfig ( USART2 , USART_IT_RXNE , ENABLE ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
2026-02-09 11:14:38 +08:00
//Usart1 NVIC <20> <> <EFBFBD> <EFBFBD>
NVIC_InitStructure . NVIC_IRQChannel = USART2_IRQn ; //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> ж<EFBFBD> ͨ<EFBFBD> <CDA8>
NVIC_InitStructure . NVIC_IRQChannelPreemptionPriority = 3 ; //<2F> <> ռ <EFBFBD> <D5BC> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelSubPriority = 3 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelCmd = ENABLE ; //IRQͨ<51> <CDA8> ʹ <EFBFBD> <CAB9>
NVIC_Init ( & NVIC_InitStructure ) ; //<2F> <> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> IJ<EFBFBD> <C4B2> <EFBFBD> <EFBFBD> <EFBFBD> ʼ <EFBFBD> <CABC> VIC<49> Ĵ<EFBFBD> <C4B4> <EFBFBD> <EFBFBD> <EFBFBD>
}
void USART2_IRQHandler ( void ) //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> жϷ<D0B6> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
{
2026-02-09 17:29:30 +08:00
u8 uart1_data ;
if ( USART_GetITStatus ( USART2 , USART_IT_RXNE ) ! = RESET ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
{
USART_ClearITPendingBit ( USART2 , USART_IT_RXNE ) ;
uart1_data = USART_ReceiveData ( USART2 ) ; //<2F> <> ȡ<EFBFBD> <C8A1> <EFBFBD> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
g_rx2_buffer [ 0 ] = uart1_data ;
//USART_ClearITPendingBit(USART1, USART_IT_RXNE);
if ( g_usart2_rx_sta = = 0 & & g_rx2_buffer [ 0 ] = = 0xBB )
{
g_usart2_rx_buf [ 0 ] = g_rx2_buffer [ 0 ] ;
g_usart2_rx_sta = 1 ;
}
else if ( g_usart2_rx_sta ! = 0 )
{
g_usart2_rx_buf [ g_usart2_rx_sta & 0 X3FFF ] = g_rx2_buffer [ 0 ] ;
g_usart2_rx_sta + + ;
if ( g_usart2_rx_sta > ( USART_REC_LEN - 1 ) )
{
g_usart2_rx_sta = 0 ;
g_usart2_rx_state = 1 ;
// memset(g_usart1_rx_buf, 0x0, 6);
// g_rx1_buffer[0] = 0x0;
}
}
}
else if ( USART_GetITStatus ( USART2 , USART_IT_TXE ) ! = RESET )
{
USART_ClearITPendingBit ( USART2 , USART_IT_TXE ) ;
}
2026-02-09 11:14:38 +08:00
}
void uart3_init ( u32 bound ) {
//GPIO<49> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure ;
USART_InitTypeDef USART_InitStructure ;
NVIC_InitTypeDef NVIC_InitStructure ;
2026-02-09 17:29:30 +08:00
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOD , ENABLE ) ; //ʹ <> <CAB9> GPIOAʱ<41> <CAB1>
2026-02-10 09:08:03 +08:00
RCC_APB1PeriphClockCmd ( RCC_APB1Periph_USART3 , ENABLE ) ; //ʹ <> <CAB9> USART1ʱ<31> <CAB1>
2026-02-09 11:14:38 +08:00
2026-02-10 09:08:03 +08:00
//<2F> <> <EFBFBD> <EFBFBD> 3<EFBFBD> <33> Ӧ<EFBFBD> <D3A6> <EFBFBD> Ÿ<EFBFBD> <C5B8> <EFBFBD> ӳ<EFBFBD> <D3B3>
2026-02-11 09:44:25 +08:00
GPIO_PinAFConfig ( GPIOD , GPIO_PinSource8 , GPIO_AF_USART3 ) ; //GPIOD8<44> <38> <EFBFBD> <EFBFBD> ΪUSART1
GPIO_PinAFConfig ( GPIOD , GPIO_PinSource9 , GPIO_AF_USART3 ) ; //GPIOD9<44> <39> <EFBFBD> <EFBFBD> ΪUSART1
2026-02-09 11:14:38 +08:00
2026-02-10 09:08:03 +08:00
//USART3<54> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 ; //
2026-02-09 11:14:38 +08:00
GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ; //<2F> <> <EFBFBD> ù<EFBFBD> <C3B9> <EFBFBD>
GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ; //<2F> ٶ<EFBFBD> 50MHz
GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ; //<2F> <> <EFBFBD> 츴<EFBFBD> <ECB8B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_UP ; //<2F> <> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
GPIO_Init ( GPIOD , & GPIO_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> PA9<41> <39> PA10
2026-02-09 11:14:38 +08:00
2026-02-10 09:08:03 +08:00
//USART3 <20> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2026-02-09 11:14:38 +08:00
USART_InitStructure . USART_BaudRate = bound ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_WordLength = USART_WordLength_8b ; //<2F> ֳ<EFBFBD> Ϊ8λ<38> <CEBB> <EFBFBD> ݸ<EFBFBD> ʽ
USART_InitStructure . USART_StopBits = USART_StopBits_1 ; //һ <> <D2BB> ֹͣλ
USART_InitStructure . USART_Parity = USART_Parity_No ; //<2F> <> <EFBFBD> <EFBFBD> żУ <C5BC> <D0A3> λ
USART_InitStructure . USART_HardwareFlowControl = USART_HardwareFlowControl_None ; //<2F> <> Ӳ<EFBFBD> <D3B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_Mode = USART_Mode_Rx | USART_Mode_Tx ; //<2F> շ<EFBFBD> ģʽ
USART_Init ( USART3 , & USART_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 1
USART_Cmd ( USART3 , ENABLE ) ; //ʹ <> ܴ<EFBFBD> <DCB4> <EFBFBD> 1
//USART_ClearFlag(USART1, USART_FLAG_TC);
2026-02-09 17:29:30 +08:00
USART_ITConfig ( USART3 , USART_IT_RXNE , ENABLE ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
2026-02-09 11:14:38 +08:00
//Usart1 NVIC <20> <> <EFBFBD> <EFBFBD>
NVIC_InitStructure . NVIC_IRQChannel = USART3_IRQn ; //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> ж<EFBFBD> ͨ<EFBFBD> <CDA8>
NVIC_InitStructure . NVIC_IRQChannelPreemptionPriority = 3 ; //<2F> <> ռ <EFBFBD> <D5BC> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelSubPriority = 3 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelCmd = ENABLE ; //IRQͨ<51> <CDA8> ʹ <EFBFBD> <CAB9>
NVIC_Init ( & NVIC_InitStructure ) ; //<2F> <> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> IJ<EFBFBD> <C4B2> <EFBFBD> <EFBFBD> <EFBFBD> ʼ <EFBFBD> <CABC> VIC<49> Ĵ<EFBFBD> <C4B4> <EFBFBD> <EFBFBD> <EFBFBD>
}
void USART3_IRQHandler ( void ) //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> жϷ<D0B6> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
{
2026-02-09 17:29:30 +08:00
u8 uart1_data ;
if ( USART_GetITStatus ( USART3 , USART_IT_RXNE ) ! = RESET ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
{
USART_ClearITPendingBit ( USART3 , USART_IT_RXNE ) ;
2026-02-10 01:35:53 +08:00
uart1_data = USART_ReceiveData ( USART3 ) ; //<2F> <> ȡ<EFBFBD> <C8A1> <EFBFBD> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
g_rx3_buffer [ 0 ] = uart1_data ;
if ( g_usart3_rx_sta = = 0 & & g_rx3_buffer [ 0 ] = = 0xBB )
2026-02-09 17:29:30 +08:00
{
g_usart3_rx_buf [ 0 ] = g_rx3_buffer [ 0 ] ;
g_usart3_rx_sta = 1 ;
}
else if ( g_usart3_rx_sta ! = 0 )
{
g_usart3_rx_buf [ g_usart3_rx_sta & 0 X3FFF ] = g_rx3_buffer [ 0 ] ;
g_usart3_rx_sta + + ;
if ( g_usart3_rx_sta > ( USART_REC_LEN - 1 ) )
{
g_usart3_rx_sta = 0 ;
g_usart3_rx_state = 1 ;
// memset(g_usart1_rx_buf, 0x0, 6);
// g_rx1_buffer[0] = 0x0;
}
}
}
else if ( USART_GetITStatus ( USART3 , USART_IT_TXE ) ! = RESET )
{
USART_ClearITPendingBit ( USART3 , USART_IT_TXE ) ;
}
2026-02-09 11:14:38 +08:00
}
void uart4_init ( u32 bound ) {
//GPIO<49> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure ;
USART_InitTypeDef USART_InitStructure ;
NVIC_InitTypeDef NVIC_InitStructure ;
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOA , ENABLE ) ; //ʹ <> <CAB9> GPIOAʱ<41> <CAB1>
2026-02-10 10:28:33 +08:00
RCC_APB1PeriphClockCmd ( RCC_APB1Periph_UART4 , ENABLE ) ; //ʹ <> <CAB9> USART1ʱ<31> <CAB1>
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
// SYSCFG->PMC |= ((uint32_t)0x00008000); // <20> <> <EFBFBD> <EFBFBD> USART4<54> <34> ӳ<EFBFBD> 䣨PA0/PA1<41> <31>
2026-02-09 11:14:38 +08:00
//<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> <31> Ӧ<EFBFBD> <D3A6> <EFBFBD> Ÿ<EFBFBD> <C5B8> <EFBFBD> ӳ<EFBFBD> <D3B3>
2026-02-10 10:28:33 +08:00
GPIO_PinAFConfig ( GPIOA , GPIO_PinSource0 , GPIO_AF_UART4 ) ; //GPIOA9<41> <39> <EFBFBD> <EFBFBD> ΪUSART1
GPIO_PinAFConfig ( GPIOA , GPIO_PinSource1 , GPIO_AF_UART4 ) ; //GPIOA10<31> <30> <EFBFBD> <EFBFBD> ΪUSART1
2026-02-09 11:14:38 +08:00
//USART1<54> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
GPIO_InitStructure . GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 ; //GPIOA9<41> <39> GPIOA10
2026-02-09 11:14:38 +08:00
GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ; //<2F> <> <EFBFBD> ù<EFBFBD> <C3B9> <EFBFBD>
GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ; //<2F> ٶ<EFBFBD> 50MHz
GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ; //<2F> <> <EFBFBD> 츴<EFBFBD> <ECB8B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_UP ; //<2F> <> <EFBFBD> <EFBFBD>
GPIO_Init ( GPIOA , & GPIO_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> PA9<41> <39> PA10
//USART1 <20> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_BaudRate = bound ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_WordLength = USART_WordLength_8b ; //<2F> ֳ<EFBFBD> Ϊ8λ<38> <CEBB> <EFBFBD> ݸ<EFBFBD> ʽ
USART_InitStructure . USART_StopBits = USART_StopBits_1 ; //һ <> <D2BB> ֹͣλ
USART_InitStructure . USART_Parity = USART_Parity_No ; //<2F> <> <EFBFBD> <EFBFBD> żУ <C5BC> <D0A3> λ
USART_InitStructure . USART_HardwareFlowControl = USART_HardwareFlowControl_None ; //<2F> <> Ӳ<EFBFBD> <D3B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_Mode = USART_Mode_Rx | USART_Mode_Tx ; //<2F> շ<EFBFBD> ģʽ
2026-02-09 17:29:30 +08:00
USART_Init ( UART4 , & USART_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 1
2026-02-09 11:14:38 +08:00
2026-02-09 17:29:30 +08:00
USART_Cmd ( UART4 , ENABLE ) ; //ʹ <> ܴ<EFBFBD> <DCB4> <EFBFBD> 1
2026-02-09 11:14:38 +08:00
//USART_ClearFlag(USART1, USART_FLAG_TC);
2026-02-09 17:29:30 +08:00
USART_ITConfig ( UART4 , USART_IT_RXNE , ENABLE ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
2026-02-09 11:14:38 +08:00
//Usart1 NVIC <20> <> <EFBFBD> <EFBFBD>
NVIC_InitStructure . NVIC_IRQChannel = UART4_IRQn ; //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> ж<EFBFBD> ͨ<EFBFBD> <CDA8>
NVIC_InitStructure . NVIC_IRQChannelPreemptionPriority = 3 ; //<2F> <> ռ <EFBFBD> <D5BC> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelSubPriority = 3 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelCmd = ENABLE ; //IRQͨ<51> <CDA8> ʹ <EFBFBD> <CAB9>
NVIC_Init ( & NVIC_InitStructure ) ; //<2F> <> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> IJ<EFBFBD> <C4B2> <EFBFBD> <EFBFBD> <EFBFBD> ʼ <EFBFBD> <CABC> VIC<49> Ĵ<EFBFBD> <C4B4> <EFBFBD> <EFBFBD> <EFBFBD>
}
void UART4_IRQHandler ( void ) //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> жϷ<D0B6> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
{
u8 Res ;
}
void uart5_init ( u32 bound ) {
//GPIO<49> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure ;
USART_InitTypeDef USART_InitStructure ;
NVIC_InitTypeDef NVIC_InitStructure ;
2026-02-09 17:29:30 +08:00
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOC , ENABLE ) ; //ʹ <> <CAB9> GPIOAʱ<41> <CAB1>
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOD , ENABLE ) ; //ʹ <> <CAB9> GPIOAʱ<41> <CAB1>
2026-02-11 09:44:25 +08:00
RCC_APB1PeriphClockCmd ( RCC_APB1Periph_UART5 , ENABLE ) ; //ʹ <> <CAB9> USART1ʱ<31> <CAB1>
2026-02-09 11:14:38 +08:00
//<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> <31> Ӧ<EFBFBD> <D3A6> <EFBFBD> Ÿ<EFBFBD> <C5B8> <EFBFBD> ӳ<EFBFBD> <D3B3>
2026-02-09 17:29:30 +08:00
GPIO_PinAFConfig ( GPIOC , GPIO_PinSource12 , GPIO_AF_UART5 ) ; //GPIOA9<41> <39> <EFBFBD> <EFBFBD> ΪUSART1
GPIO_PinAFConfig ( GPIOD , GPIO_PinSource2 , GPIO_AF_UART5 ) ; //GPIOA10<31> <30> <EFBFBD> <EFBFBD> ΪUSART1
2026-02-09 11:14:38 +08:00
//USART1<54> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
GPIO_InitStructure . GPIO_Pin = GPIO_Pin_12 ; //GPIOA9<41> <39> GPIOA10
2026-02-09 11:14:38 +08:00
GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ; //<2F> <> <EFBFBD> ù<EFBFBD> <C3B9> <EFBFBD>
GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ; //<2F> ٶ<EFBFBD> 50MHz
GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ; //<2F> <> <EFBFBD> 츴<EFBFBD> <ECB8B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_UP ; //<2F> <> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
GPIO_Init ( GPIOC , & GPIO_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> PA9<41> <39> PA10
GPIO_InitStructure . GPIO_Pin = GPIO_Pin_2 ; //GPIOA9<41> <39> GPIOA10
GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ; //<2F> <> <EFBFBD> ù<EFBFBD> <C3B9> <EFBFBD>
GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ; //<2F> ٶ<EFBFBD> 50MHz
2026-02-11 09:44:25 +08:00
GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ; //<2F> <> <EFBFBD> 츴<EFBFBD> <ECB8B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_UP ; //<2F> <> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
GPIO_Init ( GPIOD , & GPIO_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> PA9<41> <39> PA10
2026-02-09 11:14:38 +08:00
//USART1 <20> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_BaudRate = bound ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_WordLength = USART_WordLength_8b ; //<2F> ֳ<EFBFBD> Ϊ8λ<38> <CEBB> <EFBFBD> ݸ<EFBFBD> ʽ
USART_InitStructure . USART_StopBits = USART_StopBits_1 ; //һ <> <D2BB> ֹͣλ
USART_InitStructure . USART_Parity = USART_Parity_No ; //<2F> <> <EFBFBD> <EFBFBD> żУ <C5BC> <D0A3> λ
USART_InitStructure . USART_HardwareFlowControl = USART_HardwareFlowControl_None ; //<2F> <> Ӳ<EFBFBD> <D3B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_Mode = USART_Mode_Rx | USART_Mode_Tx ; //<2F> շ<EFBFBD> ģʽ
2026-02-09 17:29:30 +08:00
USART_Init ( UART5 , & USART_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 1
2026-02-09 11:14:38 +08:00
2026-02-09 17:29:30 +08:00
USART_Cmd ( UART5 , ENABLE ) ; //ʹ <> ܴ<EFBFBD> <DCB4> <EFBFBD> 1
2026-02-09 11:14:38 +08:00
//USART_ClearFlag(USART1, USART_FLAG_TC);
2026-02-09 17:29:30 +08:00
USART_ITConfig ( UART5 , USART_IT_RXNE , ENABLE ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
2026-02-09 11:14:38 +08:00
//Usart1 NVIC <20> <> <EFBFBD> <EFBFBD>
NVIC_InitStructure . NVIC_IRQChannel = UART5_IRQn ; //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> ж<EFBFBD> ͨ<EFBFBD> <CDA8>
NVIC_InitStructure . NVIC_IRQChannelPreemptionPriority = 3 ; //<2F> <> ռ <EFBFBD> <D5BC> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelSubPriority = 3 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelCmd = ENABLE ; //IRQͨ<51> <CDA8> ʹ <EFBFBD> <CAB9>
NVIC_Init ( & NVIC_InitStructure ) ; //<2F> <> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> IJ<EFBFBD> <C4B2> <EFBFBD> <EFBFBD> <EFBFBD> ʼ <EFBFBD> <CABC> VIC<49> Ĵ<EFBFBD> <C4B4> <EFBFBD> <EFBFBD> <EFBFBD>
}
void UART5_IRQHandler ( void ) //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> жϷ<D0B6> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
{
u8 Res ;
}
void uart6_init ( u32 bound ) {
//GPIO<49> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure ;
USART_InitTypeDef USART_InitStructure ;
NVIC_InitTypeDef NVIC_InitStructure ;
2026-02-09 17:29:30 +08:00
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOC , ENABLE ) ; //ʹ <> <CAB9> GPIOAʱ<41> <CAB1>
RCC_APB2PeriphClockCmd ( RCC_APB2Periph_USART6 , ENABLE ) ; //ʹ <> <CAB9> USART1ʱ<31> <CAB1>
2026-02-09 11:14:38 +08:00
//<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> <31> Ӧ<EFBFBD> <D3A6> <EFBFBD> Ÿ<EFBFBD> <C5B8> <EFBFBD> ӳ<EFBFBD> <D3B3>
2026-02-10 01:35:53 +08:00
//GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART1); //GPIOA9<41> <39> <EFBFBD> <EFBFBD> ΪUSART1
//GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART1); //GPIOA10<31> <30> <EFBFBD> <EFBFBD> ΪUSART1 <20> <> <EFBFBD> ڸ<EFBFBD> <DAB8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ô<EFBFBD> <C3B4> <EFBFBD>
2026-02-09 11:14:38 +08:00
2026-02-10 01:35:53 +08:00
// 3. <20> <> <EFBFBD> Ÿ<EFBFBD> <C5B8> <EFBFBD> ӳ<EFBFBD> 䣨<EFBFBD> <E4A3A8> PC6/PC7ӳ<37> 䵽USART6<54> <36>
GPIO_PinAFConfig ( GPIOC , GPIO_PinSource6 , GPIO_AF_USART6 ) ; // PC6 -> USART6_TX
GPIO_PinAFConfig ( GPIOC , GPIO_PinSource7 , GPIO_AF_USART6 ) ; // PC7 -> USART6_RX
2026-02-09 11:14:38 +08:00
//USART1<54> ˿<EFBFBD> <CBBF> <EFBFBD> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
GPIO_InitStructure . GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 ; //GPIOA9<41> <39> GPIOA10
2026-02-09 11:14:38 +08:00
GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ; //<2F> <> <EFBFBD> ù<EFBFBD> <C3B9> <EFBFBD>
GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ; //<2F> ٶ<EFBFBD> 50MHz
GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ; //<2F> <> <EFBFBD> 츴<EFBFBD> <ECB8B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_UP ; //<2F> <> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
GPIO_Init ( GPIOC , & GPIO_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> PA9<41> <39> PA10
2026-02-09 11:14:38 +08:00
//USART1 <20> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_BaudRate = bound ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_WordLength = USART_WordLength_8b ; //<2F> ֳ<EFBFBD> Ϊ8λ<38> <CEBB> <EFBFBD> ݸ<EFBFBD> ʽ
USART_InitStructure . USART_StopBits = USART_StopBits_1 ; //һ <> <D2BB> ֹͣλ
USART_InitStructure . USART_Parity = USART_Parity_No ; //<2F> <> <EFBFBD> <EFBFBD> żУ <C5BC> <D0A3> λ
USART_InitStructure . USART_HardwareFlowControl = USART_HardwareFlowControl_None ; //<2F> <> Ӳ<EFBFBD> <D3B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
USART_InitStructure . USART_Mode = USART_Mode_Rx | USART_Mode_Tx ; //<2F> շ<EFBFBD> ģʽ
2026-02-09 17:29:30 +08:00
USART_Init ( USART6 , & USART_InitStructure ) ; //<2F> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 1
2026-02-09 11:14:38 +08:00
2026-02-09 17:29:30 +08:00
USART_Cmd ( USART6 , ENABLE ) ; //ʹ <> ܴ<EFBFBD> <DCB4> <EFBFBD> 1
2026-02-09 11:14:38 +08:00
//USART_ClearFlag(USART1, USART_FLAG_TC);
2026-02-09 17:29:30 +08:00
USART_ITConfig ( USART6 , USART_IT_RXNE , ENABLE ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
2026-02-09 11:14:38 +08:00
//Usart1 NVIC <20> <> <EFBFBD> <EFBFBD>
NVIC_InitStructure . NVIC_IRQChannel = USART6_IRQn ; //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> ж<EFBFBD> ͨ<EFBFBD> <CDA8>
NVIC_InitStructure . NVIC_IRQChannelPreemptionPriority = 3 ; //<2F> <> ռ <EFBFBD> <D5BC> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelSubPriority = 3 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> 3
NVIC_InitStructure . NVIC_IRQChannelCmd = ENABLE ; //IRQͨ<51> <CDA8> ʹ <EFBFBD> <CAB9>
NVIC_Init ( & NVIC_InitStructure ) ; //<2F> <> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> IJ<EFBFBD> <C4B2> <EFBFBD> <EFBFBD> <EFBFBD> ʼ <EFBFBD> <CABC> VIC<49> Ĵ<EFBFBD> <C4B4> <EFBFBD> <EFBFBD> <EFBFBD>
}
2026-02-10 15:06:39 +08:00
void USART6_IRQHandler ( void ) //<2F> <> <EFBFBD> <EFBFBD> 6<EFBFBD> жϷ<D0B6> <CFB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2026-02-09 11:14:38 +08:00
{
2026-02-09 17:29:30 +08:00
u8 uart1_data ;
if ( USART_GetITStatus ( USART6 , USART_IT_RXNE ) ! = RESET ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ж<EFBFBD>
{
USART_ClearITPendingBit ( USART6 , USART_IT_RXNE ) ;
uart1_data = USART_ReceiveData ( USART6 ) ; //<2F> <> ȡ<EFBFBD> <C8A1> <EFBFBD> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
g_rx6_buffer [ 0 ] = uart1_data ;
//USART_ClearITPendingBit(USART1, USART_IT_RXNE);
2026-02-25 11:13:03 +08:00
if ( g_usart2_rx_sta = = 0 & & g_rx6_buffer [ 0 ] = = 0xBC ) //<2F> <> <EFBFBD> Ƶ<EFBFBD> <C6B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> BC 01 00 00 XX 66 //<2F> ر<EFBFBD> 1<EFBFBD> <31> <EFBFBD> <EFBFBD>
//BC 01 00 FF XX 66 //<2F> <> <EFBFBD> <EFBFBD> 1<EFBFBD> <31> <EFBFBD> <EFBFBD>
2026-02-09 17:29:30 +08:00
{
g_usart6_rx_buf [ 0 ] = g_rx6_buffer [ 0 ] ;
2026-02-25 11:13:03 +08:00
g_usart6_rx_sta = 1 ;
}
2026-02-09 17:29:30 +08:00
else if ( g_usart6_rx_sta ! = 0 )
{
2026-02-25 11:13:03 +08:00
g_usart6_rx_buf [ g_usart6_rx_sta & 0 X3FFF ] = g_rx6_buffer [ 0 ] ;
g_usart6_rx_sta + + ;
if ( g_usart6_rx_sta > ( USART_REC_LEN - 1 ) )
{
g_usart6_rx_sta = 0 ;
g_usart6_rx_state = 1 ;
2026-02-09 17:29:30 +08:00
// memset(g_usart1_rx_buf, 0x0, 6);
// g_rx1_buffer[0] = 0x0;
2026-02-25 11:13:03 +08:00
}
}
2026-02-09 17:29:30 +08:00
}
else if ( USART_GetITStatus ( USART6 , USART_IT_TXE ) ! = RESET )
{
USART_ClearITPendingBit ( USART6 , USART_IT_TXE ) ;
}
2026-02-09 11:14:38 +08:00
}
2026-02-10 01:35:53 +08:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
void Uart1_Send_data ( u8 * databuf , u16 len )
{
u8 i = 0 ;
for ( i = 0 ; i < len ; i + + )
{
USART_SendData ( USART1 , * databuf ) ; //<2F> <> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> ֽ<EFBFBD> <D6BD> <EFBFBD> <EFBFBD> <EFBFBD>
while ( USART_GetFlagStatus ( USART1 , USART_FLAG_TXE ) = = RESET ) { } ; //
databuf + + ; //i++;
}
}
2026-02-08 17:48:22 +08:00
2026-02-11 09:44:25 +08:00
void Uart3_Send_data ( u8 * databuf , u16 len )
{
u8 i = 0 ;
for ( i = 0 ; i < len ; i + + )
{
USART_SendData ( USART3 , * databuf ) ; //<2F> <> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> ֽ<EFBFBD> <D6BD> <EFBFBD> <EFBFBD> <EFBFBD>
while ( USART_GetFlagStatus ( USART3 , USART_FLAG_TXE ) = = RESET ) { } ; //
databuf + + ; //i++;
}
}
2026-02-10 10:28:33 +08:00
void Uart4_Send_data ( u8 * databuf , u16 len )
{
u8 i = 0 ;
for ( i = 0 ; i < len ; i + + )
{
USART_SendData ( UART4 , * databuf ) ; //<2F> <> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> ֽ<EFBFBD> <D6BD> <EFBFBD> <EFBFBD> <EFBFBD>
while ( USART_GetFlagStatus ( UART4 , USART_FLAG_TXE ) = = RESET ) { } ; //
databuf + + ; //i++;
}
}
2026-02-11 09:44:25 +08:00
void Uart5_Send_data ( u8 * databuf , u16 len )
{
u8 i = 0 ;
for ( i = 0 ; i < len ; i + + )
{
USART_SendData ( UART5 , * databuf ) ; //<2F> <> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> ֽ<EFBFBD> <D6BD> <EFBFBD> <EFBFBD> <EFBFBD>
while ( USART_GetFlagStatus ( UART5 , USART_FLAG_TXE ) = = RESET ) { } ; //
databuf + + ; //i++;
}
}
2026-02-10 01:35:53 +08:00
void Uart6_Send_data ( u8 * databuf , u16 len )
{
u8 i = 0 ;
for ( i = 0 ; i < len ; i + + )
{
USART_SendData ( USART6 , * databuf ) ; //<2F> <> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> ֽ<EFBFBD> <D6BD> <EFBFBD> <EFBFBD> <EFBFBD>
while ( USART_GetFlagStatus ( USART6 , USART_FLAG_TXE ) = = RESET ) { } ; //
databuf + + ; //i++;
}
}
2026-02-08 17:48:22 +08:00