st7 microcontroller training - stmicroelectronics · st7 a/d converter overview (1) • 8-bit and...

119
ST7 MICROCONTROLLER TRAINING 1. INTRODUCTION 2. CORE 3. ADDRESSING MODES 4. ASSEMBLY TOOLCHAIN 5. STVD7 DEBUGGER 6. HARDWARE TOOLS 7. PERIPHERALS 8. ST-REALIZER II 9. C TOOLCHAINS

Upload: others

Post on 05-Oct-2020

18 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 MICROCONTROLLER TRAINING

1. INTRODUCTION2. CORE 3. ADDRESSING MODES4. ASSEMBLY TOOLCHAIN5. STVD7 DEBUGGER6. HARDWARE TOOLS7. PERIPHERALS8. ST-REALIZER II9. C TOOLCHAINS

Page 2: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

PURPOSE AND OBJECTIVES

• PurposeTo improve your knowledge on standard ST7 peripherals

• ObjectivesList the main features of most of standard ST7 peripheralsOptimize their use Develop an efficient code either in Assembly or C language using these peripheralsTo set up an application environment for a quick startDemonstrate peripherals performance using ST7 INDART demo board support

Page 3: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

ST7 I/O PORTS• Optional features:

EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 4: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 I/O PORTSOverview

• All the I/Os are individually software configurable using 3 different registers:

DDR: Data Direction RegisterDR: Data RegisterOR: Option Register

• ST72254: 22 multifunction bidirectional I/O lines14 Standard I/Os (sink up to 5mA)8 High Current I/Os (PA0-PA7 can sink up to 20mA)6 Analog Inputs (PC0-PC5)14 alternate Functions on 14 pins (for Timers, SPI and I2C)All the I/Os can be set-up as Interrupt inputs

Page 5: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 I/O PORTSafe I/O pin transition

01 00 10 11

Reset State

Mode ORDDR

Output Push-Pull 1 1

Output Open-Drain0 1

Input pull- up with/without interrupt 1 0

Floating input 0 0

Page 6: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 I/O PORT Basic structure

• Software selectable configuration • HIGH FLEXIBILITY for software and PC board layout

OuputI/OPin

Data Direction Register Bit

Latch Data Output bit

InputI/O

InputReg bit

Read / Write DDRi

Write DRi

Read DRi

Page 7: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 I/O PORT Settings & electrical behaviour

• Configuration given when no external Hardware isconnected to the pins

OuputPush-Pull

OuputOpen Drain

Input Pull_upInputFloating

101011XXRead DR

VddVssFloatingVssVddVddFloatingFloatingI/O Pin

10101010Written DR

11001100OR

11110000DDR

Page 8: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 EXTERNAL INTERRUPTS

Interrupt source

Pin 1

Pin 2

Pin N

Pin 1

Pin 2

Pin M

ST7 Interrupt Controller

Edge/level selection

Edge/level selection

Interrupt Source 1

Interrupt Source 2

Negative edge only

Positive edge only

Pin 1

Pin 2

Latched

Latched

Positive and Negative edge Latched

Negative edge and low level Not Latched

Interrupt generation

Miscellaneous Register

Positive edge and high level Not Latched

Page 9: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 I/O PORT Block Diagram

DR

DDR

OR

DA

TA B

US

PAD

VDD

ALTERNATEENABLE

ALTERNATEOUTPUT 1

0

OR SEL

DDR SEL

DR SEL

PULL-UPC ONDITION

P-BUF FER(see table below)

N-BUFFER

PULL-UP(see table below)

1

0

ANALOGINPUT

If implemented

ALTERNATEINPUT

VDD

DIODES(see table below)

FROMOT HERBITS

EXTERNAL

REQUEST (eix)INT ERRUPT

SENSITIVITYSELECTION

CMOS SC HMIT TTRIGGER

REGISTERACCESS

BIT

Fro m o n-chip periphe ral

To on-ch ip pe riph eral

Note: Refer to th e Port C onfig uratio nta ble for de vice spe cif ic informa ti on.

Comb ina ti ona lL ogi c

Page 10: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

PROGRAMMING TIPSI/O Port (1)

• AD convertionEach pin used by the ADC cell must be configured as floating input (i.e. without pull-up resistors) before activating the analog input mode (which is the usual default state)

• Alternate functionA signal coming from an on-chip peripheral can be output on a port. In this case, the I/O is automatically configured in output mode.A signal coming from an I/O can be an input to an on-chip peripheral. In this case, it must be configured as Input without interrupt (Floating Input).

Page 11: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

PROGRAMMING TIPSI/O Port (2)

• Open Drain Outputs can be used for bus driving where several devices are connected on the same line (to avoid conflicts: linescan be pulled low or in high impedance) . They can be wired together in parallel to increase current drive capability (I2C bus connections typically).

• Voltages driving an Analog Input should always stay within the absolute maximum ratings (Vss-0.3V to Vdd+0.3V)

• Pull-up resistors typically deliver 50µA under 5V

• The toggling time on any output pin will be approximately 30ns for a 50pF load

Page 12: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

I/O Ports Configuration Example

• Fill the dedicated I/O portregisters in order to have the following configuration:

• PB0:PB2Push-Pull Output (high level)

• PB3,PB4Floating Input

• PB5 Input with Interrupt

• PB6Push-Pull Output (low level)

• PB7Ouput (High Impedance)

PBDDR

PBDR

PBDR7 PBDRO

PBDDR7 PBDDRO

PBOR

PBOR7 PBORO

Page 13: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

I/O Ports Configuration Example

• Fill the dedicated I/O portregisters in order to have the following configuration:

• PB0:PB2 Push-Pull Output (high level)

• PB3,PB4 Floating Input

• PB5 Input with Interrupt

• PB6 Push-Pull Output (low level)

• PB7Ouput (High Impedance)

PBDR

PBDR7 PBDR0

PBOR

PBOR7 PBOR0

PBDDR

PBDDR7 PBDDR0

0 1 1 0 0 1 1 1

1 1 0 0 0 1 1 1

1 0 X X X 1 1 1

Page 14: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

Data Ram

Data EEprom

PCL

ST7 EEPROM Data• Optional features:

EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 15: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 EEPROMOverview

• Eeprom features:Used to store non volatile dataOn M5 devices, due to a multi-cycle write access, the EEPROM cannot use to execute code (time access: 1 cycle ½ instead of 1)On M6 devices (XFlash), code can be executed in EEPROM data.

