About the configuration of usart1 serial port multiplexing A2 and A3 of stm8l05RB

Publisher:w2628203123Latest update time:2019-12-24 Source: eefocusKeywords:stm8l05RB  usart1  configuration Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#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 UART

/*

* 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);

}

Keywords:stm8l05RB  usart1  configuration Reference address:About the configuration of usart1 serial port multiplexing A2 and A3 of stm8l05RB

Previous article:Tutorial on using STM8L's own bootloader
Next article:STM8 ROP programming

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号