ST AN3258 Application note

AN3258
Application note
STM8A/S HSI oscillator calibration
using LIN automatic resynchronization

Introduction

Local interconnect network (LIN) is a widely used standard for communication between various nodes present inside the electronic control unit (ECU) of a vehicle. LIN sync frame, which is defined by LIN standard, is used as a reference by the LIN slave nodes for clock synchronization. Using this technique, LIN slave nodes can calibrate the variable internal RC oscillator and use it as the system clock source. Therefore, the LIN slave node application can save the cost of using crystal or resonator oscillators.
This application note describes a method to calibrate the STM8A/S high-speed internal (HSI) oscillator using the LIN automatic resynchronization feature of the LINUART/UART1 peripheral. The calibration method is also provided with a software routine. It can be downloaded from www.st.com.
The user must be familiar with the LIN bus standard, STM8A/S microcontroller architecture, and the basics of C language. Detailed information about the STM8A/S microcontroller peripheral features, hardware registers, and electrical characteristics are available in the STM8A (RM0009) and STM8S (RM0016) reference manuals and the product datasheets.
October 2010 Doc ID 17825 Rev 1 1/16
www.st.com
Contents AN3258
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1 HSI calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1 HSI trimming bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 LIN automatic resynchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 HSI calibration method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4 HSI calibration routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5 LIN header error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.6 LIN divider update method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.7 LIN clock deviation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2/16 Doc ID 17825 Rev 1
AN3258 List of tables
List of tables
Table 1. CLK_HSITRIMR values and binary two’s complement representation. . . . . . . . . . . . . . . . . 6
Table 2. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Doc ID 17825 Rev 1 3/16
List of figures AN3258
List of figures
Figure 1. STM8A/S HSI trimming principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 2. LIN header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 3. LIN synch field measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 4. HSI calibration routine flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 5. LDIV read/write operations when LDUM = 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 6. LDIV read/write operations when LDUM = 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4/16 Doc ID 17825 Rev 1
AN3258 HSI calibration
RC OSCILLATOR
DECODER
CLK_HSITRIM
HSI Clock Output
+
INIT_TR IM

1 HSI calibration

1.1 HSI trimming bits

STM8A/S microcontrollers have an HSI oscillator with a nominal frequency (f which is factory calibrated at an ambient temperature (T (V
) of 5 V. The accuracy for overall temperature and voltage range is ±5 % (please refer to
CC
) of 25 °C and a supply voltage
A
) of 16 MHz
HSI
the device specific datasheet) which is sufficient for many applications. For a given voltage and temperature condition, the HSI oscillator frequency can be calibrated to ±1 % or ±0.5 % by using calibration bits as described below and in Figure 1.
After a device reset, the factory calibration value at T
= 25 °C and VCC = 5 V is
A
automatically loaded into the internal calibration register. The HSI frequency can be fine­tuned by writing the calibration bits present in the HSI clock calibration trimming register (CLK_HSITRIMR). The maximum number of calibration bits present is either three or four depending on the device. The calibration bits provide an additional trimming value which is added to the factory calibration value to fine-tune the HSI output frequency. The additional trimming value, written in the trimming bits, is interpreted as a signed value with two’s complement representation (see Tab l e 1 ). In the case of three trimming bits, this additional trimming value can vary from -4 (100b) to 3 (011b) and in the case of four trimming bits, this additional trimming value varies from -7 (1001b) to 7 (0111b). Thus, the additional trimming value can be added or subtracted to the factory calibration value. An increase in the trimming value causes a decrease in the HSI frequency. The frequency change per step is ±1 % or ±0.5 % depending on the device and number of trimming bits used (three or four). Some devices can use either three or four trimming bits which are programmable via the HSITRIM option byte.

Figure 1. STM8A/S HSI trimming principle

Doc ID 17825 Rev 1 5/16
Loading...
+ 11 hidden pages