ST AN3298 APPLICATION NOTE

AN3298
Application note
STM8S DALI slave library
Introduction
This document describes the implementation of the Digital Addressable Lighting Interface (DALI) into the STM8S 8-bit microcontroller family.
The DALI slave library for STM8S microcontrollers simplifies integration of the DALI slave interface into customer applications. The implementation of DALI into STM8S, together with the various STM8S features (peripherals, computation power, communication interfaces), is mainly used in light control applications (example, electronic ballast control).
The STM8S DALI slave library was tested according to the DALI specification.
The DALI slave library comes with a simple application example (DALI slave device). The example was designed (and tested) for use with the following evaluation boards:
STM8S-DISCOVERY (see UM0817, STM8S-DISCOVERY)
DALI transceiver board (see UM1032: STEVAL-ILMOO1V1 hardware module for the STM8S-DISCOVERY interface for DALI communication).
The application example controls the light of the on-board LED diode. Light intensity is controlled by the PWM method using a built-in timer. The external DALI master device must control this application example (which is the DALI slave device). The DALI master devices were tested using the ST7DALI evaluation kit (master device board and PC software) and commercial DALI controller from Osram.
The user can use the provided example as a starting point for writing an application using the STM8S DALI slave library.
Useful information and links about DALI interface can be found on http://www.dali-ag.org.
March 2011 Doc ID 18098 Rev 1 1/27
www.st.com
Contents AN3298
Contents
1 DALI information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1 DALI standard overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1.1 DALI purpose and properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1.2 DALI physical layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.1.3 DALI stack layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2 STM8S DALI slave library overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2 Structure of final user application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1 User application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2 DALI stack layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 I/O pin driver layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Function description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1 I/O pin driver layer functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1.1 stm8_interrupt_vector.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1.2 stm8_it.c,
stm8_it.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1.3 DALIslave.c,
DALIslave.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1.4 stm8s.h,
stm8s_conf.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 DALI stack layer functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.1 dali.c,
dali.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.2 dali_cmd.c,
dali_cmd.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2.3 dali_pub.c,
dali_pub.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2.4 dali_reg.c,
dali_reg.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.2.5 eeprom.c,
eeprom.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.2.6 lite_timer_8bit.c,
lite_timer_8bit.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.2.7 dali_config.c,
dali_config.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2/27 Doc ID 18098 Rev 1
AN3298 Contents
4 Resources and examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.1 Typical user application flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2 DALI stack footprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Doc ID 18098 Rev 1 3/27
List of tables AN3298
List of tables
Table 1. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4/27 Doc ID 18098 Rev 1
AN3298 List of figures
List of figures
Figure 1. DALI wiring example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 2. Example of DALI device connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 3. Voltage and currents on the DALI bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 4. Structure of user application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 5. Structure of DALI stack layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 6. Structure of I/O pin driver layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 7. Hardware for testing DALI: STM8S Discovery kit with plugged-in DALI
transceiver board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 8. Flowchart of the user application which uses the DALI slave library . . . . . . . . . . . . . . . . . 24
Doc ID 18098 Rev 1 5/27
DALI information AN3298

1 DALI information

1.1 DALI standard overview

DALI is an international standard (IEC 62386) lighting control system that provides a single interface for electronic control gears (light sources) and devices (lighting controllers).
The DALI standard enables dimmable ballasts, transformers, relay modules, emergency fittings and controllers from different manufacturers to be mixed and matched into a single control system. A DALI system provides designers, installers, building owners, facility managers and end-users a powerful and flexible digital lighting system with security of supply from many sources.
The DALI standard is overseen by the “AG-DALI” activity group which comprises engineers, manufacturers, and institutions working in the field of digital lamp/ lighting control.
More information about the DALI standard can be found in the following documents:
IEC 62386
NEMA STANDARD 243-2004
The following sections provide an overview of the DALI standard. They describe the basic principles of the DALI interface.
Note: To better understand the STM8S DALI slave library, a knowledge of the DALI interface
specification is essential. This application note does not provide a description of this specification.

1.1.1 DALI purpose and properties

The DALI protocol was designed to control modern light sources using a computer. Functions include:
Dimming
On/off switching
Grouping lights to a common control
Scene storage and selection
The DALI design properties include:
Simple wiring using standard electrical installation cables
No special wiring topology (as with power electrical cables)
Simple installation giving cable polarity independence
Automated light source addressing
Use of low cost microcontrollers on the light source side to minimize cost of light source
Use of a simple protocol to control light dimming and switching.
6/27 Doc ID 18098 Rev 1
AN3298 DALI information
Figure 1. DALI wiring example

