I have recently been learning to develop STM8 MCU. I have just got this MCU and don’t know many of its functions well. I can only learn while developing. I will record the learning process. If there are any mistakes, please correct me.
MCU: STM8L151K4
Environment: IAR FOR STM8
Due to project requirements, the USART function needs to be debugged. At the beginning, there was no schematic diagram, only the board and datasheet. From the datesheet, I saw that the USART RX TX pins were PC2 PC3.
So I directly configured PC2 PC3 and then initialized it. However, when the code was running, I did not receive the data sent by the MCU. I checked the code and datasheet, and then searched for information online. I found that USART has a remappin function, which maps PC3 PC2 to PA2 PA3.
So I asked the hardware and confirmed that the USART hardware pins on the board were PA2 PA3, so I reconfigured the relevant code, remapped the pins, and tested it.
Although it wasted some time, I still gained something.
Some of the code is as follows:
#define USART_TX_PORT GPIOA
#define USART_RX_PORT GPIOA
#define USART_TX_PINS GPIO_Pin_2
#define USART_RX_PINS GPIO_Pin_3
void uart_gpio_init()
{
GPIO_Init(USART_TX_PORT,USART_TX_PINS, GPIO_Mode_Out_PP_Low_Fast);
GPIO_Init(USART_RX_PORT,USART_RX_PINS, GPIO_Mode_In_PU_No_IT);
}
void uart_init(void)
{
uart_gpio_init();
CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
//remapping
SYSCFG_REMAPPinConfig(REMAP_Pin_USART1TxRxPortA,ENABLE);
USART_DeInit(USART1);
/* UART1 configuration ------------------------------------------------------*/
/* UART1 configured as follow:
- USARTx = 1
- BaudRate = 9600baud
- USART_WordLength = 8 Bits
-One Stop Bit
- No parity
- Receive and transmit enabled
*/
USART_Init(USART1, (uint32_t)9600, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx));
USART_Cmd(USART1, ENABLE);
}
If the USART hardware is directly connected to PC2 PC3, there is no need for SYSCFG_REMAPPinConfig to remap.
Previous article:STM8 UART interrupt send, interrupt receive
Next article:STM8S interrupt system
- 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
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- MSP430F5438 study notes FLAHS operation
- Wiring diagram of Hall current sensor
- TI's microcontroller I8669/I44445 (MCU) MSP430
- SystemVerilog and Functional Verification
- MATLAB and FPGA Implementation of Digital Filters (2nd Edition)
- [NXP Rapid IoT Review] SWD debug line lead-out
- The domestically produced CSM32RV20 is a low-power MCU chip based on the RISC-V core
- [Raspberry Pi 4B Review] + OPENCV Simple License Plate Location
- ! ! We are looking for supply chain managers, purchasing engineers, and production managers! !
- How to use CCS 9.3.0 Offline Resource Manager