• A parallel writing allows to program up to 32 bytes in a row

Write cycle = 5 msWrite Erase cycles = 300 000 cyclesData retention = 20 years

Page 16: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 EEPROM Block Diagram

E2ITE = 0 int disabled= 1 int enabled

E2LAT = 0 read mode= 1 write mode

E2PGM = 0 prog finished or not started= 1 start programming

BUS

BUFFER

ROWDECODER

32*8 BITSDATA LATCHES

DATAMULTIPLEXER

HIGH VOLTAGE PUMP

EEPROMMEMORYMATRIX

1 ROW = 32 * 8 BITS

ADDRESSDECODERADDRESS

BUS

DATA

E2ITE E2LAT E2PGM

EEPCR

RESERVED......

256 256

8

8

5

5

11

INTERRUPTREQUEST

FALLINGEDGE

DETECTOR

Page 17: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

EEPROM Programming Cycle

Write ofdata

latches

INTERNAL PROGRAMMING VOLTAGE

E2PGM

E2LAT

Read operation not possible Read operation allowed

Tprog

INTERRUPT REQUEST

Interrupt vector fetch

Erase cycle Write cycle

Page 18: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

PROGRAMMING TIPSEEPROM

• A write is done by programming the e2prom control register:Step 1: set E2LAT bit in order to select the write modeStep 2: write up to 32 bytes with 11 MSbits in commonStep 3: set E2PGM bit to start the programming cycleStep 4: wait for E2PGM reset ie end of the programming cycle

• A read is performed as if it was a read only memory: no software overhead required !

• The halt instruction or a reset immediatly stop any eepromoperation. The wait mode has no effect

Page 19: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 EEPROM Programming mode

• To read any memory location, E2LAT must be cleared• To program EEPROM :

BSET EEPCR, #E2LAT ; Set E2LAT bitLD VARIABLE_i, A ; Write to up to 32 locations with... ; the same 11 address MSB

; BSET EEPCR, #E2ITE ; Enable interrupts if neededBSET EEPCR, #E2PGM ; Start programming

.waitBTJT EEPCR, #E2PGM, wait ; Wait for end of write cycle

Page 20: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 A/D CONVERTER

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 21: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 A/D CONVERTEROverview (1)

• 8-Bit and 10-Bit ADC depending on the device:8-Bit on ST72254, ST72334, ST7Lite010-Bit on ST7Lite2, ST7Lite3, ST7Lite1B, ST7UltraliteS, ST72264, ST72344, ST72521,ST7262

• Conversion based on successive approximations with sample and hold circuitry

• Up to 16 analog channels

• Conversion time at max ADC frequency (fADC=4MHz):8-bit → 3µs10-Bit → 3.5µs or 7.5µs (but for Fadc max = 2MHz) depending on the devices

• Integrated op-amp for a zoom function (Lite family):Gain: 8Range: [0-250mV] or [0-430mv] depending on devices

Page 22: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 A/D CONVERTEROverview (2)

• ADON bit (ADC on/off bit) allows to reduce power consumption.

• EOC or COCO bit indicates to the MCU that the conversion is completed

• Special features:x8 Amplifier for zooming (ST7Lite family)End of conversion interrupt generation (ST7Hub)AverageSpeed adjustmentOne shot mode (ST7262)

Page 23: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 AD CONVERTEROverview (3)

• ADC vs. low consumption modesWait mode doesn't affect the ADCHalt mode stops the ADC

• Conversion results vs. analog input voltageConversion is linearIf analog voltage input > VREF:converted result = FFh (no overflow indication)If analog voltage input < VSS:converted result = 00h (no underflow indication)

• Two voltage reference configuration:VREF and VSSA available:

0.7xVDD < VREF < 5.5V with decoupling capacitors.VREF and VSSA pins not available:

connection done internally to VDD and VSS

Page 24: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 A/D CONVERTERBlock diagram

SAMPLEx1/2/4

MUX

AIN0AIN1

AIN15AIN16

(Control Status Register) CSR

(Data Register High) DR

&HOLD

ANALOG TODIGITAL CONVERTER

AD9 AD2AD3AD4AD5AD8 AD7 AD6

SlowEOC CH0CH1CH2Speed ADON CH3

AD0AD1

(Data Register Low) DR

Fadc Fcpu

Page 25: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 A/D CONVERTERPROGRAMMING TIPS

• Procedure:Step 1: Configure the pin to be used as the analog input in input floating mode (no pull-up, no interrupt )Step 2: Select the channel to be converted using the bits CH[3:0] in CSR register and set the ADON bitStep 3: Wait until COCO or EOC bit is set. A continuous conversion is performed .Step 4: Read the ADC data registers.

• To reach the best accuracy, the impedance seen by the analog input pin must be lower than 10Kohm.

Page 26: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 A/D CONVERTERADC TYPE VS. DEVICE

MCU

ADCST7Lite0 ST7Lite2 ST7F264 ST7F324 ST7F521

ADCTYPE 8-Bit 10-Bit 10-Bit 10-Bit

±4

8

10-Bit

ERROR(LSB) ±2 ±4 ±4 ±4

NB.INPUTS 5 7 6 16

Page 27: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 A/D CONVERTERSUMMARY

• Which are the two types of ST7 ADC?8-Bit & 10-Bit

• What is the configuration of the analog input pin?The pin used as an analog input must be configured in input

floating mode (no pull-up, no interrupt).

• Which bit indicates the completion of the conversion?The EOC or COCO bit. It is set by hardware and cleared by

software.

• What is the conversion time of the 10-Bit ADC?The conversion time is 7.5µs at fADC=2MHz for some devices and

3.5µs for some others at fADC=4MHz.

Page 28: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ADC Configuration Example

• Fill ADCCSR register in order to have an analog conversion on AIN4 with fCPU/2 (Refer to ST7Lite0 datasheet).

ADCCSR

EOC SPEED ADON CH3 CH2 CH1 CH0

Page 29: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ADC Configuration Example

• Fill ADCCSR register in order to have an analog conversion on AIN4 with fCPU/2 (Refer to ST7Lite0 datasheet).

COCO ADON CH3 CH2 CH1 CH0

ADCDR To be tested 0 1 0 0 1 0 0

Page 30: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

• PurposeBe familiar with the ADC peripheral manipulation

• ObjectivesStep 1: Convert the analog input PB3 and display the conversion result on PA[0:4] and PB[0:2] with PA LSB and PB MSB.

