2017 lines
62 KiB
C
2017 lines
62 KiB
C
|
|
/*************************************
|
|||
|
|
time:
|
|||
|
|
auther:
|
|||
|
|
change:
|
|||
|
|
*************************************/
|
|||
|
|
|
|||
|
|
#include "usart.h"
|
|||
|
|
#include "system.h"
|
|||
|
|
|
|||
|
|
struct tagUSARTDATA g_udUsart3Data; //<2F><><EFBFBD><EFBFBD>2
|
|||
|
|
|
|||
|
|
typedef struct {
|
|||
|
|
uint8_t buffer[UART_RX_BUFFER_SIZE];
|
|||
|
|
volatile uint16_t head;
|
|||
|
|
volatile uint16_t tail;
|
|||
|
|
} RingBuffer;
|
|||
|
|
|
|||
|
|
static RingBuffer rx_buffer = {0};
|
|||
|
|
static uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
|
|||
|
|
static volatile bool is_transmitting = false;
|
|||
|
|
|
|||
|
|
void UART_Init(uint32_t baudrate) {
|
|||
|
|
|
|||
|
|
Init_485EN();
|
|||
|
|
// ʱ<><CAB1>ʹ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
|
|||
|
|
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN;
|
|||
|
|
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
|
|||
|
|
|
|||
|
|
// GPIO<49><4F><EFBFBD>ã<EFBFBD>PB6/PB7<42><37><EFBFBD>ù<EFBFBD><C3B9>ܣ<EFBFBD>
|
|||
|
|
GPIOB->MODER &= ~(GPIO_MODER_MODE6_0 | GPIO_MODER_MODE7_0);
|
|||
|
|
GPIOB->MODER |= (GPIO_MODER_MODE6_1 | GPIO_MODER_MODE7_1);
|
|||
|
|
GPIOB->AFR[0] |= (7 << GPIO_AFRL_AFSEL6_Pos) | (7 << GPIO_AFRL_AFSEL7_Pos);
|
|||
|
|
|
|||
|
|
// USART<52><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
USART1->BRR = SystemCoreClock / baudrate; // <20><EFBFBD><F2BBAFBC>㣬ʵ<E3A3AC><CAB5><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ȷ<EFBFBD>ķ<EFBFBD>Ƶ
|
|||
|
|
//USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE;
|
|||
|
|
//USART1->CR1 |= USART_CR1_UE;
|
|||
|
|
USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
|
|||
|
|
USART1->CR1 |= USART_CR1_RXNEIE; // ʹ<>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
// USART1->CR1 |= USART_CR1_RXNEIE; // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
|
USART1->CR3 |= USART_CR3_EIE; // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>ORE/FE/NE<4E>ȣ<EFBFBD>
|
|||
|
|
|
|||
|
|
// NVIC<49><43><EFBFBD><EFBFBD>
|
|||
|
|
NVIC_SetPriority(USART1_IRQn, 3);
|
|||
|
|
NVIC_EnableIRQ(USART1_IRQn);
|
|||
|
|
|
|||
|
|
RS485_RX_EN;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
//<2F><>ʼ<EFBFBD><CABC>485EN<45>˿<EFBFBD>PB8Ϊ<38><CEAA><EFBFBD><EFBFBD>
|
|||
|
|
void Init_485EN(void)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|||
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|||
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
|||
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; //<2F><><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
|
|||
|
|
void USART3_Init(uint32_t baudrate)
|
|||
|
|
{
|
|||
|
|
InitUart3_485EN();
|
|||
|
|
// 1. ʹ<><CAB9>ʱ<EFBFBD><CAB1>
|
|||
|
|
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOCEN; // ʹ<><CAB9>GPIOCʱ<43><CAB1>
|
|||
|
|
RCC->APB1ENR1 |= RCC_APB1ENR1_USART3EN; // ʹ<><CAB9>USART3ʱ<33><CAB1>
|
|||
|
|
|
|||
|
|
// 2. <20><><EFBFBD><EFBFBD>PC10(TX)<29><>PC11(RX)Ϊ<><CEAA><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>
|
|||
|
|
GPIOC->MODER &= ~(GPIO_MODER_MODE10_Msk | GPIO_MODER_MODE11_Msk);
|
|||
|
|
GPIOC->MODER |= (2 << GPIO_MODER_MODE10_Pos) | (2 << GPIO_MODER_MODE11_Pos); // PC10<31><30><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
// (2 << GPIO_MODER_MODE11_Pos); // PC11<31><31><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
|
|||
|
|
// 3. <20><><EFBFBD>ø<EFBFBD><C3B8>ù<EFBFBD><C3B9><EFBFBD>AF7<46><37>USART3<54><33>
|
|||
|
|
// GPIOC->AFR[1] |= (7 << (4*(10-8))) | // PC10: AF7 (USART3_TX)
|
|||
|
|
// (7 << (4*(11-8))); // PC11: AF7 (USART3_RX)
|
|||
|
|
GPIOC->AFR[1] |= (7 << GPIO_AFRH_AFSEL10_Pos) | (7 << GPIO_AFRH_AFSEL11_Pos);
|
|||
|
|
// 4. <20><><EFBFBD><EFBFBD>GPIO<49><4F><EFBFBD><EFBFBD>
|
|||
|
|
// GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_10 | GPIO_OTYPER_OT_11); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// GPIOC->OSPEEDR |= (3 << GPIO_OSPEEDR_OSPEED10_Pos) | // <20><><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
// (3 << GPIO_OSPEEDR_OSPEED11_Pos);
|
|||
|
|
// GPIOC->PUPDR |= (1 << GPIO_PUPDR_PUPD11_Pos); // RX<52><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
// 5. <20><><EFBFBD><EFBFBD>USART3<54><33><EFBFBD><EFBFBD>
|
|||
|
|
// USART3->BRR = (SystemCoreClock + baudrate/2) / baudrate; // <20><><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>
|
|||
|
|
USART3->BRR = SystemCoreClock/4/baudrate; // <20><><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>
|
|||
|
|
USART3->CR1 = USART_CR1_TE | USART_CR1_RE |USART_CR1_UE; // <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
|
// USART_CR1_RE | // <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
|
// USART_CR1_RXNEIE; // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
|
USART3->CR1 |= USART_CR1_RXNEIE; // ʹ<><CAB9>USART3
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD>ã<EFBFBD>ʹ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD>жϼ<D0B6><CFBC><EFBFBD>
|
|||
|
|
USART3->CR3 |= USART_CR3_EIE; // ʹ<>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
|
|||
|
|
// 6. <20><><EFBFBD><EFBFBD>NVIC<49>ж<EFBFBD>
|
|||
|
|
NVIC_SetPriority(USART3_IRQn, 2); // <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
|||
|
|
NVIC_EnableIRQ(USART3_IRQn); // ʹ<><CAB9><EFBFBD>ж<EFBFBD>
|
|||
|
|
|
|||
|
|
RS485_UART3RX_EN;
|
|||
|
|
g_udUsart3Data.usStatus = RcvSyn;
|
|||
|
|
// RS485_UART2TX_EN;
|
|||
|
|
// delay_ms(1);
|
|||
|
|
// RS485_UART2RX_EN;
|
|||
|
|
}
|
|||
|
|
//<2F><>ʼ<EFBFBD><CABC>485EN<45>˿<EFBFBD>PC12Ϊ<32><CEAA><EFBFBD><EFBFBD>
|
|||
|
|
void InitUart3_485EN(void)
|
|||
|
|
{
|
|||
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|||
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|||
|
|
GPIO_InitStruct.Pin = GPIO_PIN_12;
|
|||
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; //<2F><><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
UART_Status UART_SendByte(uint8_t data) {
|
|||
|
|
// if(is_transmitting) return UART_BUSY;
|
|||
|
|
RS485_TX_EN;
|
|||
|
|
delay_us(10);
|
|||
|
|
// Delayus(200);
|
|||
|
|
// USART1->TDR = data;
|
|||
|
|
//// is_transmitting = true;
|
|||
|
|
// USART1->CR1 |= USART_CR1_TCIE; // ʹ<>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
USART1->TDR = data;
|
|||
|
|
// while(!(USART1->ISR & USART_ISR_TXE));
|
|||
|
|
while(!(USART1->ISR & USART_ISR_TC)); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
RS485_RX_EN;
|
|||
|
|
// delay_us(100);
|
|||
|
|
// RS485_RX_EN;
|
|||
|
|
return UART_OK;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void UART_SendStr(uint8_t *PData,uint16_t Datalen)
|
|||
|
|
{
|
|||
|
|
RS485_TX_EN;
|
|||
|
|
delay_us(10);
|
|||
|
|
uint16_t i=0;
|
|||
|
|
for(;i< Datalen;i++)
|
|||
|
|
{
|
|||
|
|
while(!(USART1->ISR & USART_ISR_TXE));
|
|||
|
|
USART1->TDR = *(PData+i);
|
|||
|
|
//USART_SendData(USARTx, *(PData+i));
|
|||
|
|
//while (!USART_GetFlagStatus(USART1,USART_FLAG_TC));
|
|||
|
|
}
|
|||
|
|
while(!(USART1->ISR & USART_ISR_TC)); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
RS485_RX_EN;
|
|||
|
|
// while(*str) {
|
|||
|
|
// while(!(USART1->ISR & USART_ISR_TXE));
|
|||
|
|
// USART1->TDR = *str++;
|
|||
|
|
// }
|
|||
|
|
// return UART_OK;
|
|||
|
|
// delay_us(100);
|
|||
|
|
// RS485_RX_EN;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
UART_Status UART_SendString(const char *str) {
|
|||
|
|
|
|||
|
|
RS485_TX_EN;
|
|||
|
|
delay_us(10);
|
|||
|
|
while(*str) {
|
|||
|
|
while(!(USART1->ISR & USART_ISR_TXE));
|
|||
|
|
USART1->TDR = *str++;
|
|||
|
|
}
|
|||
|
|
// delay_us(100);
|
|||
|
|
// RS485_RX_EN;
|
|||
|
|
while(!(USART1->ISR & USART_ISR_TC)); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
RS485_RX_EN;
|
|||
|
|
return UART_OK;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
UART_Status UART3_SendByte(uint8_t data)
|
|||
|
|
{
|
|||
|
|
RS485_UART3TX_EN;
|
|||
|
|
delay_us(10);
|
|||
|
|
USART3->TDR = data;
|
|||
|
|
while(!(USART3->ISR & USART_ISR_TC)); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
RS485_UART3RX_EN;
|
|||
|
|
return UART_OK;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void UART3_SendStr(uint8_t *PData,uint16_t Datalen)
|
|||
|
|
{
|
|||
|
|
RS485_UART3TX_EN;
|
|||
|
|
delay_us(10);
|
|||
|
|
uint16_t i=0;
|
|||
|
|
for(;i< Datalen;i++)
|
|||
|
|
{
|
|||
|
|
while(!(USART3->ISR & USART_ISR_TXE));
|
|||
|
|
USART3->TDR = *(PData+i);
|
|||
|
|
}
|
|||
|
|
while(!(USART3->ISR & USART_ISR_TC)); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
RS485_UART3RX_EN;
|
|||
|
|
}
|
|||
|
|
//uint16_t UART_Available(void) {
|
|||
|
|
// return (rx_buffer.head - rx_buffer.tail) % UART_RX_BUFFER_SIZE;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//uint8_t UART_ReadByte(void) {
|
|||
|
|
// if(rx_buffer.head == rx_buffer.tail) return 0;
|
|||
|
|
//
|
|||
|
|
// uint8_t data = rx_buffer.buffer[rx_buffer.tail];
|
|||
|
|
// rx_buffer.tail = (rx_buffer.tail + 1) % UART_RX_BUFFER_SIZE;
|
|||
|
|
// return data;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void UART_FlushRxBuffer(void) {
|
|||
|
|
// rx_buffer.head = rx_buffer.tail = 0;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
// <20>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void USART1_IRQHandler(void) {
|
|||
|
|
uint32_t isr = USART1->ISR;
|
|||
|
|
|
|||
|
|
/*---------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> ----------*/
|
|||
|
|
if (isr & USART_ISR_RXNE) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռĴ<D5BC><C4B4><EFBFBD><EFBFBD>ǿձ<C7BF>־
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼĴ<DDBC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>RXNE<4E><45>־<EFBFBD><D6BE>
|
|||
|
|
uint8_t data = USART1->RDR;
|
|||
|
|
PushQueue(&RecQueue,data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*---------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־ ----------*/
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// uint32_t errors = 0;
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6>
|
|||
|
|
if (isr & USART_ISR_ORE) {
|
|||
|
|
USART1->ICR |= USART_ICR_ORECF; // д1<D0B4><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
|
// <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (isr & USART_ISR_FE) {
|
|||
|
|
USART1->ICR |= USART_ICR_FECF; // <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (isr & USART_ISR_NE) {
|
|||
|
|
USART1->ICR |= USART_ICR_NCF; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣨<EFBFBD><E2A3A8>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// #ifdef USART_ISR_PE
|
|||
|
|
// if (isr & USART_ISR_PE) {
|
|||
|
|
// USART1->ICR |= USART_ICR_PECF; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>żУ<C5BC><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
|
// }
|
|||
|
|
// #endif
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>жϴ<D0B6><CFB4><EFBFBD>
|
|||
|
|
// if(USART1->ISR & USART_ISR_RXNE) {
|
|||
|
|
// uint8_t data = USART1->RDR;
|
|||
|
|
// PushQueue(&RecQueue,data);
|
|||
|
|
//// uint16_t next_head = (rx_buffer.head + 1) % UART_RX_BUFFER_SIZE;
|
|||
|
|
//
|
|||
|
|
//// if(next_head != rx_buffer.tail) {
|
|||
|
|
//// rx_buffer.buffer[rx_buffer.head] = data;
|
|||
|
|
//// rx_buffer.head = next_head;
|
|||
|
|
//// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϴ<D0B6><CFB4><EFBFBD>
|
|||
|
|
// if(USART1->ISR & USART_ISR_TC) {
|
|||
|
|
// USART1->ICR |= USART_ICR_TCCF; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
|
|||
|
|
// USART1->CR1 &= ~USART_CR1_TCIE; // <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
//// is_transmitting = false;
|
|||
|
|
// RS485_RX_EN;
|
|||
|
|
// }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>棩
|
|||
|
|
void USART3_IRQHandler(void)
|
|||
|
|
{
|
|||
|
|
uint32_t isr = USART3->ISR; // <20><>ȡ<EFBFBD>ж<EFBFBD>״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
|
|||
|
|
/*---------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD>ж<EFBFBD> ----------*/
|
|||
|
|
if (isr & USART_ISR_RXNE) { // <20><><EFBFBD>ռĴ<D5BC><C4B4><EFBFBD><EFBFBD>ǿ<EFBFBD>
|
|||
|
|
uint8_t data = USART3->RDR; // <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݣ<EFBFBD><DDA3>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>RXNE<4E><45>־
|
|||
|
|
Uart3Rcv(data);
|
|||
|
|
// <20>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Overrun Error<6F><72>
|
|||
|
|
if (isr & USART_ISR_ORE) {
|
|||
|
|
// usart3_errors.overrun_errors++;
|
|||
|
|
USART3->ICR |= USART_ICR_ORECF; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 2. ֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Framing Error<6F><72>
|
|||
|
|
if (isr & USART_ISR_FE) {
|
|||
|
|
// usart3_errors.framing_errors++;
|
|||
|
|
USART3->ICR |= USART_ICR_FECF; // <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 3. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Noise Error<6F><72>
|
|||
|
|
if (isr & USART_ISR_NE) {
|
|||
|
|
// usart3_errors.noise_errors++;
|
|||
|
|
USART3->ICR |= USART_ICR_NCF; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// // 4. <20><>żУ<C5BC><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Parity Error<6F><72>
|
|||
|
|
// if (isr & USART_ISR_PE) {
|
|||
|
|
// usart3_errors.parity_errors++;
|
|||
|
|
// USART3->ICR |= USART_ICR_PECF; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>żУ<C5BC><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// /*---------------- <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>ճ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> ----------------*/
|
|||
|
|
// #ifdef USART_CR1_RTOIE
|
|||
|
|
// if (isr & USART_ISR_RTOF) { // <20><><EFBFBD>ճ<EFBFBD>ʱ<EFBFBD><CAB1>־
|
|||
|
|
// USART3->ICR |= USART_ICR_RTOCF; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>־
|
|||
|
|
// // <20>˴<EFBFBD><CBB4>ɴ<EFBFBD><C9B4><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// }
|
|||
|
|
// #endif
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD> 22.1.25
|
|||
|
|
void Uart3Rcv(unsigned char ucReadData)
|
|||
|
|
{
|
|||
|
|
switch(g_udUsart3Data.usStatus)
|
|||
|
|
{
|
|||
|
|
case RcvSyn:
|
|||
|
|
{
|
|||
|
|
if( ucReadData == COMM_FRAME_HEAD)//<2F>ж<EFBFBD><D0B6><EFBFBD>ʼλ<CABC>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.usStatus = RcvtargetAddress;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc += ucReadData;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc = 0;
|
|||
|
|
g_udUsart3Data.usStatus = RcvSyn;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
case RcvtargetAddress://Ŀ<>ĵ<EFBFBD>ַ
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.ucRcvtargetAddress = ucReadData;
|
|||
|
|
if(g_udUsart3Data.ucRcvtargetAddress == COMPARE55)
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.usStatus = RcvsourceAddress;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc += ucReadData;
|
|||
|
|
}
|
|||
|
|
else if(ucReadData == COMM_FRAME_HEAD)
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc = 0;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc += ucReadData;
|
|||
|
|
g_udUsart3Data.usStatus = RcvtargetAddress;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.usStatus = RcvSyn;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc = 0;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
case RcvsourceAddress://<2F><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>ַ
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.ucRcvsourceAddress = ucReadData;
|
|||
|
|
if(ucReadData == FREUENCYDATA) //<2F><><EFBFBD><EFBFBD>˫<EFBFBD><CBAB>ַģ<D6B7><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc += ucReadData;
|
|||
|
|
}
|
|||
|
|
else if((ucReadData == THORGHFARE0)||(ucReadData == THORGHFARE1))
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.usStatus = RcvaData;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc += ucReadData;
|
|||
|
|
g_udUsart3Data.ucDataCount = 0;
|
|||
|
|
}
|
|||
|
|
else if(ucReadData == COMM_FRAME_HEAD)
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc = 0;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc += ucReadData;
|
|||
|
|
g_udUsart3Data.usStatus = RcvtargetAddress;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.usStatus = RcvSyn;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc = 0;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
case RcvaData://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.aData[g_udUsart3Data.ucDataCount] = ucReadData;
|
|||
|
|
g_udUsart3Data.ucDataCount ++;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc += ucReadData;
|
|||
|
|
|
|||
|
|
if( g_udUsart3Data.ucDataCount >= DIELECTRICLEGTH)
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.usStatus = ChkSum;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
case ChkSum://CRCУ<43><D0A3>
|
|||
|
|
{
|
|||
|
|
if(ucReadData != g_udUsart3Data.ucReceiveChkCrc)
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.ucCommand = 0xFF;
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc = 0;
|
|||
|
|
g_udUsart3Data.usStatus = RcvSyn;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.usStatus = CmdOperate;
|
|||
|
|
g_udUsart3Data.ucCommand = 0x00;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
default:
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/****************************
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 22.1.25
|
|||
|
|
****************************/
|
|||
|
|
void Uart3data_Processing(void)
|
|||
|
|
{
|
|||
|
|
unsigned int i;//,RX_SPEED,Setfdata=0;
|
|||
|
|
//unsigned char chack_data_sum;
|
|||
|
|
if(g_udUsart3Data.usStatus == CmdOperate)//<2F><><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
if( g_udUsart3Data.ucCommand == 0xFF )
|
|||
|
|
{
|
|||
|
|
g_udUsart3Data.ucCommand = 0x00;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
switch(g_udUsart3Data.ucRcvsourceAddress)
|
|||
|
|
{
|
|||
|
|
case THORGHFARE0: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>ڣ<EFBFBD>
|
|||
|
|
for(i=0;i<DIELECTRICLEGTH;i++)
|
|||
|
|
{
|
|||
|
|
MeasurementData_Farbit.ucDataValueBuf[i+75] = s_Data.ReceiveBuf[i];
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case THORGHFARE1: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>⣩
|
|||
|
|
for(i=0;i<DIELECTRICLEGTH;i++)
|
|||
|
|
{
|
|||
|
|
MeasurementData_Farbit.ucDataValueBuf[i+83] = s_Data.ReceiveBuf[i];
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
g_udUsart3Data.ucReceiveChkCrc = 0;
|
|||
|
|
//ParallelUart_RevFlag = 0; //<2F><><EFBFBD>ڽ<EFBFBD><DABD>ճɹ<D5B3> 2022.1.25
|
|||
|
|
g_udUsart3Data.usStatus = RcvSyn;
|
|||
|
|
g_Data.GetUart3OverFlag = 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//extern QueueHandle_t Uart_Queue_Handle;
|
|||
|
|
//volatile uint8_t rx_len = 0; //<2F><><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD>ݵij<DDB5><C4B3><EFBFBD>
|
|||
|
|
//volatile uint8_t recv_end_flag = 0; //һ֡<D2BB><D6A1><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
|
|||
|
|
//uint8_t rx_buffer[100]={0}; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
////usart3 <20><>Ϊ<EFBFBD><CEAA><EFBFBD>Կڣ<D4BF><DAA3><EFBFBD><EFBFBD><EFBFBD>print <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
|
|||
|
|
//#pragma import(__use_no_semihosting)
|
|||
|
|
////<2F><><EFBFBD><D7BC><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>֧<EFBFBD>ֺ<EFBFBD><D6BA><EFBFBD>
|
|||
|
|
//struct __FILE
|
|||
|
|
//{
|
|||
|
|
// int handle;
|
|||
|
|
//};
|
|||
|
|
|
|||
|
|
//FILE __stdout;
|
|||
|
|
///**
|
|||
|
|
// * @brief <09><><EFBFBD><EFBFBD>_sys_exit()<29>Ա<EFBFBD><D4B1><EFBFBD>ʹ<EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
// *
|
|||
|
|
// * @param void
|
|||
|
|
// *
|
|||
|
|
// * @return void
|
|||
|
|
// */
|
|||
|
|
//void _sys_exit(int x)
|
|||
|
|
//{
|
|||
|
|
// x = x;
|
|||
|
|
//}
|
|||
|
|
///**
|
|||
|
|
// * @brief <09>ض<EFBFBD><D8B6><EFBFBD>fputc<74><63><EFBFBD><EFBFBD>
|
|||
|
|
// *
|
|||
|
|
// * @param ch <09><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
// * @param f <09>ļ<EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
|
// *
|
|||
|
|
// * @return void
|
|||
|
|
// */
|
|||
|
|
//int fputc(int ch, FILE *f)
|
|||
|
|
//{
|
|||
|
|
//#ifndef BNGF
|
|||
|
|
// while((USART1->ISR & 0X40) == 0); //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// USART1->TDR = (u8) ch;
|
|||
|
|
// return ch;
|
|||
|
|
//#endif
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void debug_printf(char *information,int len)
|
|||
|
|
//{
|
|||
|
|
// TX1_UART();TX1_UART();
|
|||
|
|
// printf("\r\n");
|
|||
|
|
// printf(information,len);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
////ע<><D7A2>,<2C><>ȡUSARTx->SR<53>ܱ<EFBFBD><DCB1><EFBFBD>Ī<EFBFBD><C4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
//u8 USART_RX_BUF[USART3_RX_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 USART3_RX_STA = 0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
|||
|
|
///**
|
|||
|
|
// * @brief <09><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD> <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// *
|
|||
|
|
// * @param bound <09><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// *
|
|||
|
|
// * @return void
|
|||
|
|
// */
|
|||
|
|
////void uart3_init(u32 bound)
|
|||
|
|
////{
|
|||
|
|
//// //UART <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// huart3.Instance = USART3; //USART1
|
|||
|
|
//// huart3.Init.BaudRate = bound; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// huart3.Init.WordLength = UART_WORDLENGTH_8B; //<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
|
|||
|
|
//// huart3.Init.StopBits = UART_STOPBITS_1; //һ<><D2BB>ֹͣλ
|
|||
|
|
//// huart3.Init.Parity = UART_PARITY_NONE; //<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
|
|||
|
|
//// huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; //<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// huart3.Init.Mode = UART_MODE_TX_RX; //<2F>շ<EFBFBD>ģʽ
|
|||
|
|
//// HAL_UART_Init(&huart3); //HAL_UART_Init()<29><>ʹ<EFBFBD><CAB9>UART1
|
|||
|
|
|
|||
|
|
//// __HAL_UART_CLEAR_IDLEFLAG(&huart3);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
|||
|
|
//// __HAL_UART_CLEAR_FLAG(&huart3,UART_IT_IDLE|UART_FLAG_NE|UART_FLAG_FE|UART_FLAG_TXE|UART_FLAG_TC);
|
|||
|
|
////
|
|||
|
|
//// HAL_NVIC_EnableIRQ(USART3_IRQn); //ʹ<><CAB9>USART1<54>ж<EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
|
//// HAL_NVIC_SetPriority(USART3_IRQn, 3, 0); //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
|
|||
|
|
//// HAL_UART_Receive_IT(&huart3, &usart1_buf.aRxBuff, 1);
|
|||
|
|
//// __HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);
|
|||
|
|
//// __HAL_UART_CLEAR_IDLEFLAG(&huart3);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
|||
|
|
//// RX3_UART();
|
|||
|
|
////}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
///* USART1 init function */
|
|||
|
|
|
|||
|
|
//void MX_USART1_UART_Init(uint32_t bound)
|
|||
|
|
//{
|
|||
|
|
|
|||
|
|
// huart1.Instance = USART1;
|
|||
|
|
// huart1.Init.BaudRate = bound;
|
|||
|
|
// huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|||
|
|
// huart1.Init.StopBits = UART_STOPBITS_1;
|
|||
|
|
// huart1.Init.Parity = UART_PARITY_NONE;
|
|||
|
|
// huart1.Init.Mode = UART_MODE_TX_RX;
|
|||
|
|
// huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|||
|
|
// //huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|||
|
|
// if (HAL_UART_Init(&huart1) != HAL_OK)
|
|||
|
|
// {
|
|||
|
|
// Error_Handler(1);
|
|||
|
|
// }
|
|||
|
|
// TX1_UART();
|
|||
|
|
//// __HAL_UART_CLEAR_IDLEFLAG(&huart1);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
|||
|
|
//// __HAL_UART_CLEAR_FLAG(&huart1,UART_IT_IDLE|UART_FLAG_NE|UART_FLAG_FE|UART_FLAG_TXE|UART_FLAG_TC);
|
|||
|
|
////
|
|||
|
|
//// HAL_NVIC_EnableIRQ(USART1_IRQn); //ʹ<><CAB9>USART1<54>ж<EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
|
//// HAL_NVIC_SetPriority(USART1_IRQn, 3, 0); //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
|
|||
|
|
//// HAL_UART_Receive_IT(&huart1, &usart1_buf.aRxBuff, 1);
|
|||
|
|
//
|
|||
|
|
////DMA<4D><41><EFBFBD>պ<EFBFBD><D5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾<EFBFBD>һ<EFBFBD><D2BB>Ҫ<EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>ݣ<EFBFBD><DDA3>ǿյģ<D5B5><C4A3>Ҵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
|
//// HAL_UART_Receive_DMA(&huart1,rx_buffer,USART_REC_LEN);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void MX_DMA_Init(void)
|
|||
|
|
//{
|
|||
|
|
//
|
|||
|
|
// /* DMA controller clock enable */
|
|||
|
|
// __HAL_RCC_DMA1_CLK_ENABLE();
|
|||
|
|
|
|||
|
|
// /* DMA1_Channel6_IRQn interrupt configuration */
|
|||
|
|
// HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 1, 0);
|
|||
|
|
// HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
|
|||
|
|
// /* DMA2_Channel7_IRQn interrupt configuration */
|
|||
|
|
//// HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 2, 0);
|
|||
|
|
//// HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn);
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
//}
|
|||
|
|
//void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
|||
|
|
//{
|
|||
|
|
// GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|||
|
|
// RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
|||
|
|
// if(uartHandle->Instance==USART1)
|
|||
|
|
// {
|
|||
|
|
//// PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
|
|||
|
|
//// PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
|
|||
|
|
//// if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|||
|
|
//// {
|
|||
|
|
//// Error_Handler(1);
|
|||
|
|
//// printf("[%s] %d err\r\n",__func__,__LINE__);
|
|||
|
|
//// }
|
|||
|
|
// // USART1 clock enable <20><><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>Ӧʱ<D3A6><CAB1>
|
|||
|
|
// __HAL_RCC_USART1_CLK_ENABLE();
|
|||
|
|
// __HAL_RCC_GPIOB_CLK_ENABLE();
|
|||
|
|
|
|||
|
|
// __HAL_RCC_GPIOD_CLK_ENABLE();
|
|||
|
|
// #ifdef BAD_DEBUG
|
|||
|
|
// __HAL_RCC_GPIOA_CLK_ENABLE();
|
|||
|
|
// #endif
|
|||
|
|
// #ifdef Board_VerE
|
|||
|
|
// __HAL_RCC_GPIOA_CLK_ENABLE();
|
|||
|
|
// #endif
|
|||
|
|
// GPIO_InitStruct.Pin = UART_RD1_PIN ;
|
|||
|
|
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|||
|
|
// GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP;
|
|||
|
|
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
|||
|
|
// HAL_GPIO_Init(UART_RD1_PORT, &GPIO_InitStruct);
|
|||
|
|
//
|
|||
|
|
//
|
|||
|
|
// GPIO_InitStruct.Pin = UART1_RX_PIN|UART1_TX_PIN;
|
|||
|
|
// GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|||
|
|
// GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP;//
|
|||
|
|
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
|||
|
|
// GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
|||
|
|
// HAL_GPIO_Init(UART1_PORT, &GPIO_InitStruct);
|
|||
|
|
// TX1_UART();
|
|||
|
|
//
|
|||
|
|
// // USART1 DMA Init
|
|||
|
|
// // USART1_RX Init
|
|||
|
|
// #ifndef debug_board
|
|||
|
|
// /*
|
|||
|
|
// hdma_usart1_rx.Instance = DMA1_Channel5;
|
|||
|
|
// hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
|||
|
|
// hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
|||
|
|
// hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
|
|||
|
|
// hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
|||
|
|
// hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
|||
|
|
// hdma_usart1_rx.Init.Mode = DMA_NORMAL;
|
|||
|
|
// hdma_usart1_rx.Init.Priority = DMA_PRIORITY_HIGH;
|
|||
|
|
// if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)
|
|||
|
|
// {
|
|||
|
|
// Error_Handler(1);
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart1_rx);
|
|||
|
|
// */
|
|||
|
|
///*
|
|||
|
|
// // USART1_TX Init
|
|||
|
|
// hdma_usart1_tx.Instance = DMA1_Channel4;
|
|||
|
|
// hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
|||
|
|
// hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
|||
|
|
// hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;
|
|||
|
|
// hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
|||
|
|
// hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
|||
|
|
// hdma_usart1_tx.Init.Mode = DMA_NORMAL;
|
|||
|
|
// hdma_usart1_tx.Init.Priority = DMA_PRIORITY_HIGH;
|
|||
|
|
// if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)
|
|||
|
|
// {
|
|||
|
|
// Error_Handler(1);
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx);
|
|||
|
|
|
|||
|
|
//*/
|
|||
|
|
// #endif
|
|||
|
|
//
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
//// else if(uartHandle->Instance == USART3) //<2F><><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>1 MSP<53><50>ʼ<EFBFBD><CABC>
|
|||
|
|
//// {
|
|||
|
|
//// __HAL_RCC_GPIOA_CLK_ENABLE(); //ʹ<><CAB9>GPIOAʱ<41><CAB1>
|
|||
|
|
//// __HAL_RCC_GPIOC_CLK_ENABLE();
|
|||
|
|
//// __HAL_RCC_USART3_CLK_ENABLE(); //ʹ<><CAB9>USART3ʱ<33><CAB1>
|
|||
|
|
|
|||
|
|
//// GPIO_InitStruct.Pin = UART3_RD_PIN ;
|
|||
|
|
//// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|||
|
|
//// GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP;
|
|||
|
|
//// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|||
|
|
//// HAL_GPIO_Init(UART3_RD_PORT, &GPIO_InitStruct);
|
|||
|
|
////
|
|||
|
|
//// GPIO_InitStruct.Pin = UART3_RX_PIN|UART3_TX_PIN;
|
|||
|
|
//// GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
//// GPIO_InitStruct.Speed = GPIO_SPEED_FAST; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
//// GPIO_InitStruct.Alternate = GPIO_AF7_USART3; //<2F><><EFBFBD><EFBFBD>ΪUSART2
|
|||
|
|
//// HAL_GPIO_Init(UART3_PORT, &GPIO_InitStruct);
|
|||
|
|
////
|
|||
|
|
//// //HAL_NVIC_DisableIRQ(USART3_IRQn);
|
|||
|
|
//// //TX3_UART();
|
|||
|
|
//// }
|
|||
|
|
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
|||
|
|
//{
|
|||
|
|
|
|||
|
|
//// if(uartHandle->Instance==USART1)
|
|||
|
|
//// {
|
|||
|
|
// // Peripheral clock disable
|
|||
|
|
// __HAL_RCC_USART1_CLK_DISABLE();
|
|||
|
|
// //PA9 ------> USART1_TX
|
|||
|
|
// //PA10 ------> USART1_RX
|
|||
|
|
// HAL_GPIO_DeInit(UART1_PORT, UART1_RX_PIN|UART1_RX_PIN);
|
|||
|
|
// // USART1 DMA DeInit
|
|||
|
|
// // HAL_DMA_DeInit(uartHandle->hdmarx);
|
|||
|
|
// //HAL_DMA_DeInit(uartHandle->hdmatx);
|
|||
|
|
|
|||
|
|
// HAL_NVIC_DisableIRQ(USART1_IRQn);
|
|||
|
|
|
|||
|
|
//// }
|
|||
|
|
//// else if(uartHandle->Instance==USART3)
|
|||
|
|
//// {
|
|||
|
|
//// // Peripheral clock disable
|
|||
|
|
//// __HAL_RCC_USART3_CLK_DISABLE();
|
|||
|
|
//// //PA9 ------> USART1_TX
|
|||
|
|
//// //PA10 ------> USART1_RX
|
|||
|
|
//// HAL_GPIO_DeInit(UART3_PORT, UART3_RX_PIN|UART3_RX_PIN);
|
|||
|
|
|
|||
|
|
//// HAL_NVIC_DisableIRQ(USART3_IRQn);
|
|||
|
|
|
|||
|
|
//// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//void HAL_UART_IDLECallback(UART_HandleTypeDef *huart)
|
|||
|
|
//{
|
|||
|
|
// //BaseType_t xHigherPriorityTaskWoken=1;
|
|||
|
|
// u8 Res;
|
|||
|
|
|
|||
|
|
|
|||
|
|
// if(huart->Instance == USART3)
|
|||
|
|
// {
|
|||
|
|
// Res = (uint8_t)(huart->Instance->RDR) ;
|
|||
|
|
// usart1_buf.RxBuff[usart1_buf.RxSize++] = Res;
|
|||
|
|
// if(usart1_buf.RxBuff[0]!=0xab)
|
|||
|
|
// usart1_buf.RxSize=0;
|
|||
|
|
// if(usart1_buf.RxSize>50)
|
|||
|
|
// usart1_buf.RxSize=50;
|
|||
|
|
// HAL_UART_Receive_IT(huart, &usart1_buf.aRxBuff, 1);
|
|||
|
|
// if(__HAL_UART_GET_FLAG(huart,UART_FLAG_IDLE) != RESET)
|
|||
|
|
// {
|
|||
|
|
// __HAL_UART_CLEAR_IDLEFLAG(huart);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
|||
|
|
//
|
|||
|
|
// if(usart1_buf.RxBuff[0]==0Xab && usart1_buf.RxSize>4)
|
|||
|
|
// {
|
|||
|
|
// __HAL_UART_DISABLE_IT(huart, UART_IT_IDLE);//__HAL_UART_DISABLE_IT(&huart1, UART_IT_IDLE); //<2F>ر<EFBFBD>idle<6C>ж<EFBFBD>
|
|||
|
|
// //xQueueSendFromISR(Uart_Queue_Handle,usart1_buf.RxBuff ,&xHigherPriorityTaskWoken);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// //portYIELD_FROM_ISR(xHigherPriorityTaskWoken);//<2F><><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// if(__HAL_UART_GET_FLAG(huart,UART_FLAG_ORE) != RESET)
|
|||
|
|
// {
|
|||
|
|
// __HAL_UART_CLEAR_OREFLAG(huart);
|
|||
|
|
// }
|
|||
|
|
// if(__HAL_UART_GET_FLAG(huart,UART_FLAG_ORE) != RESET)
|
|||
|
|
// {
|
|||
|
|
//
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
|||
|
|
//{
|
|||
|
|
// if(huart->Instance == USART3)
|
|||
|
|
// {
|
|||
|
|
// if(usart1_buf.Tx_end_flag == 0)
|
|||
|
|
// {
|
|||
|
|
// //debug_printf("\r\n\r\n<><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d\r\n",usart1_buf.TxSize);
|
|||
|
|
// //usart1_buf.TxSize = 0;
|
|||
|
|
// usart1_buf.Tx_end_flag = 1;
|
|||
|
|
// //memset(usart1_buf.TxBuff,0,usart1_buf.TxSize);
|
|||
|
|
// //RX3_UART();
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
////void USART3_IRQHandler(void)
|
|||
|
|
////{
|
|||
|
|
|
|||
|
|
//// HAL_UART_IDLECallback(&huart3);
|
|||
|
|
//// HAL_UART_IRQHandler(&huart3);
|
|||
|
|
////// if(huart3.Instance != USART3)
|
|||
|
|
////// {
|
|||
|
|
////// uart3_init(57600);//MX_USART3_UART_Init(57600);
|
|||
|
|
////// }
|
|||
|
|
//// HAL_UART_ErrorCallback(&huart3);
|
|||
|
|
////
|
|||
|
|
////}
|
|||
|
|
///**
|
|||
|
|
// * @brief <09><><EFBFBD><EFBFBD>3<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// *
|
|||
|
|
// * @remark <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>Ӱ<EFBFBD><D3B0>жϿ<D0B6><CFBF><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>
|
|||
|
|
// * ˵<><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HAL<41><EFBFBD><E2B4A6><EFBFBD><EFBFBD><DFBC><EFBFBD>Ч<EFBFBD>ʲ<EFBFBD><CAB2>ߡ<EFBFBD>
|
|||
|
|
// *
|
|||
|
|
// * @param void
|
|||
|
|
// *
|
|||
|
|
// * @return void
|
|||
|
|
// */
|
|||
|
|
//void USART1_IRQHandler(void)
|
|||
|
|
//{
|
|||
|
|
//// u8 Res;
|
|||
|
|
///*
|
|||
|
|
// //HAL_UART_Receive(&huart3, &Res, 1, 1000);
|
|||
|
|
// //HAL_UART_Receive_IT(&huart3, &usart1_buf.aRxBuff, 1);
|
|||
|
|
// if((__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET)) //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>(<28><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>0x0d 0x0a<30><61>β)
|
|||
|
|
// {
|
|||
|
|
// HAL_UART_Receive(&huart1, &Res, 1, 1000);
|
|||
|
|
// HAL_UART_Receive_IT(&huart1, &usart1_buf.aRxBuff, 1);
|
|||
|
|
// if((USART3_RX_STA & 0x8000) == 0) //<2F><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
|
|||
|
|
// {
|
|||
|
|
// if(USART3_RX_STA & 0x4000) //<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>0x0d
|
|||
|
|
// {
|
|||
|
|
// if(Res != 0x0a)USART3_RX_STA = 0; //<2F><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>,<2C><><EFBFBD>¿<EFBFBD>ʼ
|
|||
|
|
|
|||
|
|
// else USART3_RX_STA |= 0x8000; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// }
|
|||
|
|
// else //<2F><>û<EFBFBD>յ<EFBFBD>0X0D
|
|||
|
|
// {
|
|||
|
|
// if(Res == 0x0d)
|
|||
|
|
// USART3_RX_STA |= 0x4000;
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// USART_RX_BUF[USART3_RX_STA & 0X3FFF] = Res ;
|
|||
|
|
// USART3_RX_STA++;
|
|||
|
|
|
|||
|
|
// if(USART3_RX_STA > (USART3_RX_LEN - 1))
|
|||
|
|
// USART3_RX_STA = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>,<2C><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// */
|
|||
|
|
// HAL_UART_IRQHandler(&huart1);
|
|||
|
|
//}
|
|||
|
|
//void Error_Handler(uint8_t flag)
|
|||
|
|
//{
|
|||
|
|
// printf("error \r\n");
|
|||
|
|
//}
|
|||
|
|
//void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
|||
|
|
//{
|
|||
|
|
// if(HAL_UART_GetError(huart) & HAL_UART_ERROR_PE){ /*!< Parity error */
|
|||
|
|
// //<2F><>żУ<C5BC><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// __HAL_UART_CLEAR_PEFLAG(huart);
|
|||
|
|
// }else if(HAL_UART_GetError(huart) & HAL_UART_ERROR_NE){ /*!< Noise error */
|
|||
|
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// __HAL_UART_CLEAR_NEFLAG(huart);
|
|||
|
|
// }else if(HAL_UART_GetError(huart) & HAL_UART_ERROR_FE){ /*!< Frame error */
|
|||
|
|
// //֡<><D6A1>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
|
|||
|
|
// __HAL_UART_CLEAR_FEFLAG(huart);
|
|||
|
|
// }else if(HAL_UART_GetError(huart) & HAL_UART_ERROR_ORE){ /*!< Overrun error */
|
|||
|
|
// //<2F><><EFBFBD><EFBFBD>̫<EFBFBD>മ<EFBFBD><E0B4AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>
|
|||
|
|
// __HAL_UART_CLEAR_OREFLAG(huart);
|
|||
|
|
// }
|
|||
|
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
// if(huart ->Instance == USART1){
|
|||
|
|
// HAL_UART_Receive_IT(&huart1, &usart1_buf.aRxBuff, 1);
|
|||
|
|
// }
|
|||
|
|
//// if(huart ->Instance == USART3){
|
|||
|
|
//// HAL_UART_Receive_IT(&huart3, &usart1_buf.aRxBuff, 1);
|
|||
|
|
//// }
|
|||
|
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>......
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
////#include "./SYSTEM/sys/sys.h"
|
|||
|
|
////#include "./SYSTEM/usart/usart.h"
|
|||
|
|
|
|||
|
|
//const char AT_STR[] = "AT"; // 0x4154
|
|||
|
|
//const uint16_t CR_STR = 0x0A0D;//"\r\n"; <20>෴<EFBFBD><E0B7B4><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>ǰ
|
|||
|
|
|
|||
|
|
//uint8_t Uart1_RX_Buffer[USART_MAX_LEN]; //<2F><><EFBFBD>ý<EFBFBD><C3BD>ջ<EFBFBD><D5BB>漰<EFBFBD><E6BCB0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
|||
|
|
//uint8_t Uart1_TX_Buffer[USART_MAX_LEN];
|
|||
|
|
//UartBuff_TypeDef AtCmdUart;
|
|||
|
|
//void BSP_AddBuff(UartBuff_TypeDef *hAtUart);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
///* <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>os,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
//#if SYS_SUPPORT_OS
|
|||
|
|
//#include "os.h" /* os ʹ<><CAB9> */
|
|||
|
|
//#endif
|
|||
|
|
////UART_HandleTypeDef huart1;
|
|||
|
|
///******************************************************************************************/
|
|||
|
|
///* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD>, ֧<><D6A7>printf<74><66><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫѡ<D2AA><D1A1>use MicroLIB */
|
|||
|
|
|
|||
|
|
//#if 1
|
|||
|
|
//#if (__ARMCC_VERSION >= 6010050) /* ʹ<><CAB9>AC6<43><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ */
|
|||
|
|
//__asm(".global __use_no_semihosting\n\t"); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD>ģʽ */
|
|||
|
|
//__asm(".global __ARM_use_no_argv \n\t"); /* AC6<43><36><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>main<69><6E><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><DEB2><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2B2BFB7><EFBFBD><EFBFBD>̿<EFBFBD><CCBF>ܳ<EFBFBD><DCB3>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD>ģʽ */
|
|||
|
|
|
|||
|
|
//#else
|
|||
|
|
///* ʹ<><CAB9>AC5<43><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ, Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD>ﶨ<EFBFBD><EFB6A8>__FILE <20><> <20><>ʹ<EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD>ģʽ */
|
|||
|
|
//#pragma import(__use_no_semihosting)
|
|||
|
|
|
|||
|
|
//struct __FILE
|
|||
|
|
//{
|
|||
|
|
// int handle;
|
|||
|
|
// /* Whatever you require here. If the only file you are using is */
|
|||
|
|
// /* standard output using printf() for debugging, no file handling */
|
|||
|
|
// /* is required. */
|
|||
|
|
//};
|
|||
|
|
|
|||
|
|
//#endif
|
|||
|
|
|
|||
|
|
///* <20><>ʹ<EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ض<EFBFBD><D8B6><EFBFBD>_ttywrch\_sys_exit\_sys_command_string<6E><67><EFBFBD><EFBFBD>,<2C><>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>AC6<43><36>AC5ģʽ */
|
|||
|
|
//int _ttywrch(int ch)
|
|||
|
|
//{
|
|||
|
|
// ch = ch;
|
|||
|
|
// return ch;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
///* <20><><EFBFBD><EFBFBD>_sys_exit()<29>Ա<EFBFBD><D4B1><EFBFBD>ʹ<EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD>ģʽ */
|
|||
|
|
//void _sys_exit(int x)
|
|||
|
|
//{
|
|||
|
|
// x = x;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//char *_sys_command_string(char *cmd, int len)
|
|||
|
|
//{
|
|||
|
|
// return NULL;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
///* FILE <20><> stdio.h<><68><EFBFBD>涨<EFBFBD><E6B6A8>. */
|
|||
|
|
//FILE __stdout;
|
|||
|
|
|
|||
|
|
///* <20>ض<EFBFBD><D8B6><EFBFBD>fputc<74><63><EFBFBD><EFBFBD>, printf<74><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>fputc<74><63><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
//int fputc(int ch, FILE *f)
|
|||
|
|
//{
|
|||
|
|
// while ((USART1->ISR & 0X40) == 0); /* <20>ȴ<EFBFBD><C8B4><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
|
|||
|
|
// USART1->TDR = (uint8_t)ch; /* <20><>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD> ch д<>뵽DR<44>Ĵ<EFBFBD><C4B4><EFBFBD> */
|
|||
|
|
// return ch;
|
|||
|
|
//}
|
|||
|
|
//#endif
|
|||
|
|
/***********************************************END*******************************************/
|
|||
|
|
|
|||
|
|
//#if USART_EN_RX
|
|||
|
|
// /* <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>˽<EFBFBD><CBBD><EFBFBD> */
|
|||
|
|
|
|||
|
|
///* <20><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>, <20><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>. */
|
|||
|
|
//uint8_t g_usart_rx_buf[USART_REC_LEN];
|
|||
|
|
|
|||
|
|
///* <20><><EFBFBD><EFBFBD>״̬
|
|||
|
|
// * bit15<31><35> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
|
|||
|
|
// * bit14<31><34> <20><><EFBFBD>յ<EFBFBD>0x0d
|
|||
|
|
// * bit13~0<><30> <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ŀ
|
|||
|
|
//*/
|
|||
|
|
//uint16_t g_usart_rx_sta = 0;
|
|||
|
|
|
|||
|
|
//uint8_t g_rx_buffer[RXBUFFERSIZE]; /* HAL<41><4C>ʹ<EFBFBD>õĴ<C3B5><C4B4>ڽ<EFBFBD><DABD>ջ<EFBFBD><D5BB><EFBFBD> */
|
|||
|
|
|
|||
|
|
//UART_HandleTypeDef g_uart1_handle; /* UART<52><54><EFBFBD><EFBFBD> */
|
|||
|
|
|
|||
|
|
|
|||
|
|
///**
|
|||
|
|
// * @brief <20><><EFBFBD><EFBFBD>X<EFBFBD><58>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// * @param baudrate: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
|
// * @note ע<><D7A2>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>ʱ<EFBFBD><CAB1>Դ, <20><><EFBFBD>ڲ<F2B4AEBF><DAB2><EFBFBD><EFBFBD>ʾͻ<CABE><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣.
|
|||
|
|
// * <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USART<52><54>ʱ<EFBFBD><CAB1>Դ<EFBFBD><D4B4>sys_stm32_clock_init()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>.
|
|||
|
|
// * @retval <20><>
|
|||
|
|
// */
|
|||
|
|
//void usart_init(uint32_t baudrate)
|
|||
|
|
//{
|
|||
|
|
// g_uart1_handle.Instance = USART_UX; /* USART1 */
|
|||
|
|
// g_uart1_handle.Init.BaudRate = baudrate; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
// g_uart1_handle.Init.WordLength = UART_WORDLENGTH_8B; /* <20>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ */
|
|||
|
|
// g_uart1_handle.Init.StopBits = UART_STOPBITS_1; /* һ<><D2BB>ֹͣλ */
|
|||
|
|
// g_uart1_handle.Init.Parity = UART_PARITY_NONE; /* <20><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ */
|
|||
|
|
// g_uart1_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; /* <20><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
// g_uart1_handle.Init.Mode = UART_MODE_TX_RX; /* <20>շ<EFBFBD>ģʽ */
|
|||
|
|
// HAL_UART_Init(&g_uart1_handle); /* HAL_UART_Init()<29><>ʹ<EFBFBD><CAB9>UART1 */
|
|||
|
|
//
|
|||
|
|
// /* <20>ú<EFBFBD><C3BA><EFBFBD><EFBFBD>Ὺ<EFBFBD><E1BFAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD>־λUART_IT_RXNE<4E><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><C3BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
// HAL_UART_Receive_IT(&g_uart1_handle, (uint8_t *)g_rx_buffer, RXBUFFERSIZE);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void UartRD_Init(void)
|
|||
|
|
//{
|
|||
|
|
// /*
|
|||
|
|
// RS485-EN PB8
|
|||
|
|
// */
|
|||
|
|
// GPIO_InitTypeDef GPIO_InitStruct;
|
|||
|
|
|
|||
|
|
// __HAL_RCC_GPIOB_CLK_ENABLE();
|
|||
|
|
|
|||
|
|
// GPIO_InitStruct.Pin = GPIO_PIN_8;
|
|||
|
|
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|||
|
|
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|||
|
|
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|||
|
|
// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|||
|
|
|
|||
|
|
// HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
///**
|
|||
|
|
// * @brief UART<52>ײ<EFBFBD><D7B2><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// * @param huart: UART<52><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
|
// * @note <20>˺<EFBFBD><CBBA><EFBFBD><EFBFBD>ᱻHAL_UART_Init()<29><><EFBFBD><EFBFBD>
|
|||
|
|
// * <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// * @retval <20><>
|
|||
|
|
// */
|
|||
|
|
//void HAL_UART_MspInit(UART_HandleTypeDef *huart)
|
|||
|
|
//{
|
|||
|
|
// GPIO_InitTypeDef gpio_init_struct;
|
|||
|
|
// if(huart->Instance == USART_UX) /* <20><><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>1 MSP<53><50>ʼ<EFBFBD><CABC> */
|
|||
|
|
// {
|
|||
|
|
// USART_UX_CLK_ENABLE(); /* USART1 ʱ<><CAB1>ʹ<EFBFBD><CAB9> */
|
|||
|
|
// USART_TX_GPIO_CLK_ENABLE(); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9> */
|
|||
|
|
// USART_RX_GPIO_CLK_ENABLE(); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9> */
|
|||
|
|
|
|||
|
|
// gpio_init_struct.Pin = USART_TX_GPIO_PIN; /* TX<54><58><EFBFBD><EFBFBD> */
|
|||
|
|
// gpio_init_struct.Mode = GPIO_MODE_AF_PP; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
// gpio_init_struct.Pull = GPIO_PULLUP; /* <20><><EFBFBD><EFBFBD> */
|
|||
|
|
// gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH; /* <20><><EFBFBD><EFBFBD> */
|
|||
|
|
// gpio_init_struct.Alternate = USART_TX_GPIO_AF; /* <20><><EFBFBD><EFBFBD>ΪUSART1 */
|
|||
|
|
// HAL_GPIO_Init(USART_TX_GPIO_PORT, &gpio_init_struct); /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
|
|||
|
|
// gpio_init_struct.Pin = USART_RX_GPIO_PIN; /* RX<52><58><EFBFBD><EFBFBD> */
|
|||
|
|
// gpio_init_struct.Alternate = USART_RX_GPIO_AF; /* <20><><EFBFBD><EFBFBD>ΪUSART1 */
|
|||
|
|
// HAL_GPIO_Init(USART_RX_GPIO_PORT, &gpio_init_struct); /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
|
|||
|
|
//#if USART_EN_RX
|
|||
|
|
// HAL_NVIC_EnableIRQ(USART_UX_IRQn); /* ʹ<><CAB9>USART1<54>ж<EFBFBD>ͨ<EFBFBD><CDA8> */
|
|||
|
|
// HAL_NVIC_SetPriority(USART_UX_IRQn, 3, 3); /* <20><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3 */
|
|||
|
|
//#endif
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_UART_RingBuff_Init;
|
|||
|
|
////Brief: UART <20><><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UART <20><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_UART_RingBuff_Init(UartBuff_TypeDef *hAtUart, UART_HandleTypeDef *huart,
|
|||
|
|
// uint8_t* rxbuff, uint8_t* txbuff, uint16_t buffLen, uint8_t mode)
|
|||
|
|
//{
|
|||
|
|
|
|||
|
|
// huart->pRxBuffPtr = rxbuff;
|
|||
|
|
// huart->pTxBuffPtr = txbuff;
|
|||
|
|
//
|
|||
|
|
// huart->RxXferSize = 0;
|
|||
|
|
// huart->TxXferSize = 0;
|
|||
|
|
//
|
|||
|
|
// huart->RxXferCount = 0;
|
|||
|
|
// huart->TxXferCount = 0;
|
|||
|
|
//
|
|||
|
|
////#if defined (__STM32L1xx_HAL_H) // Cortex-M3
|
|||
|
|
//// huart->State = HAL_UART_STATE_BUSY_RX;
|
|||
|
|
////#elif defined (__STM32F1xx_HAL_H) || defined (__STM32F0xx_HAL_H) || defined (__STM32L0xx_HAL_H) || defined (__STM32L4xx_HAL_H)
|
|||
|
|
// huart->gState = HAL_UART_STATE_READY;
|
|||
|
|
// huart->RxState = HAL_UART_STATE_BUSY_RX;
|
|||
|
|
////#endif
|
|||
|
|
//
|
|||
|
|
// hAtUart->pUART = huart;
|
|||
|
|
// hAtUart->mode = mode;
|
|||
|
|
// hAtUart->CmdStatus = 0;
|
|||
|
|
// hAtUart->BufferLen = buffLen;
|
|||
|
|
//
|
|||
|
|
// __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
|
|||
|
|
// __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: bUART_IT_TxEnd;
|
|||
|
|
////Brief: UART <20>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void bUART_IT_TxEnd(UartBuff_TypeDef *hAtUart)
|
|||
|
|
//{
|
|||
|
|
// //UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: bUART_IT_Rx;
|
|||
|
|
////Brief: UART <20>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void bUART_IT_Rx(UartBuff_TypeDef *hAtUart, uint32_t errorflags)
|
|||
|
|
//{
|
|||
|
|
// UART_HandleTypeDef *huart =hAtUart->pUART;
|
|||
|
|
//
|
|||
|
|
////#if defined (__STM32F1xx_HAL_H) || defined (__STM32L1xx_HAL_H) // Cortex-M3
|
|||
|
|
//// uint8_t data = (uint8_t)(hAtUart->pUART->Instance->DR);
|
|||
|
|
////#elif defined (__STM32F0xx_HAL_H) || defined (__STM32L0xx_HAL_H) || defined (__STM32F3xx_HAL_H) || defined (__STM32L4xx_HAL_H)
|
|||
|
|
// uint8_t data = (uint8_t)(huart->Instance->RDR);
|
|||
|
|
////#endif
|
|||
|
|
//
|
|||
|
|
// if(errorflags!=RESET)
|
|||
|
|
// {
|
|||
|
|
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD>뻺<EFBFBD><EBBBBA>
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// huart->pRxBuffPtr[huart->RxXferCount] = data;
|
|||
|
|
//
|
|||
|
|
// if(hAtUart->mode == UART_MODE_AT)
|
|||
|
|
// {
|
|||
|
|
// if((data == (uint8_t)AT_STR[0]) && (hAtUart->CmdStatus==0))//<2F>ж<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>һ<EFBFBD>ֽ<EFBFBD>
|
|||
|
|
// {
|
|||
|
|
// hAtUart->CmdStatus = CMD_1ST;
|
|||
|
|
// huart->pRxBuffPtr[0] = data;
|
|||
|
|
// huart->RxXferSize=0;
|
|||
|
|
// huart->RxXferCount=1;
|
|||
|
|
// }
|
|||
|
|
// else if( (data == (uint8_t)AT_STR[1]) && (huart->RxXferCount==1) &&
|
|||
|
|
// (hAtUart->CmdStatus == CMD_1ST) ) //<2F>ж<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ڶ<EFBFBD><DAB6>ֽ<EFBFBD>
|
|||
|
|
// {
|
|||
|
|
// hAtUart->CmdStatus = CMD_2ST;
|
|||
|
|
// huart->RxXferCount++;
|
|||
|
|
// }
|
|||
|
|
// else if (hAtUart->CmdStatus == CMD_2ST)
|
|||
|
|
// {
|
|||
|
|
// huart->RxXferCount++;
|
|||
|
|
// // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
// if (huart->RxXferCount>=hAtUart->BufferLen)
|
|||
|
|
// {
|
|||
|
|
// //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
// hAtUart->CmdStatus=0;
|
|||
|
|
// huart->RxXferCount=0;
|
|||
|
|
// }else{
|
|||
|
|
// // <20>س<EFBFBD><D8B3>ж<EFBFBD>
|
|||
|
|
// if(data == 0x0A){
|
|||
|
|
// if(huart->pRxBuffPtr[huart->RxXferCount - 2]==0x0D)
|
|||
|
|
// {
|
|||
|
|
// BSP_AddBuff(hAtUart);
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// }else{
|
|||
|
|
// }
|
|||
|
|
// }else{ //____________ UART_MODE_DATA __________________________________//
|
|||
|
|
// // <20>س<EFBFBD><D8B3>ж<EFBFBD>
|
|||
|
|
// if(data == 0x0A)
|
|||
|
|
// {
|
|||
|
|
// if(huart->pRxBuffPtr[huart->RxXferCount - 1]==0x0D)
|
|||
|
|
// {
|
|||
|
|
// // <20><><EFBFBD><EFBFBD>idle<6C>жϱ<D0B6><CFB1><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// __HAL_UART_DISABLE_IT(huart, UART_IT_IDLE);
|
|||
|
|
// if (++huart->RxXferCount>=hAtUart->BufferLen) huart->RxXferCount=0;
|
|||
|
|
// BSP_AddBuff(hAtUart);
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// // <20><>IDLE<4C><45>־
|
|||
|
|
//#if defined (__STM32F1xx_HAL_H) || defined (__STM32L1xx_HAL_H) // Cortex-M3
|
|||
|
|
// // <20>ȶ<EFBFBD>SR<53><52><EFBFBD>ٶ<EFBFBD>DR <20><><EFBFBD><EFBFBD> IDLE | ORE | NE | FE | PE
|
|||
|
|
//#elif defined (__STM32F0xx_HAL_H) || defined (__STM32L0xx_HAL_H) || defined (__STM32L4xx_HAL_H)
|
|||
|
|
// __HAL_UART_CLEAR_IT(huart, UART_CLEAR_IDLEF);
|
|||
|
|
//#endif
|
|||
|
|
// // <20><><EFBFBD><EFBFBD>idle<6C>ж<EFBFBD>
|
|||
|
|
// __HAL_UART_ENABLE_IT(huart, UART_IT_IDLE);
|
|||
|
|
//
|
|||
|
|
// if (++huart->RxXferCount>=hAtUart->BufferLen) huart->RxXferCount=0;
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: bUART_IT_Idle;
|
|||
|
|
////Brief: UART <20>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void bUART_IT_Idle(UartBuff_TypeDef *hAtUart)
|
|||
|
|
//{
|
|||
|
|
// UART_HandleTypeDef *huart =hAtUart->pUART;
|
|||
|
|
// __HAL_UART_DISABLE_IT(huart, UART_IT_IDLE);
|
|||
|
|
//
|
|||
|
|
// BSP_AddBuff(hAtUart);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_USART_IRQHandler;
|
|||
|
|
////Brief: UART <20>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void bUART_IT_Tx(UartBuff_TypeDef *hAtUart)
|
|||
|
|
//{
|
|||
|
|
// UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
// if (huart->TxXferCount != huart->TxXferSize ) // δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// {
|
|||
|
|
//#if defined (__STM32F1xx_HAL_H) || defined (__STM32L1xx_HAL_H) // Cortex-M3
|
|||
|
|
// huart->Instance->DR = huart->pTxBuffPtr[huart->TxXferCount++];
|
|||
|
|
//#elif defined (__STM32F0xx_HAL_H) || defined (__STM32L0xx_HAL_H) || defined (__STM32L4xx_HAL_H)
|
|||
|
|
// huart->Instance->TDR = huart->pTxBuffPtr[huart->TxXferCount++];
|
|||
|
|
//#endif
|
|||
|
|
// if (huart->TxXferCount >= hAtUart->BufferLen) huart->TxXferCount =0;
|
|||
|
|
// }else{
|
|||
|
|
// // ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
// __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
|
|||
|
|
//
|
|||
|
|
//#if defined (__STM32L1xx_HAL_H) // Cortex-M3
|
|||
|
|
// huart->State = HAL_UART_STATE_BUSY_RX;
|
|||
|
|
//#elif defined (__STM32F1xx_HAL_H) || defined (__STM32F0xx_HAL_H) || defined (__STM32L0xx_HAL_H) || defined (__STM32L4xx_HAL_H)
|
|||
|
|
// huart->gState = HAL_UART_STATE_READY;
|
|||
|
|
// huart->RxState = HAL_UART_STATE_BUSY_RX;
|
|||
|
|
//#endif
|
|||
|
|
//
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_USART_IRQHandler;
|
|||
|
|
////Brief: UART <20>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_USART_IRQHandler(UartBuff_TypeDef *hAtUart)
|
|||
|
|
//{
|
|||
|
|
// UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
//
|
|||
|
|
////#if defined (__STM32F1xx_HAL_H) || defined (__STM32L1xx_HAL_H) // Cortex-M3
|
|||
|
|
//// uint32_t isrflags= READ_REG(huart->Instance->SR);
|
|||
|
|
////#elif defined (__STM32F0xx_HAL_H) || defined (__STM32L0xx_HAL_H) || defined (__STM32F3xx_HAL_H) || defined (__STM32L4xx_HAL_H)
|
|||
|
|
// uint32_t isrflags= READ_REG(huart->Instance->ISR);
|
|||
|
|
////#endif
|
|||
|
|
// uint32_t cr1its = READ_REG(huart->Instance->CR1);
|
|||
|
|
// uint32_t cr2its = READ_REG(huart->Instance->CR2);
|
|||
|
|
// uint32_t cr3its = READ_REG(huart->Instance->CR3);
|
|||
|
|
// uint32_t errorflags;
|
|||
|
|
//
|
|||
|
|
// errorflags = isrflags & 0x0000000F;
|
|||
|
|
//
|
|||
|
|
//#if defined (__STM32L4xx_HAL_H)
|
|||
|
|
// // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Wakeup<75><70>־ 2019-3-19
|
|||
|
|
// if (((isrflags & USART_ISR_WUF) != RESET) && ((cr3its & USART_CR3_WUFIE) != RESET))
|
|||
|
|
// {
|
|||
|
|
// __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_WUF);
|
|||
|
|
// }
|
|||
|
|
//#endif
|
|||
|
|
//
|
|||
|
|
// if (errorflags != RESET)
|
|||
|
|
// {//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>ִ<EFBFBD><D6B4>
|
|||
|
|
// /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>־ */
|
|||
|
|
//#if defined (__STM32F1xx_HAL_H) || defined (__STM32L1xx_HAL_H) // Cortex-M3
|
|||
|
|
// // M3<4D><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD>ȶ<EFBFBD>SR<53><52><EFBFBD>ٶ<EFBFBD>DR <20><><EFBFBD><EFBFBD> IDLE | ORE | NE | FE | PE
|
|||
|
|
// uint32_t tmp= READ_REG(huart->Instance->SR);
|
|||
|
|
// tmp += READ_REG(huart->Instance->DR);
|
|||
|
|
//#elif defined (__STM32F0xx_HAL_H) || defined (__STM32L0xx_HAL_H) //Cortex-M0
|
|||
|
|
// __HAL_UART_CLEAR_IT(huart, 0x0000000F);
|
|||
|
|
//#endif
|
|||
|
|
// HAL_UART_ErrorCallback(huart);
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
// huart->ErrorCode |= HAL_UART_ERROR_PE;
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// //_______________________________________________________________________//
|
|||
|
|
// //__ <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> _________________________________________________________//
|
|||
|
|
// if(((isrflags & UART_FLAG_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
|
|||
|
|
// {
|
|||
|
|
// bUART_IT_Rx(hAtUart,errorflags);
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// //_______________________________________________________________________//
|
|||
|
|
// //__ <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> _________________________________________________________//
|
|||
|
|
// if(((isrflags & UART_FLAG_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
|
|||
|
|
// {
|
|||
|
|
// bUART_IT_Tx(hAtUart);
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// //_______________________________________________________________________//
|
|||
|
|
// //__ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> ______________________________________________________//
|
|||
|
|
// if(((isrflags & UART_FLAG_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
|
|||
|
|
// {
|
|||
|
|
// bUART_IT_TxEnd(hAtUart);
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
//
|
|||
|
|
// //_______________________________________________________________________//
|
|||
|
|
// //__ <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> _________________________________________________________//
|
|||
|
|
// if(((isrflags & UART_FLAG_IDLE) != RESET) && ((cr1its & USART_CR1_IDLEIE) != RESET))
|
|||
|
|
// {
|
|||
|
|
// bUART_IT_Idle(hAtUart);
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_UART_Entel_Half;
|
|||
|
|
////Brief: UART<52><54><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3>ģʽ
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_UART_Entel_Half(UartBuff_TypeDef *hAtUart)
|
|||
|
|
//{
|
|||
|
|
// // GPIO_InitTypeDef GPIO_InitStruct;
|
|||
|
|
// // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
//
|
|||
|
|
// uint8_t timeout = 20; //<2F>ȴ<EFBFBD>200ms
|
|||
|
|
// while (huart->TxXferCount != huart->TxXferSize ){
|
|||
|
|
// if (--timeout==0){
|
|||
|
|
// // ǿ<><C7BF>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|||
|
|
// break;
|
|||
|
|
// }
|
|||
|
|
// HAL_Delay(10);
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// /* Peripheral interrupt Deinit*/
|
|||
|
|
// HAL_NVIC_DisableIRQ(USART1_IRQn);
|
|||
|
|
//
|
|||
|
|
// /* Peripheral clock disable */
|
|||
|
|
// __HAL_RCC_USART1_CLK_DISABLE();
|
|||
|
|
// __HAL_UART_DISABLE(huart);
|
|||
|
|
//
|
|||
|
|
// // <20><><EFBFBD><EFBFBD>ҪRX<52><58><EFBFBD><EFBFBD> ʹ<><CAB9> RX IO<49><4F><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
// // GPIO_InitStruct.Pin = USART1_RX_Pin;
|
|||
|
|
// // GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
|||
|
|
// // GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|||
|
|
// // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|||
|
|
// //
|
|||
|
|
// // HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
|
|||
|
|
// // HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
|||
|
|
// // __HAL_GPIO_EXTI_CLEAR_IT(GPIO_InitStruct.Pin);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_UART_Exit_Half;
|
|||
|
|
////Brief: UART<52><54><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><F3A3ACBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_UART_Exit_Half(UartBuff_TypeDef *hAtUart)
|
|||
|
|
//{
|
|||
|
|
// UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
// // GPIO_InitTypeDef GPIO_InitStruct;
|
|||
|
|
//
|
|||
|
|
// huart->RxXferSize = 0;
|
|||
|
|
// huart->TxXferSize = 0;
|
|||
|
|
// huart->RxXferCount = 0;
|
|||
|
|
// huart->TxXferCount = 0;
|
|||
|
|
// hAtUart->CmdStatus = 0;
|
|||
|
|
//
|
|||
|
|
//
|
|||
|
|
//#if defined (__STM32L1xx_HAL_H) // Cortex-M3
|
|||
|
|
// huart->State = HAL_UART_STATE_BUSY_RX;
|
|||
|
|
//#elif defined (__STM32F1xx_HAL_H) || defined (__STM32F0xx_HAL_H) || defined (__STM32L0xx_HAL_H) //Cortex-M0
|
|||
|
|
// huart->gState = HAL_UART_STATE_READY;
|
|||
|
|
// huart->RxState = HAL_UART_STATE_BUSY_RX;
|
|||
|
|
//#endif
|
|||
|
|
//
|
|||
|
|
// // GPIO_InitStruct.Pin = USART1_RX_Pin;
|
|||
|
|
// // GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|||
|
|
// // GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|||
|
|
// // HAL_GPIO_Init(USART1_RX_GPIO_Port, &GPIO_InitStruct);
|
|||
|
|
// //MX_USART1_UART_Init(); //<2F><><EFBFBD>³<EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
|
//
|
|||
|
|
// __HAL_RCC_USART1_CLK_ENABLE();
|
|||
|
|
// __HAL_UART_ENABLE(huart);
|
|||
|
|
// HAL_NVIC_EnableIRQ(USART1_IRQn);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_AddBuff;
|
|||
|
|
////Brief: <09><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_AddBuff(UartBuff_TypeDef *hAtUart)
|
|||
|
|
//{
|
|||
|
|
// UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
// StrBuff_TypeDef *combuff = &hAtUart->CmbBuff[hAtUart->HandlePtr];
|
|||
|
|
// uint16_t size;
|
|||
|
|
// uint16_t freelen;
|
|||
|
|
// if(huart->RxXferCount > huart->RxXferSize )
|
|||
|
|
// {
|
|||
|
|
// size = huart->RxXferCount - huart->RxXferSize;
|
|||
|
|
// memcpy(combuff->Buff, (huart->pRxBuffPtr + huart->RxXferSize), size);
|
|||
|
|
//
|
|||
|
|
// }else{ //<2F><>Խ<EFBFBD>߽<EFBFBD>
|
|||
|
|
// freelen = hAtUart->BufferLen - huart->RxXferSize;
|
|||
|
|
// size = huart->RxXferCount + freelen;
|
|||
|
|
//
|
|||
|
|
// memcpy(combuff->Buff, (huart->pRxBuffPtr + huart->RxXferSize), freelen);
|
|||
|
|
// memcpy((combuff->Buff + freelen), huart->pRxBuffPtr , huart->RxXferCount);
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// combuff->Len = size;
|
|||
|
|
//
|
|||
|
|
// if(++hAtUart->HandlePtr>=5) hAtUart->HandlePtr=0;
|
|||
|
|
//
|
|||
|
|
// //memset(huart->pRxBuffPtr,0,huart->RxXferCount);//<2F><>0
|
|||
|
|
// huart->RxXferCount=0;
|
|||
|
|
// huart->RxXferSize =0;
|
|||
|
|
// hAtUart->CmdStatus =0;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_SendChar;
|
|||
|
|
////Brief: <09><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2BFAAB4><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_SendChar(UartBuff_TypeDef *hAtUart, uint8_t ch)
|
|||
|
|
//{
|
|||
|
|
// //UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
// UART_HandleTypeDef *huart = &g_uart1_handle;
|
|||
|
|
// huart->pTxBuffPtr[huart->TxXferSize]=ch;
|
|||
|
|
// if( ++(huart->TxXferSize) >= hAtUart->BufferLen ) huart->TxXferSize=0;
|
|||
|
|
// __HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_SendStr;
|
|||
|
|
////Brief: <09><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2BFAAB4><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_SendStr(UartBuff_TypeDef *hAtUart, uint8_t *str,uint16_t len)
|
|||
|
|
//{
|
|||
|
|
// UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
// uint16_t freelen = hAtUart->BufferLen - huart->TxXferSize;
|
|||
|
|
// if (freelen >= len) // <20><><EFBFBD>㹻<EFBFBD><E3B9BB><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>
|
|||
|
|
// {
|
|||
|
|
// memcpy( (huart->pTxBuffPtr+huart->TxXferSize), str, len);
|
|||
|
|
// huart->TxXferSize += len;
|
|||
|
|
// if( huart->TxXferSize >= hAtUart->BufferLen ) huart->TxXferSize -= hAtUart->BufferLen;
|
|||
|
|
// }else{ // <20><>Խ<EFBFBD>߽<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>
|
|||
|
|
// memcpy( (huart->pTxBuffPtr+huart->TxXferSize), str, freelen);
|
|||
|
|
// huart->TxXferSize = len-freelen;
|
|||
|
|
// memcpy( huart->pTxBuffPtr, (str+freelen), huart->TxXferSize);
|
|||
|
|
//
|
|||
|
|
// }
|
|||
|
|
// __HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_UART_Polling;
|
|||
|
|
////Brief: ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_UART_Polling(UartBuff_TypeDef *hAtUart)
|
|||
|
|
//{
|
|||
|
|
// //UART_HandleTypeDef *huart = hAtUart->pUART;
|
|||
|
|
// StrBuff_TypeDef *combuff;
|
|||
|
|
|
|||
|
|
// while(hAtUart->HandlePtr != hAtUart->PresentPtr)
|
|||
|
|
// {
|
|||
|
|
// combuff = &hAtUart->CmbBuff[hAtUart->PresentPtr];
|
|||
|
|
// // <* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5>վ<EFBFBD><D5BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ATָ<54><D6B8> *>
|
|||
|
|
// {
|
|||
|
|
// BSP_UART_Callback(combuff->Buff,combuff->Len);
|
|||
|
|
// }
|
|||
|
|
// // <* END *>
|
|||
|
|
// if(++hAtUart->PresentPtr>=5) hAtUart->PresentPtr=0;
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: BSP_UART_Callback;
|
|||
|
|
////Brief: <09><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//__weak void BSP_UART_Callback(uint8_t *str,uint8_t len)
|
|||
|
|
//{
|
|||
|
|
// BSP_SendStr(&AtCmdUart,str,len);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: ANO_F2I;
|
|||
|
|
////Brief: <09><><EFBFBD><EFBFBD> float to uint8_t
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void ANO_F2I(uint8_t *pint8, float f,uint8_t *len)
|
|||
|
|
//{
|
|||
|
|
//#if (ANO_DEBUG==1)
|
|||
|
|
// *pint8++ = BYTE3(f);
|
|||
|
|
// *pint8++ = BYTE2(f);
|
|||
|
|
// *pint8++ = BYTE1(f);
|
|||
|
|
// *pint8 = BYTE0(f);
|
|||
|
|
// *len +=4;
|
|||
|
|
//#endif
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: ANO_F2I;
|
|||
|
|
////Brief: <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD>ֽ<EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//uint8_t ANO_sum(uint8_t *pint8, uint8_t len)
|
|||
|
|
//{
|
|||
|
|
//
|
|||
|
|
// uint8_t sum=0;
|
|||
|
|
// while(len-->0)
|
|||
|
|
// sum += *pint8++;
|
|||
|
|
// return sum;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
////=====================================================================//
|
|||
|
|
////Description: ANO_F2I;
|
|||
|
|
////Brief: <09><><EFBFBD><EFBFBD> <20><>ӡһ<D3A1><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
////=====================================================================//
|
|||
|
|
//void BSP_ANO( uint16_t x,uint16_t y,uint16_t z,uint16_t f,uint16_t p,uint16_t d)
|
|||
|
|
//{
|
|||
|
|
//#if (ANO_DEBUG==1)
|
|||
|
|
// uint8_t ano[64]={0};
|
|||
|
|
// uint8_t fun = 0xF1;
|
|||
|
|
// uint8_t cnt=0;
|
|||
|
|
//
|
|||
|
|
// ano[cnt++]=0xAA;
|
|||
|
|
// ano[cnt++]=0xAA;// ָ<><D6B8>ͷ
|
|||
|
|
// ano[cnt++]=fun; // <20><><EFBFBD><EFBFBD>/֡
|
|||
|
|
// ano[cnt++]=0; // <20><><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// ano[cnt++]= BYTE1(x);
|
|||
|
|
// ano[cnt++]= BYTE0(x);
|
|||
|
|
// ano[cnt++]= BYTE1(y);
|
|||
|
|
// ano[cnt++]= BYTE0(y);
|
|||
|
|
// ano[cnt++]= BYTE1(z);
|
|||
|
|
// ano[cnt++]= BYTE0(z);
|
|||
|
|
// ano[cnt++]= BYTE1(f);
|
|||
|
|
// ano[cnt++]= BYTE0(f);
|
|||
|
|
// ano[cnt++]= BYTE1(p);
|
|||
|
|
// ano[cnt++]= BYTE0(p);
|
|||
|
|
// ano[cnt++]= BYTE1(d);
|
|||
|
|
// ano[cnt++]= BYTE0(d);
|
|||
|
|
//// ANO_F2I( &ano[cnt],f,&cnt);
|
|||
|
|
// ano[3]=cnt-4; // <20><><EFBFBD><EFBFBD>
|
|||
|
|
// ano[cnt]=ANO_sum(ano,cnt); //У<><D0A3>
|
|||
|
|
// cnt++;
|
|||
|
|
//
|
|||
|
|
// BSP_SendStr(&AtCmdUart,ano,cnt);
|
|||
|
|
//#endif
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//void HAL_UART_IDLECallback(UART_HandleTypeDef *huart)
|
|||
|
|
//{
|
|||
|
|
// BaseType_t xHigherPriorityTaskWoken=1;
|
|||
|
|
// u8 Res;
|
|||
|
|
|
|||
|
|
|
|||
|
|
// if(huart->Instance == USART3)
|
|||
|
|
// {
|
|||
|
|
// Res = (uint8_t)(huart->Instance->RDR) ;
|
|||
|
|
// usart1_buf.RxBuff[usart1_buf.RxSize++] = Res;
|
|||
|
|
// if(usart1_buf.RxBuff[0]!=0xab)
|
|||
|
|
// usart1_buf.RxSize=0;
|
|||
|
|
// if(usart1_buf.RxSize>50)
|
|||
|
|
// usart1_buf.RxSize=50;
|
|||
|
|
// HAL_UART_Receive_IT(huart, &usart1_buf.aRxBuff, 1);
|
|||
|
|
// if(__HAL_UART_GET_FLAG(huart,UART_FLAG_IDLE) != RESET)
|
|||
|
|
// {
|
|||
|
|
// __HAL_UART_CLEAR_IDLEFLAG(huart);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
|||
|
|
//
|
|||
|
|
// if(usart1_buf.RxBuff[0]==0Xab && usart1_buf.RxSize>4)
|
|||
|
|
// {
|
|||
|
|
// __HAL_UART_DISABLE_IT(huart, UART_IT_IDLE);//__HAL_UART_DISABLE_IT(&huart1, UART_IT_IDLE); //<2F>ر<EFBFBD>idle<6C>ж<EFBFBD>
|
|||
|
|
// xQueueSendFromISR(Uart_Queue_Handle,usart1_buf.RxBuff ,&xHigherPriorityTaskWoken);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// //portYIELD_FROM_ISR(xHigherPriorityTaskWoken);//<2F><><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// if(__HAL_UART_GET_FLAG(huart,UART_FLAG_ORE) != RESET)
|
|||
|
|
// {
|
|||
|
|
// __HAL_UART_CLEAR_OREFLAG(huart);
|
|||
|
|
// }
|
|||
|
|
// if(__HAL_UART_GET_FLAG(huart,UART_FLAG_ORE) != RESET)
|
|||
|
|
// {
|
|||
|
|
//
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
|||
|
|
//{
|
|||
|
|
// if(huart->Instance == USART3)
|
|||
|
|
// {
|
|||
|
|
// if(usart1_buf.Tx_end_flag == 0)
|
|||
|
|
// {
|
|||
|
|
// //debug_printf("\r\n\r\n<><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d\r\n",usart1_buf.TxSize);
|
|||
|
|
// //usart1_buf.TxSize = 0;
|
|||
|
|
// usart1_buf.Tx_end_flag = 1;
|
|||
|
|
// //memset(usart1_buf.TxBuff,0,usart1_buf.TxSize);
|
|||
|
|
// RX3_UART();
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
///**
|
|||
|
|
// * @brief Rx<52><78><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// * @param huart: UART<52><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
|
// * @retval <20><>
|
|||
|
|
// */
|
|||
|
|
//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
|||
|
|
//{
|
|||
|
|
// if(huart->Instance == USART_UX) /* <20><><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD>1 */
|
|||
|
|
// {
|
|||
|
|
// if((g_usart_rx_sta & 0x8000) == 0) /* <20><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
|
|||
|
|
// {
|
|||
|
|
// if(g_usart_rx_sta & 0x4000) /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>0x0d */
|
|||
|
|
// {
|
|||
|
|
// if(g_rx_buffer[0] != 0x0a)
|
|||
|
|
// {
|
|||
|
|
// g_usart_rx_sta = 0; /* <20><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>,<2C><><EFBFBD>¿<EFBFBD>ʼ */
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// g_usart_rx_sta |= 0x8000; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// else /* <20><>û<EFBFBD>յ<EFBFBD>0X0D */
|
|||
|
|
// {
|
|||
|
|
// if(g_rx_buffer[0] == 0x0d)
|
|||
|
|
// {
|
|||
|
|
// g_usart_rx_sta |= 0x4000;
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// g_usart_rx_buf[g_usart_rx_sta & 0X3FFF] = g_rx_buffer[0] ;
|
|||
|
|
// g_usart_rx_sta++;
|
|||
|
|
// if(g_usart_rx_sta > (USART_REC_LEN - 1))
|
|||
|
|
// {
|
|||
|
|
// g_usart_rx_sta = 0; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>,<2C><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> */
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
// HAL_UART_Receive_IT(&g_uart1_handle, (uint8_t *)g_rx_buffer, RXBUFFERSIZE);
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
///**
|
|||
|
|
// * @brief <20><><EFBFBD><EFBFBD>1<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// * @param <20><>
|
|||
|
|
// * @retval <20><>
|
|||
|
|
// */
|
|||
|
|
//void USART_UX_IRQHandler(void)
|
|||
|
|
//{
|
|||
|
|
//#if SYS_SUPPORT_OS /* ʹ<><CAB9>OS */
|
|||
|
|
// OSIntEnter();
|
|||
|
|
//#endif
|
|||
|
|
|
|||
|
|
// HAL_UART_IRQHandler(&g_uart1_handle); /* <20><><EFBFBD><EFBFBD>HAL<41><4C><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD> */
|
|||
|
|
|
|||
|
|
//#if SYS_SUPPORT_OS /* ʹ<><CAB9>OS */
|
|||
|
|
// OSIntExit();
|
|||
|
|
//#endif
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//#endif
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//unsigned char Test_Data_Flag = 0;
|
|||
|
|
|
|||
|
|
//#if 1
|
|||
|
|
////<2F>ض<EFBFBD><D8B6><EFBFBD>c<EFBFBD>⺯<EFBFBD><E2BAAF>printf<74><66>USART1
|
|||
|
|
//int fputc(int ch, FILE *f)
|
|||
|
|
//{
|
|||
|
|
///* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵ<EFBFBD>USART1 */
|
|||
|
|
// USART_SendData(USART1, (uint8_t) ch);
|
|||
|
|
|
|||
|
|
// /* <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
// while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
|
|||
|
|
// return (ch);
|
|||
|
|
//}
|
|||
|
|
//#endif
|
|||
|
|
////<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD> 2022.2.5
|
|||
|
|
////<2F>Ĵ<DEB8><C4B4><EFBFBD>ΪPB6 PB7 2022.2.5
|
|||
|
|
//void USART1_Config(u32 bound)
|
|||
|
|
//{
|
|||
|
|
// USART_InitTypeDef USART_InitStructure;
|
|||
|
|
// GPIO_InitTypeDef GPIO_InitStructure;
|
|||
|
|
// NVIC_InitTypeDef NVIC_InitStruct;
|
|||
|
|
//
|
|||
|
|
// RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
|||
|
|
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
|||
|
|
//
|
|||
|
|
// GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_6 | GPIO_Pin_7); //USART1<54><31>Ӧ<EFBFBD><D3A6>TX<54><58>RX,<2C><><EFBFBD><EFBFBD> PB6 PB7
|
|||
|
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //<2F><><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|||
|
|
// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|||
|
|
// GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|||
|
|
//
|
|||
|
|
// GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_8); //485ʹ<35><CAB9> PB8
|
|||
|
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|||
|
|
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|||
|
|
// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|||
|
|
// GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|||
|
|
//
|
|||
|
|
// //<2F><><EFBFBD>ø<EFBFBD><C3B8>ù<EFBFBD><C3B9><EFBFBD>
|
|||
|
|
// GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_7);
|
|||
|
|
// GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_7);
|
|||
|
|
//
|
|||
|
|
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
|||
|
|
// NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;
|
|||
|
|
// NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
|
|||
|
|
// NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
|
|||
|
|
// NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
|||
|
|
// NVIC_Init(&NVIC_InitStruct);
|
|||
|
|
//
|
|||
|
|
// //USART_InitStructure.USART_BaudRate = 115200;
|
|||
|
|
// USART_InitStructure.USART_BaudRate = bound;
|
|||
|
|
// 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_DeInit(USART1);
|
|||
|
|
// USART_Init(USART1, &USART_InitStructure);
|
|||
|
|
// USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//ʹ<><CAB9><EFBFBD>ж<EFBFBD>
|
|||
|
|
// USART_ClearFlag(USART1,USART_FLAG_TC);
|
|||
|
|
// USART_Cmd(USART1, ENABLE);
|
|||
|
|
//
|
|||
|
|
// RS485_RX_EN;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void USART_SendStr(USART_TypeDef* USARTx, uint8_t *PData,uint16_t Datalen)
|
|||
|
|
//{
|
|||
|
|
// RS485_TX_EN;
|
|||
|
|
// Delayus(200);
|
|||
|
|
// u16 i=0;
|
|||
|
|
// for(;i< Datalen;i++)
|
|||
|
|
// {
|
|||
|
|
// USART_SendData(USARTx, *(PData+i));
|
|||
|
|
// while (!USART_GetFlagStatus(USART1,USART_FLAG_TC));
|
|||
|
|
// }
|
|||
|
|
// RS485_RX_EN;
|
|||
|
|
//
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void USART_SentByte(USART_TypeDef* USARTx, uint16_t Data)
|
|||
|
|
//{
|
|||
|
|
// RS485_TX_EN;
|
|||
|
|
// Delayus(200);
|
|||
|
|
// USART_SendData(USARTx, Data);
|
|||
|
|
// while (!USART_GetFlagStatus(USART1,USART_FLAG_TC));
|
|||
|
|
// RS485_RX_EN;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
////<2F>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//void USART1_IRQHandler (void)
|
|||
|
|
//{
|
|||
|
|
// uint8_t res = 0;
|
|||
|
|
// if (USART_GetFlagStatus(USART1,USART_FLAG_RXNE) ==SET)
|
|||
|
|
// {
|
|||
|
|
// res=USART_ReceiveData(USART1);
|
|||
|
|
// PushQueue(&RecQueue,res);
|
|||
|
|
|
|||
|
|
// }
|
|||
|
|
// USART_ClearITPendingBit(USART1,USART_IT_RXNE);//<2F><><EFBFBD>жϱ<D0B6>־λ
|
|||
|
|
//}
|
|||
|
|
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD>
|
|||
|
|
////void USART1_SET_Baudrate(u8 bound)
|
|||
|
|
////{
|
|||
|
|
//// switch(bound)
|
|||
|
|
//// {
|
|||
|
|
//// case 0:
|
|||
|
|
//// USART1_Config(SET_BAUDRATE_9600);
|
|||
|
|
//// break;
|
|||
|
|
//// case 1:
|
|||
|
|
//// USART1_Config(SET_BAUDRATE_38400);
|
|||
|
|
//// break;
|
|||
|
|
//// case 2:
|
|||
|
|
//// USART1_Config(SET_BAUDRATE_57600);
|
|||
|
|
//// break;
|
|||
|
|
//// case 3:
|
|||
|
|
//// USART1_Config(SET_BAUDRATE_115200);
|
|||
|
|
//// break;
|
|||
|
|
//// default:break;
|
|||
|
|
//// }
|
|||
|
|
////}
|
|||
|
|
////<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD> 2022.2.7
|
|||
|
|
////void USART2_Init(u32 bound)
|
|||
|
|
////{
|
|||
|
|
//// //<2F><>ʼ<EFBFBD><CABC><EFBFBD>ṹ<EFBFBD><E1B9B9> 2022.2.7
|
|||
|
|
//// GPIO_InitTypeDef GPIO_InitStructure;
|
|||
|
|
//// USART_InitTypeDef USART_InitStructure;
|
|||
|
|
//// NVIC_InitTypeDef NVIC_InitStructure;
|
|||
|
|
//// //|RCC_APB2Periph_AFIO
|
|||
|
|
//// RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //ʹ<><CAB9>GPIOAʱ<41><CAB1>
|
|||
|
|
//// RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); //ʹ<><CAB9>USART2ʱ<32><CAB1>
|
|||
|
|
////
|
|||
|
|
//// GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_2 | GPIO_Pin_3); //USART2<54><32>Ӧ<EFBFBD><D3A6>TX<54><58>RX,<2C><><EFBFBD><EFBFBD> PA2 PA3
|
|||
|
|
//// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //<2F><><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
//// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|||
|
|
//// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
//// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|||
|
|
//// GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|||
|
|
////
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_11); //<2F><><EFBFBD>Զ˿<D4B6>PA11 22.3.15
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|||
|
|
//// //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
//// //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|||
|
|
//// //GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|||
|
|
////
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA2
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// //GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|||
|
|
////
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//PA3
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// //GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|||
|
|
////
|
|||
|
|
//// //RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,ENABLE);//<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>2
|
|||
|
|
//// //RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,DISABLE);//ֹͣ<CDA3><D6B9>λ
|
|||
|
|
////
|
|||
|
|
//// //<2F><><EFBFBD>ø<EFBFBD><C3B8>ù<EFBFBD><C3B9><EFBFBD>
|
|||
|
|
//// GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_7);
|
|||
|
|
//// GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_7);
|
|||
|
|
////
|
|||
|
|
//// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //<2F><><EFBFBD><EFBFBD>NVIC<49>жϷ<D0B6><CFB7><EFBFBD>2:2λ<32><CEBB>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD>2λ<32><CEBB>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD> 0-3;
|
|||
|
|
//// NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>2<EFBFBD>ж<EFBFBD>
|
|||
|
|
//// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>2<EFBFBD><32>
|
|||
|
|
//// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>2<EFBFBD><32>
|
|||
|
|
//// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹ<><CAB9><EFBFBD>ⲿ<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
|
//// NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>NVIC_InitStruct<63><74>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NVIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
////
|
|||
|
|
//// USART_InitStructure.USART_BaudRate = bound;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8λ<38><CEBB><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
|
//// USART_InitStructure.USART_StopBits = USART_StopBits_1;//һ<><D2BB>ֹͣλ
|
|||
|
|
//// USART_InitStructure.USART_Parity = USART_Parity_No;///<2F><>żУ<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_DeInit(USART2);
|
|||
|
|
//// USART_Init(USART2, &USART_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
//// //USART_ClearFlag(USART2,USART_FLAG_TC); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ձ<EFBFBD>־
|
|||
|
|
//// USART_Cmd(USART2, ENABLE); //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>
|
|||
|
|
////}
|
|||
|
|
// /**
|
|||
|
|
//* USART2<54><32><EFBFBD><EFBFBD>len<65><6E><EFBFBD>ֽ<EFBFBD>.
|
|||
|
|
//* buf:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|||
|
|
//* len:<3A><><EFBFBD>͵<EFBFBD><CDB5>ֽ<EFBFBD><D6BD><EFBFBD>(Ϊ<>˺ͱ<CBBA><CDB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>ƥ<EFBFBD><C6A5>,<2C><><EFBFBD>ィ<EFBFBD>鲻Ҫ<E9B2BB><D2AA><EFBFBD><EFBFBD>64<36><34><EFBFBD>ֽ<EFBFBD>)
|
|||
|
|
//**/
|
|||
|
|
////void USART2_Send_Data(u8 *buf,u16 len)
|
|||
|
|
////{
|
|||
|
|
//// u16 t;
|
|||
|
|
//// for(t=0;t<len;t++) //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// {
|
|||
|
|
//// while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
|
|||
|
|
//// USART_SendData(USART2,buf[t]);
|
|||
|
|
//// }
|
|||
|
|
//// while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
|
|||
|
|
////}
|
|||
|
|
///**
|
|||
|
|
//* <20><>Ҳ<EFBFBD><D2B2>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>պ<EFBFBD><D5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>main<69><6E><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//* USART2<54><32>ѯ<EFBFBD><D1AF><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//* buf:<3A><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>ַ
|
|||
|
|
//* len:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
|
//**/
|
|||
|
|
///*void USART2_Receive_Data(u8 *buf)
|
|||
|
|
//{
|
|||
|
|
// u8 rxlen=USART2_RX_CNT;
|
|||
|
|
// u8 i=0;
|
|||
|
|
// delay_ms(10); //<2F>ȴ<EFBFBD>10ms,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10msû<73>н<EFBFBD><D0BD>յ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ս<EFBFBD><D5BD><EFBFBD>
|
|||
|
|
// while(rxlen!=USART2_RX_CNT)
|
|||
|
|
// {
|
|||
|
|
// rxlen=USART2_RX_CNT;
|
|||
|
|
// delay_ms(10);
|
|||
|
|
// }
|
|||
|
|
// for(i=0;i<(USART2_RX_CNT);i++)
|
|||
|
|
// {
|
|||
|
|
// buf[i] = USART2_RX_BUF[i];
|
|||
|
|
// USART2_RX_BUF[i] = 0;
|
|||
|
|
// }
|
|||
|
|
// USART2_RX_CNT=0; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
//}*/
|
|||
|
|
|
|||
|
|
////void USART2_SendStr(USART_TypeDef* USARTx, uint8_t *PData,uint8_t Datalen)
|
|||
|
|
////{
|
|||
|
|
//// unsigned char i=0;
|
|||
|
|
//// for(;i< Datalen;i++)
|
|||
|
|
//// {
|
|||
|
|
//// USART_SendData(USARTx, *(PData+i));
|
|||
|
|
//// while (!USART_GetFlagStatus(USARTx,USART_FLAG_TC));
|
|||
|
|
//// }
|
|||
|
|
////}
|
|||
|
|
////
|
|||
|
|
////void USART2_SentByte(USART_TypeDef* USARTx, uint16_t Data)
|
|||
|
|
////{
|
|||
|
|
//// USART_SendData(USARTx, Data);
|
|||
|
|
//// while (!USART_GetFlagStatus(USARTx,USART_FLAG_TC));
|
|||
|
|
////}
|
|||
|
|
|
|||
|
|
////void USART2_IRQHandler(void)
|
|||
|
|
////{
|
|||
|
|
//// u8 res;
|
|||
|
|
//// if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// {
|
|||
|
|
//// res = USART_ReceiveData(USART2); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// PushQueue(&UART2RecQueue,res);
|
|||
|
|
//// //if(USART2_RX_STA==0)
|
|||
|
|
//// //{
|
|||
|
|
//// // USART2_RX_BUF[USART2_RX_CNT] = res; //<2F><>¼<EFBFBD><C2BC><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ֵ
|
|||
|
|
//// // //<2F><><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD>β<EFBFBD>յ<EFBFBD>0xA0<41><30>0xA1<41><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// // if(USART2_RX_BUF[USART2_RX_CNT-1]==0xA0&&USART2_RX_BUF[USART2_RX_CNT]==0xA1)
|
|||
|
|
//// // USART2_RX_STA=1;//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>
|
|||
|
|
//// // USART2_RX_CNT++; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
|||
|
|
//// //}
|
|||
|
|
//// }
|
|||
|
|
//// //<2F><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ȶ<EFBFBD>SR,<2C>ٶ<EFBFBD>DR<44>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵ<D0B6><CFB5><EFBFBD><EFBFBD><EFBFBD> 22.4.20
|
|||
|
|
//// //if(USART_GetFlagStatus(USART2,USART_FLAG_ORE) == SET)
|
|||
|
|
//// //{
|
|||
|
|
//// // USART_ReceiveData(USART2);
|
|||
|
|
//// // USART_ClearFlag(USART2,USART_FLAG_ORE);
|
|||
|
|
//// //}
|
|||
|
|
//// USART_ClearFlag(USART2,USART_IT_RXNE); //һ<><D2BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
////}
|
|||
|
|
|
|||
|
|
////2022.02.07 <20><><EFBFBD><EFBFBD>3<EFBFBD><33>ʼ<EFBFBD><CABC>
|
|||
|
|
////void USART3_Init(u32 baud)
|
|||
|
|
////{
|
|||
|
|
//// USART_InitTypeDef USART_InitStructure;
|
|||
|
|
//// NVIC_InitTypeDef NVIC_InitStructure;
|
|||
|
|
//// GPIO_InitTypeDef GPIO_InitStructure; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>GPIO
|
|||
|
|
//// //ʹ<>ܴ<EFBFBD><DCB4>ڵ<EFBFBD>RCCʱ<43><CAB1>
|
|||
|
|
//// RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB , ENABLE); //ʹ<><CAB9>UART3<54><33><EFBFBD><EFBFBD>GPIOB<4F><42>ʱ<EFBFBD><CAB1>
|
|||
|
|
//// RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
|||
|
|
////
|
|||
|
|
//// GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_10 | GPIO_Pin_11); //USART1<54><31>Ӧ<EFBFBD><D3A6>TX<54><58>RX,<2C><><EFBFBD><EFBFBD> PB6 PB7
|
|||
|
|
//// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //<2F><><EFBFBD><EFBFBD>ģʽ
|
|||
|
|
//// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|||
|
|
//// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
//// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|||
|
|
//// GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|||
|
|
//// //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>GPIO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// // Configure USART3 Rx (PB.11) as input floating
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
|||
|
|
//// //GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|||
|
|
////
|
|||
|
|
//// // Configure USART3 Tx (PB.10) as alternate function push-pull
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|||
|
|
//// //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
|||
|
|
//// //GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|||
|
|
//// //<2F><><EFBFBD>ø<EFBFBD><C3B8>ù<EFBFBD><C3B9><EFBFBD>
|
|||
|
|
//// GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_7);
|
|||
|
|
//// GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_7);
|
|||
|
|
////
|
|||
|
|
//// //<2F><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
|||
|
|
//// USART_InitStructure.USART_BaudRate = baud;
|
|||
|
|
//// 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 USART3
|
|||
|
|
////
|
|||
|
|
//// USART_Init(USART3, &USART_InitStructure);//<2F><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>3
|
|||
|
|
//// // Enable USART3 Receive interrupts ʹ<>ܴ<EFBFBD><DCB4>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|||
|
|
//// USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
|||
|
|
//// // Enable the USART3
|
|||
|
|
//// USART_Cmd(USART3, ENABLE);//ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>3
|
|||
|
|
////
|
|||
|
|
//// //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// //Configure the NVIC Preemption Priority Bits
|
|||
|
|
//// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
|||
|
|
////
|
|||
|
|
//// // Enable the USART3 Interrupt
|
|||
|
|
//// NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
|||
|
|
//// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
|
|||
|
|
//// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
|
|||
|
|
//// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|||
|
|
//// NVIC_Init(&NVIC_InitStructure);
|
|||
|
|
////
|
|||
|
|
////
|
|||
|
|
////
|
|||
|
|
////}
|
|||
|
|
|
|||
|
|
////void USART3_Sned_Char(u8 temp)
|
|||
|
|
////{
|
|||
|
|
//// USART_SendData(USART3,(u8)temp);
|
|||
|
|
//// while(USART_GetFlagStatus(USART3,USART_FLAG_TXE)==RESET);
|
|||
|
|
////}
|
|||
|
|
|
|||
|
|
////void USART3_Sned_Char_Buff(u8 buf[],u32 len)
|
|||
|
|
////{
|
|||
|
|
//// u32 i;
|
|||
|
|
//// for(i=0;i<len;i++)
|
|||
|
|
//// USART3_Sned_Char(buf[i]);
|
|||
|
|
////}
|
|||
|
|
|
|||
|
|
////void USART3_IRQHandler(void) //<2F><><EFBFBD><EFBFBD>3<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
////{
|
|||
|
|
//// u8 Res;
|
|||
|
|
//// if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
|
|||
|
|
//// {
|
|||
|
|
//// //USART3_RX_TIMEOUT=0;
|
|||
|
|
//// //USART3_RX_BUF[USART3_RX_CNT++] = USART_ReceiveData(USART3); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// Res = USART_ReceiveData(USART3);
|
|||
|
|
//// PushQueue(&UART3RecQueue,Res);
|
|||
|
|
//// }
|
|||
|
|
//// //<2F><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ȶ<EFBFBD>SR,<2C>ٶ<EFBFBD>DR<44>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵ<D0B6><CFB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//// if(USART_GetFlagStatus(USART3,USART_FLAG_ORE) == SET)
|
|||
|
|
//// {
|
|||
|
|
//// USART_ReceiveData(USART3);
|
|||
|
|
//// USART_ClearFlag(USART3,USART_FLAG_ORE);
|
|||
|
|
//// }
|
|||
|
|
//// USART_ClearITPendingBit(USART3, USART_IT_RXNE);
|
|||
|
|
////}
|
|||
|
|
//
|