#include "uart1.h"
#include "stm8l15x.h"
void Uart1_Init(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_USART1,ENABLE);
SYSCFG_REMAPDeInit();
SYSCFG_REMAPPinConfig(REMAP_Pin_USART1TxRxPortA,ENABLE);
GPIO_Init(GPIOA, GPIO_Pin_2, GPIO_Mode_Out_PP_High_Fast);//TXD
GPIO_Init(GPIOA, GPIO_Pin_3, GPIO_Mode_In_PU_No_IT);//RXD
USART_DeInit(USART1); // Duplicate UART1
/*
* Configure UART1 as:
* Baud rate = 115200
* Data bits = 8
* 1 stop bit
* No check digit
* Enable receiving and sending
*/
USART_Init(USART1,(u32)115200, USART_WordLength_8b, USART_StopBits_1,
USART_Parity_No, USART_Mode_Tx|USART_Mode_Rx);
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //Enable receive interrupt
//USART_ITConfig(USART1, USART_IT_TC, ENABLE); //Enable receive interrupt
USART_Cmd(USART1, ENABLE); //Enable UART2
}
/*******************************************************************************
* Name: UART1_SendByte
* Function: UART1 sends a byte
* Parameters: data -> bytes to send
* Return: None
* Description: None
******************************************************************************/
void UART1_SendByte(u8 data)
{
USART_SendData8(USART1, data);
/* Wait for the transfer to complete */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
/*******************************************************************************
* Name: UART1_SendStr
* Function: UART1 sends len characters
* Parameter: data -> points to the string to be sent
* len -> number of bytes to send
* Return: None
* Description: None
******************************************************************************/
void UART1_SendStr(u8 *str)
{
while(*str != '')
{
UART1_SendByte(*str++); /* Loop call to send a character function*/
}
}
/*******************************************************************************
* Name: UART2_ReceiveByte
* Function: UART2 receives a character
* Parameters: None
* Return: received characters
* Description: None
******************************************************************************/
u8 UART1_ReceiveByte(void)
{
u8 UART1_RX_BUF;
/* Wait for receiving to complete */
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
UART1_RX_BUF = USART_ReceiveData8(USART1);
return UART1_RX_BUF;
}
/*******************************************************************************
* Name: fputc
* Function: Redirect C library function printf to UART1
* Parameters: None
* Return: the character to be printed
* Description: Called by printf
******************************************************************************/
#ifdef _IAR_
int fputc(int ch, FILE *f)
{
/* Send Printf content to the serial port*/
UART1_SendByte(ch);
return (ch);
}
#else
PUTCHAR_PROTOTYPE
{
/* Write a character to the UART1 */
UART1_SendByte(c);
return (c);
}
#endif
GETCHAR_PROTOTYPE
{
#ifdef _COSMIC_
char c = 0;
#else
int c = 0;
#endif
/* Loop until the Read data register flag is SET */
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
c = USART_ReceiveData8(USART1);
return (c);
}
Previous article:ST official library function GPIO port read and write function
Next article:IAR FOR STM8 study notes firmware library GPIO
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- [Evaluation of EC-01F-Kit, the EC-01F NB-IoT development board] Part 2: Manual connection and data publishing of MQTT
- Teach you step by step how to design CPLD/FPGA and MCU together
- In three minutes, you can understand the concept and classification of power amplifiers!
- Gate circuits: AND gate, OR gate, NOT gate circuits and examples
- 4 types of electrical energy conversion, let’s take a look
- Summary of the differences between SPMSM and IPMSM
- DSP system design - Why is the DSP with large on-chip RAM more efficient?
- What are the advantages and disadvantages of BMS controlling the positive end of the battery and controlling the negative end?
- A brief summary of the DQ axis in the FOC algorithm
- 【NUCLEO-WL55JC2 Review】——by nich20xx