Step 2: Convert the analog input PB3 and display it as follows:0V < Vin < 1.5V → LED on PB0 is ON1.5V < Vin < 3.5V → LED on PB1 is ON3.5V < Vin < 5V → LED on PB2 is ON

Refer to: Training Manual: Exercise 4 – P.26/30

Exercise N°4ADC

1 H

Page 31: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 ANALOG COMPARATOR

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 32: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 Analog comparator

• Features (lite1b device):External and internal reference voltage (1.2V fixed internalbandgap or 16 voltage levels between 3.2V and 0.2V with a 0.2V step)Output available externally or possibility to connect it internallyto the break function of the 12-bit ARTimerCOMPIN+ is also connected to AIN0 and COMPIN- to AIN4If COMPIN+ < COMPIN- then COMPOUT=0If COMPIN+ > COMPIN- then COMPOUT=1Stabilization time of 500nsCINV bit to invert comparator output (COMPOUT)Dedicated interrupt on output change

Page 33: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SCI

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 34: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SCI - New features

• Division by 2 has been removed from Rx and Tx formula on new devices

• New features: parity control and reduced power consumption mode

New devices(X and HD flash) Other devicesST7226x ST72311ST7232x ST72511ST72521 ST72532ST7262 ST72334ST7263B ST72314ST7234x ST72124

ST72589ST72389ST7263ST7285ST72171ST72121ST72331

Page 35: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SCIOverview (1)

• Full duplex, asynchronous communication, 2 pins (RDI / TDO)

• Dual baud rate generator (maximum speed for SCI TX and RX: 500kHz or 500000 bauds)

• Programmable word length8 bits9 bits

• Noise, overrun and frame error detection• Parity control (new devices only!)• Reduced power consumption mode (new devices only!)

FcpuFtx = [16 × PR ] × TRFcpuFrx = [16 × PR ] × RR

Page 36: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SCIOverview (2)

• Muting functions for multiprocessor configurations

• Receiver wake function by the most significant bit or idle line

• 6 Interrupt sources with flagsTransmit data register emptyTransmission completeReceived data ready to be readOverrun error detectedParity error (new devices only!)

• 2 Flags without interruptNoise flagFraming error

Page 37: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SCI - Serial data format

Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7

Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Bit 8

Idle frame

Break frame

Idle frame

Break frame

Data frame

Data frame

Start Stop

Start Stop

Extra ‘1’

Extra ‘1’

• 8-bit word length

• 9-bit word length

Possible parity

bit

Possible parity

bit

Page 38: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Bit Time

Sampling Time

SCI Sampling Data Format

• Each bit time is Divided by 16 by the SCI clockSampled 3 times on the 8th, 9th and 10th count of the SCI clock

• NF flag is set if the 3 sampling are not equal but the reception is still available

0111111110111011010011011

10010

1000100000

DataSampled values

Receivedbit value

NF Flag

Page 39: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Transmit data register

Transmit shift register

Receive data register

Receive shift register

Transmit Control

Wake-Up Unit

ReceiveControl

Control Register 2

Status Register

SCI InterruptControl

Transmit rate Control

Receive rate Control

fcpu/ PR/ 16/ 2

Control register 1

RDI pin

TDO pin

Data Register

SCI Block Diagram

Removed on new devices

Page 40: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SCI Clock selection

TRANSMITTERCLOCK

RECEIVER CLOCK

ETPR

ERPR

EXTENDED PRESCALER RECEIVER RATE CONTROL

EXTENDED PRESCALER TRANSMITTER RATE CONTROL

EXTENDED PRESCALER

RECEIVER RATE

TRANSMITTER RATE

BRR

f CPU

CONTROL

CONTROL

SCP1 SCP0 SCT2 SCT1 SCT0 SCR2 SCR1 SCR0

/2 /PR/16

CONVENTIONAL BAUD RATE GENERATOR

EXTENDED RECEIVER PRESCALER REGISTER

EXTENDED TRANSMITTER PRESCALER REGISTER

Removed on new devices

Page 41: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SCI Configurable Baud Rate (1/2)• New devices

Conventional Baud Rate Generation

Extended Baud Rate Generation

• Others devicesConventional Baud Rate Generation

Extended Baud Rate Generation

FcpuFtx = [16 × PR ] × TRFcpuFrx = [16 × PR ] × RR

FcpuFtx = [16 × PR × 2 ] × TRFcpuFrx = [16 × PR × 2 ] × RR

FcpuFtx = [16 × PR ] × TR × ETPRFcpuFrx = [16 × PR ] × RR × ERPR

FcpuFtx = 16 × ETPRFcpuFrx = 16 × ERPR

Page 42: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SCI Configurable Baud Rate (2/2)• New devices

Values given for fCPU =8MHz

• Other devices

Values given for fCPU =8MHz

TR - SCT2:SCT0 PR - SCP1,SCP0 ETPR Baud rate64 - 110 13 - 11 0 30016 - 100 13 - 11 0 12008 - 011 13 - 11 0 24004 - 010 13 - 11 0 48002 - 001 13 - 11 0 96001 - 000 13 - 11 0 19200

X X 13 38400X X 9 57600

TR - SCT2:SCT0 PR - SCP1,SCP0 ETPR Baud rate64 - 110 13 - 11 0 60016 - 100 13 - 11 0 24008 - 011 13 - 11 0 48004 - 010 13 - 11 0 96002 - 001 13 - 11 0 192001 - 000 13 - 11 0 38400

1 1 13 384001 1 9 57600

Page 43: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SCI Configuration Example

• Fill the SCI registers in order to configure the SCI cell in8 Bit word reception at 9600 Bauds8 bit word transmission at 1200 BaudsInterrupt generation when RDRF is set (reception flag)

• fCPU = 8MHz

SCICR1

R8 T8 M WAKE

SCICR2

TIE TCIE RIE ILIE TE RE RWU SBK

SCIBRR

SCP1 SCP0 SCT2 SCT1 SCT0 SCR2 SCR1 SCR0

Page 44: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

• Fill the SCI registers in order to configure the SCI cell in 8 Bit word reception at 9600 Bauds8 bit word transmission at 1200 BaudsInterrupt generation when RDRF is set (reception flag)

• fCPU = 8MHz

R8 T8 SCID M WAKE PCE PS PIE

SCICR1 X X X 0 0 1 1 0TIE TCIE RIE ILIE TE RE RWU SBK