1.1.2 DALI physical layer

The DALI interface consists of a physical layer from two wires. This is a simple installation for which the polarity is independent.
The protocol used on these cables is a standard serial protocol. There is 1 start bit, 8 data bits, and 2 stop bits. The communication speed is fixed at 1200 Bd 10 %. Manchester coding is used for better resynchronisation: rising edge is logical 1 and falling edge is logical
0. Bytes are grouped into frames. One frame usually consists of 1 or 2 bytes which is either data only (answer from the device) or address + data (command to device).
Voltage levels present on DALI communication wires are higher than the transistor-transistor logic (TTL) levels that are usually used. This is due to better noise immunity because of higher interference present on nearby power installation cables. Voltage levels are defined as follows:
Low level state
-4.5 to 4.5 V (transmitter)
-6.5 to 6.5 V (receiver)
High level state
– 11.5 to 20.5 V (transmitter) – 9.5 ... 22.5 V (receiver)
Low level state is dominant on the DALI bus. The device can force this level to the DALI bus by shortening the DALI wires. Consequently, current levels are defined for devices used on the DALI bus. There are two device types:
1. DALI master or DALI slave communication devices. In these devices the current is sunk from the DALI bus. They consume a maximum of 2 mA to receive high level state and sink a minimum of 250 mA to transmit low level state.
The maximum length of the DALI bus depends on the cables used for the DALI communication wires. The length is linearly dependent on the cross section of the conductor. For example, a 1.5 mm
2
cable (which is typically used in light installation cables)
allows a maximum bus length of up to 300 m.
Doc ID 18098 Rev 1 7/27
DALI information AN3298
$UALPOWER
SUPPLY
#OMMUNICATIONS
INTERFACE
'ROUP 'ROUP 'ROUP

#ONTROLLER
#ONTROLLER
/THERCONTROLLER
AI
Collisions between several DALI masters on the DALI bus are solved on the basis of timing priorities. When a collision is detected (the DALI master should check the sent data), communication is muted for a period of time according to the assigned master priority. There are five defined priority levels: 12 ms, 13 ms, 14 ms, 15 ms, and 16 ms. The longest waiting time has less priority.
Figure 2. Example of DALI device connections
Figure 3. Voltage and currents on the DALI bus
AI
&ORWARDTRANSMISSION
(IGHLEVELVOLTAGE6TO6TYPICAL6
,OWLEVELVOLTAGE6TO6
.ONACTIVESTATE
()GHLEVELCURRENT
&ORWARDDATABITS
M!
3ETTINGTIME
3TOPBITS
"ACKWARDTRANSMISSION
,OWVOLTAGELEVEL
!CTIVESTATE
-AXIMUMCURRENT
3TART
BIT
M!
"ACKWARD
DATABITS
6
T
T
AI
8/27 Doc ID 18098 Rev 1
AN3298 DALI information

1.1.3 DALI stack layer

The DALI stack is the higher DALI layer which implements DALI commands, DALI structures, timing management, and error management according to the DALI specification.
The most important feature of the DALI stack layer is the DALI commands. These commands are used for:
Direct light control such as dimming, on/off switching, and scene selection.
Device configuration to set DALI variables, read device properties, address
assignments, and query device status.
The DALI stack layer is fully implemented in microcontroller software.

1.2 STM8S DALI slave library overview

The STM8S DALI slave library contains instructions for implementing software of the DALI protocol into STM8S microcontrollers.
The DALI slave library consists of two layers:
Upper layer (DALI stack layer)
Hardware layer (I/O pin driver layer)
The upper layer of the DALI slave library (also known as the DALI stack layer), consists of routines for processing the required DALI commands and other necessary control functions (including timing control, error management, memory management, and light control).
The hardware layer (also known as the direct I/O pin driver layer), contains the physical layer implementation. This is necessary because STM8S microcontrollers do not support DALI communication peripherals.
The DALI slave library is written in C-language and is designed (and tested) for the Cosmic compiler. In future, the IAR and Raisonance compilers will also be used. The DALI slave library was developed using ST Visual Develop (STVD) IDE. In future, the IAR Embedded Workbench IDE will be used. All of these tools (compilers and IDE) are free for download from http://www.st.com/mcu or from compiler vendor websites.
Doc ID 18098 Rev 1 9/27
Loading...
+ 18 hidden pages