Serial port printf output based on STM8L15x microcontroller

Here we took the STM8L15x series of microcontrollers to use the ADC internal reference voltage to measure the VDD voltage and write the voltage value to the window as an example. (The STM8L uses the ADC internal reference voltage channel to measure the VDD voltage.)

Usart.h header file:

#ifndef _usart_H

#define _usart_H

#include "stm8l15x.h"

Void Usart_Init(void);

#endif

Usart.c source files:

#include "usart.h"

Void Usart_Init(void)

{

CLK_PeripheralClockConfig (CLK_Peripheral_USART1,ENABLE); //Open the USART1 clock

USART_Init (USART1, 9600, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, USART_Mode_Tx); // USART initialization, baud rate 9600, 8-bit data length, 1 stop bit, no parity bit, transmission mode

USART_Cmd (USART1, ENABLE); // Enable USART1

}

#include "stm8l15x.h"

#include "adc.h"

#include "usart.h"

#include "stdio.h"

Int putchar(int data)

{

USART_SendData8(USART1,(u8)data); //send 8-bit data

While(!USART_GetFlagStatus (USART1,USART_FLAG_TXE));//waits to be sent

Return data;

}

Int main( void )

{

U16 adc1_value=0;

Float value=0;

Adc_Init();

Usart_Init();

While(1)

{

ADC_SoftwareStartConv(ADC1); //Start software conversion

While(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));//wait for conversion to end

ADC_ClearFlag(ADC1,ADC_FLAG_EOC) ;// Clear corresponding flag

Adc1_value=ADC_GetConversionValue(ADC1); //Get converted value

Value=1.225*4096/adc1_value; //unit V

Printf("ad=%fV",value);

}

}

IAR printf output and keil settings are not the same, first of course first include the header file "stdio.h", and then override the putchar function

Perform the following configuration in the IAR development environment:

(1) Right click on Demo-Debug and select opTIon

Serial port printf output based on STM8L15x microcontroller

(2) Change Library ConfiguraTIon to Full in OpTIons

Serial port printf output based on STM8L15x microcontroller

(3) Change the Printf formatter to Large in Library OpTIons

Serial port printf output based on STM8L15x microcontroller

(4) After completing the above settings, compile the entire project, and then download the program to the STM8L15x board and enter the Debug debugging environment. Click View-”Terminal I/O to bring up the virtual terminal, and then run it all, you can see in the Terminal window. To print information

Custom Molded Cables

We specialize in cable assembly overmolding. Our customized molded cables are built precisly following customers' spec.Experienced proposal can be offered to customers for evaluation by considering stable quality and competitive price.


Custom cable overmoldings improve the quality, look and functionality of many electrical cables. From battery interconnects and molded plugs to custom molded plugs and many other custom designed assemblies – ETOP is a premier custom cable overmolding supplier to OEMs.

we have internal design, prototype, and manufacturing the widest range of molded harnesses, also a diversified line of strain / flex reliefs and grommets.

Molded Cables,Stranded Round Molded Cables,Molded Patch Cord Cable,4 Pole Waterproof Molded Cable,Waterproof Connectors

ETOP WIREHARNESS LIMITED , https://www.oemwireharness.com