SCICR2 0 0 1 0 1 1 0 0SCP1 SCP0 SCT2 SCT1 SCT0 SCR2 SCR1 SCR0

SCIBRR 1 1 1 0 1 0 1 0

SCI Configuration Example

Page 45: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Serial Peripheral Interface

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 46: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SPIOverview (1/2)

• The SPI cell allows a full duplex synchronous serial communication between 2 devices

• Main features:Full duplex, 3 wire synchronous transfersMaster: 6 frequency available. It rates up to 2 MHzSlave mode: it rates up 4 MHz/SS (Slave Select) also configurable through software(MISCR2 or SPICSR on Xflash and HDFlash devices)

• The clock is programmable: polarity and phase

Page 47: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SPIOverview (2/2)

• 3 Interrupt sources with flagsData transfer: data transfer completedOverrun error: SPIF bit has not be cleared (new devices only!)Fault flag: fault in master mode detected

• 1 Flag without interruptWrite collision: access to SPIDR during a transmission

Page 48: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SPIMaster-Slave communication

SPI Clock Generator

8-bit Shift Register 8-bit Shift Register

Master SlaveMISO

MOSI

SCK

MISO

MOSI

SCK

SS SS5V

Page 49: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SPISTATE CONTROL

Read Buffer

8-Bit Shift Register

Write

Read Internal Bus

SPIE SPE SPR2- MSTR CPHA SPR0SPR1CPOL

SPIF WCOL MODFMOSI

MISO

SS

SCK

- - - - -

ITrequest

SERIAL CLOCK GENERATOR

MASTER CONTROLMISCR2

SPISR

SPIDR

SPIOD SSM SSI

SPICR

ST7 SPIBlock diagram

Page 50: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 SPISingle master configuration

MISO

MOSI

MOSI

MOSI MOSI MOSIMISO MISO MISOMISO

SS

SS SS SS SSSCK SCKSCKSCK

SCK

5V Po

rts

SlaveMCU

SlaveMCU

SlaveMCU

SlaveMCU

MasterMCU

Page 51: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SPI Configuration Example

• Fill the SPICR register in order to configure the SPI cell inMaster modeSerial clock at 5OOKHz (fCPU=8MHz)Sampling on 2nd edgeHigh level after clock signalNo interrupt generation

SPICR

SPIE SPE SPR2 MSTR CPOL CPHA SPR1 SPRO

Page 52: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SPI Configuration Example

• Fill the SPICR register in order to configure the SPI cell in Master modeSerial clock at 5OOKHz (fCPU=8MHz)Sampling on 2nd edgeHigh level after clock signalNo interrupt generation

SPIE SPE SPR2 MSTR CPOL CPHA SPR1 SPR0

SPICR 0 1 0 1 1 1 0 1

Page 53: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 I2C

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 54: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 I2C Overview

• The I2C cell provides all I2C bus specific sequencing, protocol,arbitration and timing in order to reduce as much as possible the software overhead

• Polling Management or Interrupt Driven Cell

• Main features:Multi Master capabilityInterrupt generationStandard I2C mode (up to 100kHz) and Fast I2C mode (up to 400kHz)7-bit and 10-bit addressing

Page 55: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

I2C Bus Protocol

SCL

SDA

1 2 8 9

MSB ACK

STOP STARTCONDITIONCONDITION

Page 56: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

I2C Master ModeTransfer Sequencing

S Address A DATA1 A DATA2 A DATA n A PEV5 EV6 EV8 EV8 EV8 EV8

7-bit Master Transmitter

7-bit Master ReceiverS Address A DATA1 A DATA2 A DATA n NA P

EV5 EV6 EV7 EV7 EV7

EV5: EVF=1, SB=1, cleared by reading SR1 register followed by writing DR register.EV6: EVF=1, cleared by reading SR1 register followed by writing CR register (for example PE=1).EV7: EVF=1, BTF=1, cleared by reading SR1 register followed by reading DR register.EV8: EVF=1, BTF=1, cleared by reading SR1 register followed by writing DR register.

Send by the master

Send by the slave

Page 57: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

I2C Slave ModeTransfer Sequencing

EV1: EVF=1, ADSL=1, cleared by reading SR1 register.EV2: EVF=1, BTF=1, cleared by reading SR1 register followed by reading DR register.EV3: EVF=1, BTF=1, cleared by reading SR1 register followed by writing DR register.EV4: EVF=1, STOPF=1, cleared by reading SR2 register.

S Address A DATA1 A DATA2 A DATA n A PEV1 EV2 EV2 EV2 EV4

S Address A DATA1 A DATA2 A DATA n NA PEV1 EV3 EV3 EV3 EV3 EV4

7-bit Slave Transmitter

7-bit Slave Receiver

Send by the master

Send by the slave

Page 58: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

FcpuFscl =

(2x[CC6..CC0]+2)FcpuFscl=

(3x[CC6..CC0]+2)

Standard Mode Fast Mode

FM/SM CC6 CC5 CC4 CC3 CC2 CC1 CC0

FM/SM :Fast / standard I2C mode0: Standard I2C mode1: Fast I2C mode

CC6-CC0 : 7bit clock divider

I2C CLOCK CONTROL REGISTER (CCR)

I2C Clock Control

Page 59: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 I2C Block Diagram

INTERRUPT

DATA REGISTER (DR)

DATA SHIFT REGISTER

COMPARATOR

OWN ADDRESS REGISTER 1 (OAR1)

CLOCK CONTROL REGISTER (CCR)

STATUS REGISTER 1 (SR1)

CONTROL REGISTER (CR)

CONTROL LOGIC

STATUS REGISTER 2 (SR2)

CLOCK CONTROL

DATA CONTROL

SCL

SDA

OWN ADDRESS REGISTER 2 (OAR2)

Page 60: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 16-bit TIMER

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptControlle

rData Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 61: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMEROverview (1)

• 16-bit free running counter driven by a software configurable prescaler

• 4 different modes:Input capture (2 pins): to latch the value of the counter after a transition on the ICAPi pin Output compare (2 pins): to control an output waveform or to indicate when a period of time is overOne pulse: generation of a pulse when an external event occursPWM: generation of a signal with frequency and pulse length set by software (OCR1 and OCR2)

Page 62: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMEROverview (2)

• The timer clock can be provided by:The internal clock with a configurable ratioAn external source: Fext must 4 times slower than the internal clock (ie Fmax=2Mhz)

External11

Fcpu/801

Fcpu/210

Fcpu/400

CC1 CC0 Timer clock

