STM8L USART serial port debugging

Publisher:徽宗古泉Latest update time:2020-02-14 Source: eefocusKeywords:STM8L  USART Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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. 

Write the picture description here 

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. 

Write the picture description here 

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.

Keywords:STM8L  USART Reference address:STM8L USART serial port debugging

Previous article:STM8 UART interrupt send, interrupt receive
Next article:STM8S interrupt system

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号