Page 63: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMERBlock diagram

TIMER INTERNAL INTERRUPT

ST7 INTERNAL BUS

MCU-PERIPHERAL INTERFACE

16-BIT FREERUNNINGCOUNTERCOUNTER

ALTERNATEREGISTER

OVERFLOWDETECTCIRCUIT

STATUS REGISTER

LOW

BYT

E 8

16

8-BITBUFFER

16-Bit INTERNAL TIMER BUS

ICF1 OCF1 TOF OCF2 0 0 0ICF2

16

ICAP1

LOW

BYT

E

HIG

H B

YTE

16

LOW

BYT

E

HIG

H B

YTE

LOW

BYT

E

HIG

H B

YTE

LOW

BYT

E

HIG

H B

YTE

OUTPUTCOMPARE

REGISTER 1

OUTPUTCOMPARE

REGISTER 2

INPUTCAPTURE

REGISTER 1

INPUTCAPTURE

REGISTER 2

OUTPUTCOMPARE CIRCUIT

1/21/41/8

EDGEDETECT

CIRCUIT 1ICAP2

EDGEDETECT

CIRCUIT 2

LATCH 1

LATCH 2

ICIE OCIE TOIE IEDG1 OLVL2FOLV1FOLV2 OLVL2 OC1E OC2E OPM IEDG2 EXEDGCC1PWM CC0

CC1 CC0

EXCLK

OCMP1

OCMP2

CONTROL REGISTER 1 CONTROL REGISTER 2

CPU CLOCK EXEDG

Page 64: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMERInput capture (1)

• Captures the counter value upon input signal edge detection

• Allows an external pulse length measurement • Internal safety process in case of critical interrupts

timing

Edge Detector

Timer Counter Register

Input Capture RegisterICAP1A

Software MaskableInterrupt Request

Page 65: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMERInput capture (1)

CC0CC1 IEDG216-BIT FREE RUNNINGCOUNTER

ICIE IEDG1

(Control Register 1) CR1

(Control Register 2) CR2

(Status Register) SR

ICAP1

ICAP2 EDGE DETECTCIRCUIT2

16-BIT

IC1RIC2R

EDGE DETECTCIRCUIT1

ICF2ICF1 000

Page 66: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMEROutput compare (1)

• Event generation (Interrupt request/bit toggling) whenever the compare register matches the counter

• Indicates a period of time has elapsed and controls an output waveform

• Internal safety process in case of critical interrupts timing

Match? Software Maskable Interrupt RequestPulse generation

Timer Counter Register

Output Compare Register

Page 67: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMEROutput compare (2)

(Status Register) SR

OUTPUT COMPARE

16-bit

CIRCUIT

OC1R

16-BIT FREE RUNNINGCOUNTER OC1E CC0CC1OC2E

OLVL1OLVL2OCIE

(Control Register 1) CR1

(Control Register 2) CR2

000OCF2OCF1

16-bit

16-bit

OCMP1

OCMP2

Latch1

Latch2

OC2R

Page 68: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMERReal Time Clock

• In each Interrupt Routine the OCR Register content is updated.

• There is no shift time (the counter is never reset externally).

time

FREE RUNNING COUNTER VALUE

Timer IT

FFFFh

0000h

OCR

OCR+∆T

Timer IT

Page 69: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMEROne pulse mode (1)

• Generation of a pulse synchronized with an external event

• Allows Phase Locked Loop Generation

• On Input Capture eventThe counter is resetThe timer output pin is toggled

• On Output compare eventThe timer output pin is toggledThe timer waits for the next Input Capture event

Page 70: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMEROne pulse mode (2)

When a external event occurs on ICAP1 pin

When the free running counter reaches

OC1R register value

OLVL1 bit level is applied on the OCMP1 pin

Free running counter is initialized to FFFCh

OLVL2 bit level is applied on the OCMP1 pin

I CF1 bit is set

Page 71: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMEROne pulse mode (3)

FFFFh

Compare 1

OCMP1 Ouput Compare pinTimer output

0000h

FFFCh

ICAP1Input Capture pinTimer input

FREE RUNNING COUNTER VALUE

time

time

time

Page 72: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

16-bit TIMERPWM mode (1)

• Automatic generation of a Pulse Width Modulated signal

• Period & pulse length set by software: The first Output Compare Register OC1R contains the length of the pulseThe second Output Compare Register OCR2 contains the period of the pulse

• Resolution up to 100 steps at 20 KHz (fCPU =4 MHz): 1% of accuracy on the duty cycle

Page 73: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 TIMERPWM mode (2)

When the free running counter reaches

OC2R register value

When the free running counter reaches

OC1R register value

Free running counter is initialized to FFFCh

OLVL2 bit level is applied on the OCMP1 pin

ICF1 bit is set

OLVL1 bit level is applied on the OCMP1 pin

Page 74: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 TIMERPWM mode (3)

OCMP1Ouput Compare pinTimer output

FFFFh

Compare 1

0000h

Compare 2FFFCh

Ttimer × 65535Tmax =

OLVL1=0

OLVL2= 1

FREE RUNNING COUNTER VALUE

time

time

Page 75: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

PROGRAMMING TIPS16-bit timer (1)

• Define Input capture pins as inputs through the corresponding Data Direction Register

• Read MSB first and then the LSBThe counter LSB is buffered during the MSB readThe counter LSB read accesses the buffered valueAny access to the high byte disables the corresponding timer function until the low byte is accessedDisable the interrupts during any word access

• Writing the counter LSB resets the timer at FFFChAny write access is valid (CLR TACLR or LD TACLR,A)

Page 76: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

PROGRAMMING TIPS16-bit timer (2)

• Clearing a status bit is performed by a read access to the status register followed by an access (read or write) to the low byte of the corresponding register

• The alternate counter register is always matching the counter

• Use the alternate counter register when you do not want to clearthe Timer Overflow Flag

• No interrupt is generated on compare when the PWM is active, but the ICF1 bit is set every period and can generates an interrupt

• Be aware that the implicit reading performed by the emulator might clear the status flags

Page 77: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

PROGRAMMING TIPS16-bit timer (3)

Reset counter to FFFCh

Reset counter to FFFChWrite

CLR

ACLR

Clear TOF bit

ACLR

ReadCLR bufferedCHR

Any others Instructions

Read

ACLR bufferedACHR

Returns the CLR buffered value CLR Clear TOF bit

Returns the ACLR buffered value

Page 78: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Timer Configuration Example

• Fill the Timer registers in order to generate a real time clock at 5ms using an interrupt strategy & a timer clock at 1µs(fCPU = 8MHz).

An interrupt is generated every 5ms using Output compare1. OCMP1 Pin has to be toggled every period

• What is the value to add to the TAOC1HR & TAOC1LR every period?

TACR1

ICIE OCIE TOIE FOLVL2 FOLVL1 OLVL2 IEDG1 OLVL1

TACR2

OC1E OC2E OPM PWM CC1 CC0 IEDG2 EXED

Page 79: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Timer Configuration Example

• Fill the Timer registers in order to generate a real time clock at 5ms using an interrupt strategy & a timer clock at 1µs (fCPU = 8MHz).

An interrupt is generated every 5ms using Output compare1. OCMP1 pin has to be toggled every period

• What is the value to add to the TAOCIHR & TAOC1LR every period? 5ms/1µs =5000 => 0x13 88

ICIE OCIE TOIE FOLVL2 FOLVL1 OLVL2 IEDG1 OLVL1

TACR1 0 1 0 0 0 0 0 1OC1E OC2E OPM PWM CC1 CC0 IEDG2 EXED

TACR2 1 0 0 0 1 0 0 0

Page 80: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

Lite Timers

Optional

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 81: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Lite Timers Overview• LT (Lite0,Ultralite):

1 free running 8-bit (Lite0) or 13-bit upcounter (Ultralite): 1 1ms and 2ms timebase period (@Fosc=8MHz, overflow whenthe counter reaches $F9)Maskable timebase interruptInput capture with dedicated interrupt (wake up from Haltcapability)Watchdog: 2ms timeout @Fosc=8MHz, 1 bit to set (WDGD) to avoid a reset. WDG reset can be forced by setting WDGRF bit. WDG is enabled through WDGE (software WDG) or through option byte (hardware WDG).

• LT2 (Lite1b,Lite2,Lite3):2 free running 8-bit upcounters: 1 with 1ms and 2ms timebaseand the other with programmable timebase period from 4µs to 1.024ms in steps of 4µs (@Fosc=8MHz)2 maskable timebase interruptsInput capture with dedicated interrupt (wake up from Haltcapability)

Page 82: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

8-bit Auto Reload Timer

Optional

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 83: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Overview8-bit ARTimer

• Programmable Timer frequency (Fcounter)

• External Clock / counter event capability

• Up to 4 independant PWM signals (same frequency)

• Output compare and timebase Interrupts

• Up to 2 Input capture Channels with Interrupts

• Timer implemented on ST72171, ST72511R, ST72311R, ST72F521,ST7FLITE0,ST7FLITEUS

Page 84: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

8-bit ARTimerFcounter definition

• Finput could be Fcpu or Fext.

• Fext Max = Fcpu/2.

• The Counter is incremented on rising edge of Finput.

• Fcounter is a division of Finput, acccording the prescaler driven by the CC2-CC0 bits of the Control Register.

11162.5KHZFinput /128

011125KHZFinput /64

101250KHzFinput /32

001500KHzFinput /16

1001MHzFinput /8

0102MHzFinput /4

1004MHzFinput /2

0008MHzFinput

Fcounter Finput= 8MHz

CC1CC2 CC0

Page 85: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

DCRxDuty Cycle Register

ARRAuto Reload Register

00

FF

Time

Counter value

Time

PWMx Output Pin

OEx bit=1OPx bit=1

OVF is set, Interrupt generationif OIE bit is set

8-bit ARTimerAutoreload & PWM Ouputs

High LevelFFh1pulse = TcounterARR

Low LevelARR-1DCRx Value PWMx Pin (OPx=1)

Page 86: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

8-bit ARTimerInput Capture

xxh 04h

Counter Register

Fcounter

CSx bit=1ARTICx Pin

Input Capture x PinICRx

Input Capture x Register

CFx bit is setInterrupt generation

if CIEx bit is set

01h 02h 03h 04h 05h 06h 07h

Page 87: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

8-bit ARTimerProgramming Tips

• Clearing the OVF(Overflow) bit is performed by reading the CSR register.

• Clearing the CFx (Capture Flag X) bit is performed by reading the ICRx register.

• In HALT mode, the Input capture Interrupt can be used to wake up the ST7.

• In HALT mode, the Overflow Interrupt can be used to wake up the ST7, if the external clock (Fext) is used. (external event detector mode).

• Be aware that the implicit reading performed by the emulator might clear the status flags.

Page 88: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

Data Ram

Data EEprom

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

PCL

12-bit Auto Reload Timers

Optional

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 89: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Overview (1/2) 12-bit ARTimers

• AT (lite0,ultralite):No external pins, clock is Fcpu or comes from Lite timerMaskable overflow interruptPWM signal generator (programmable duty cycle, polarity control, maskable compare interrupt, freq range 2kHz-4MHz at Fcpu=8MHz)Output compare function

• AT2 (lite2):6 external pins4 independent PWM outputs: BREAK pin (force a break condition on PWM outputs) programmable duty cycle and output mode, polarity control, maskable compare interrupt, freq range 2kHz-4MHz at Fcpu=8MHz)12-bit Input Capture function (ATIC pin): rising and falling edgeMaskable IC and overflow interruptsOutput compare function

Page 90: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Overview (2/2) 12-bit ARTimers

• AT3: Dual Auto reload timer (lite3, lite1b)6 external pins1 or 2 12-bit upcounters!4 independent PWM outputs: BREAK pin (force a break condition on PWM outputs) programmable duty cycle and output mode, polarity control, maskable compare interrupt, freq range 2kHz-4MHz at Fcpu=8MHz), Dead time generation (for Half Bridge drivingmode)12-bit Input Capture function (ATIC or LTIC pin): rising and fallingedge, long range input capture feature (Lite timer clock feds ART timer, signal on LTIC: 20-bit cascaded)Maskable IC and overflow interruptsOutput Compare function

Page 91: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

Data Ram

Data EEprom

PCL

SPGA Software Programmable Gain Amplifier

• Optional features:EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 92: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Software Programable Gain AmplifierOVERVIEW

• Integrated RAIL to RAIL OpAmp

• Internal low programmable Gain (Up to 16)

• Integrated reference voltage sources, VCC dependent & independent (Band-Gap).

• OpAmp Outputs internally connected to ADC input

• Interupt flag in comparator mode

• Power on/off bit & active in low power modes

• DAC capability with PWM/ART output

Page 93: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SPGABlock Diagram

Analog (Amplifier ) or digital (Comparator) output

Reference voltages:*1.2V, Vcc independant*8 steps, VCC dependant

SPGA1

OA1O

OA1NIN

OA1

R=2K

15R /16R

R

AV CL =1, 2, 4, 8, 16, ∞

R3=2K

OA1V

AGND

OA1PIN

NS1[2:0] bits

AZ1 bit

G1[2:0] bits

VR1E, PS1[1:0] bits

VR1[2:0] bitsx V

DDA/8

OA1Interrupt

OA1IE bit

bit8-Step Reference

Voltage 1

Band GapReferenceVoltage(1.2V)

Programmable gain Op-Amp

To ADC Channel 8

Page 94: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SPGA MODES (1)OA1NIN

OA1

R=2K

16R

R

AVCL =1, 2, 4, 8, 16, ∞

R3=2K

OA1V

AGND

OA1O

OA1PIN

NS1[2:0] bits

AZ1 bit

G1[2:0] bits

VR1E, PS1[1:0] bits

VR1[2:0] bitsx VDDA /8

OA1Interrupt

OA1IE bit

bit8-Step Reference

Voltage 1(1.2V)

Band GapReferenceVoltage

OA1NIN

OA1

R=2K

15R /16R

R

AVCL =1, 2 , 4, 8, 16, ∞

R3=2K

OA1V

(1.2V)

AGND

OA1O

OA1PIN

To ADC Channel 8

NS1[2:0] bits

AZ1 bit

G1[2:0] bits

VR1E, PS1[1:0] bits

VR1[2:0] bitsx VDDA

/8

OA1Interrupt

OA1IE bitbit

8-Step ReferenceVoltage 1

Band GapReference

Voltage

Programmablegain ValueInverter

-1-2-3-4-8

-16

Non Inverter

23458

16

To ADC Channel 8

Page 95: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

OPAMP MODES (2)

OA1O

OA1NIN

OA1

R=2K

15R /16R

R

AV CL =1, 2, 4, 8, 16, ∞

R3=2K

(1.2V)

AGND

OA1PINTo ADC Channel 8

NS1[2:0] bits

AZ1 bit

G1[2:0] bits

VR1E, PS1[1:0] bits

VR1[2:0] bitsx V DDA /8

OA1Interrupt

OA1IE bitbit8-Step Reference

Voltage 1

Band GapReferenceVoltage selectables

positive input

Comparator mode

Page 96: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

SPGA MODES (3)

can sink up to

OA1NIN

OA1

R=2K

15R /16R

R

AVCL=1, 2, 4, 8, 16, ∞

R3=2K

AGND

PWM0R / OA1PIN To ADC Channel 8

NS1[2:0] bits

AZ1 bit

G1[2:0] bits

VR1E, PS1[1:0] bits

VR1[2:0] bitsx VDDA/8

OA1Interrupt

OA1IE bitbit

8-Step ReferenceVoltage 1(1.2V)

Band GapReferenceVoltage

8-bit PWM/ARTimerChannel 1

Channel 2

PWM0

Internal Resistor

ExternalCapacitor

Analog output

40 mA

8-Bit Digital to Analog Converter

Page 97: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Op-Amps characteristics comparison

4

3

1

2.7 to 10

4

80

1

yes (I/O)

TS922audio

performance

<50

4

6

3 to 6

6

5< Icc < 50

0.5

yes (I/O)

ST72C171

23

5

0.5

4 to 44

1

25

1.7

no

UA 741general purpose

Noise(nv*sqr(Hz))

Offset voltage (mV)

Slow rate (v/us)

Power supply range(v)

GPB

Output current (mA)

Consumption (mA)

Rail to Rail

Page 98: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Optional

Peripheral

PORT

16-bit timer

Peripheral

Peripheral

Peripheral

Peripheral

Peripheral

PeripheralPeripheral

PowerSupply

WatchdogTimer

Data Ram256

bytes

Oscillator

Reset

Test/Vpp

INT

ProgramOtp / Rom

InterruptController

8-Bit CORE

SP

PCH

AccuIndex XIndex Y

CC

Data Ram

Data EEprom

PCL

ST7 CAN• Optional features:

EEPROMAD converterAnalog ComparatorSCISPII2C16-bit TimerLite Timers8-bit Auto Reload Timer12_bit ARtimersProgrammable OpAmpCAN

Page 99: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Gearbox

EMS

Traction

ABS

Sensor

BODYCOMFORTACCESS

ENTERTAINMENTAUDIOVIDEO

POWER-TRAINTRACTIONSTABILITY

Radio

Audio Power

TV-Module

Car-Phone

Navigation

Video-Box

Very high speedup to 100M bps

High speed CAN2.0B 125 kbps to 1Mbps

Low speed CAN 2.0B < 125 kbps

Wiper Immobiliser

Door Module

Door Module

Door Module

Door Module

Trunk Module

Air Cond

Driver-Seat

Pass.-Seat

BackseatDoom-ControlContr.

Pannel.

Light C. Front

Light C. Rear

Central Airbag

DashboardCAN Gateway

DIAGNOSISISO914110kbps

Wiper Left UART Node to Node

High End Car Networks

Page 100: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

CAN High Lights

• Asynchronous Serial Communication Protocol Based OnMulti-master concept

CSMA/CA (Carrier Sense Multiple Access Collision Avoid)

Message priority

Object oriented communicationNo node addressing, but content identification

Realtime capabilityLow message transfer latency

System wide message consistenceError detection & management mechanism

Page 101: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

CAN Bus Topology

differential voltagetwisted wire40m @ 1 Mbps

CANH CANL

CANTransceiver

CANController

µC

TXRX

SensorSignals

ActuatorSignals

Node 1 Node 2 Node N

Page 102: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

CAN 2.0A (standard format: 11 bit identifier)

R

D

SOF

11 bit Identifier DLC

RTR

ArbitrationField

ControlField

DataField

CRCField

ACK EOF

CRC delimiterACK slot

ACK delimiter

Data, 0..8 bytes 15 bits 7 bits

Interframespace

19 bits 0..64 bits 25 bits

IDE=0

3 bits Bus Idle

CAN 2.0B (extended format: 29 bit identifier)

18 bit Identifier DLC

RTR

Arbitration Field ControlField

DataField

CRCField ACK EOF

CRC delimiterACK slot

ACK delimiter

Data, 0..8 bytes 15 bits 7 bits

39 bits 0..64 bits 25 bits

SOF SRRIDE=1

R

D11 bit Identifier

Interframespace

3 bits

Standard vs Extended Frames

Page 103: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Standard vs Extended Implementations

2.0B passive and active nodes can cohabit on the same network

Standardsend / receive yes yes yes

no (destructive !)

Extended

check / acknowledge

Extended

send / receive

no (compliant)

no (destructive !) yes

yesyes

Implementation 2.0 A 2.0B Passive 2.0B Active

Page 104: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

CAN Bus Characteristics• Wired-AND

Two LevelsRecessiveDominant

• Dominant Prevail

node 2

node 1

node N

CANBus

recessivedominant

Page 105: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Bus Access And Arbitration

Node 2

Node 1

Node N

CAN Bus recessivedominant

Arbitration Phase

Remainder

Transmit Request

Node XNode 1Node 2Node N

CAN Bus

Page 106: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Error Detection - At Transmitter

• Bit ErrorBased on the "write verify" principle each bit sent is read back by the transmitter

If the values differ an error is detectedExcept during arbitration phase

• Acknowledge ErrorA receiver considering a frame as correct has to acknowledge it otherwise it has to signal the detected error with an Error FrameA transmitter missing the acknowledge supposes to be the only active node in the network

Page 107: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Error Detection - At Receiver

• Bit ErrorSee transmitter

• Stuff ErrorMore than 5 identical bits are detected

• CRC ErrorThe received and calculated CRC values different

• Form ErrorOne of the fixed format bits is not correct

CRC delimiterACK delimiterEnd Of Frame

Page 108: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Error Active

Reset and configuration

Error Passive Bus Off

TEC > 127 orREC > 127 TEC < 128 and

REC < 128

TEC > 255

128 blocks of 11 successive recessive bits

Fault Confinement

Page 109: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Basic vs Full CAN

• Full CAN controllerMany buffers (e.g. 15)Sophisticated message filteringDedicated HWLarger silicon (buffer size, filtering)

• Basic CAN controllerFew Tx/Rx buffers (e.g. 3)Simple identifier filteringMore SW overheadLess silicon

Typical: Car body Typical: Engine management

Page 110: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Filters Possible Implementations• FULL CAN

Buffer allocation is static based on message IDMessages may not be copied to RAM (automatic reply capability)Interesting if great number of buffers

• BASIC CANBuffer allocation is dynamic based on avalaibilityMessages must be copied to RAM (more CPU load)

RX Buffer 1

RX Buffer 2

RX Buffer 3

DecreasingRX Priority

RX Buffer 1

RX Buffer 2

RX Buffer 3Match Filters0 & 1

Match Filter 0

Match Filter 1

Page 111: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST7 CAN Cell - Block Diagram

IT STAT

INTERNAL BUS

INTERFACE

TX / RXBuffer 110 Bytes

TX / RXBuffer 210 Bytes

TX / RXBuffer 310 Bytes

IDFilter 04 Bytes

IDFilter 14 Bytes

BCDL 8-bit Shift Reg.

EML

CAN 2.0 B passive Engine

REC

TEC

CSR

IT CTRL

BTR

CKDIV

PAGE

RX

TX

BTL

CRC

Page 112: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Key Features

• Comply with 2.0B passive specification

• Speed: up to 1MBits/s

• Basic CAN capability with:3 prioritized object messages (8 data bytes each)2 acceptance filters (ID + RTR match for 0, 1 or don't care)

• Flexibility

• Full baud rate & bit timing controlBuffers useable as transmit or receive buffers

Page 113: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Other Features

• Optimized buffer flip-flopping capability in transmissionReal-time performance at minimum CPU loadDeterministic transfersSolves the inner priority inversion problem with no extra hardware

• Low power mode

• Extensive interrupt schemeSeparate signalling for successful transfers and errors7 maskable sources: Tx, Rx123, Tx error, Rx error, overrun

Page 114: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Buffer Pagination

• Saves on address space44 registers mapped onto 22 addresses

• Allows more efficient addressing mode

No memory indirection

Interrupt StatusInterrupt ControlControl / Status

Baud Rate PrescalerBit Timing

Page Selection

16 PAGED REGS16 PAGED REGS

16 PAGED REGS16 PAGED REGS

5 PAGES OF16 REGISTERS

FOR DIAGNOSIS,MESSAGE BUFFERS,

ACCEPTANCE FILTERS

Page 115: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Page Mapping

• Buffer-dedicated Control / Status Register (BCSR)Reduces requirements on CPU reactiveness

• Dual mapping of Rx interupt flags in the ISR and BCSRThe same code handles any buffer

LAST ID

RESERVED

TEST REG.ERROR

COUNTERS

10-BYTEBUFFER 1

RESERVED

CTRL / STATUS 1

10-BYTEBUFFER 2

RESERVED

CTRL / STATUS 2

10-BYTEBUFFER 3

RESERVED

CTRL / STATUS 3

FILTER 0

FILTER 1

RESERVED

Page 1Page 0 Page 3Page 2 Page 4

Page 116: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Sleep Mode & Wake Up

• Software controlled low power mode (RUN bit cleared)Prescaler and protocol engine stoppedNeed for resynchronization

• Automatic low power mode after 20 recessive bitsProtocol engine stoppedNo need for resynchronization (idle mode)

• Wake-up upon reception of dominant bit

• Possible wake up pulse generation when leaving stand-by

Page 117: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

Cell Certification

• Validated with Bosch C model and patterns

• Certification on going with expert third party (c&s)Protocol compliance test according to Bosch & ISO specificationsCPU interface testCell robustness behaviour

• Final silicon certification targeted 1Q99

Page 118: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

ST725xx Kits

• Development kit - ST7MDT2-DVP2Available now at STUser software development and debuggingEasy connection to a high speed CAN node/networkCompatible to widespread CAN Vector tools

• CAN Demonstration BoardAvailable now at STSoftware functions controlled by PC - Visual CAN

• Visual CAN Intuitive GUI to discover and exercice ST7 passive CAN cellExisting CAN network traffic monitoringCAN messages generator function

Page 119: ST7 MICROCONTROLLER TRAINING - STMicroelectronics · ST7 A/D CONVERTER Overview (1) • 8-Bit and 10-Bit ADC depending on the device: ¾8-Bit on ST72254, ST72334, ST7Lite0 ¾10-Bit

VisualCAN Snapshot