Sie sind auf Seite 1von 108

KNX Device Development

Implementation examples for:


- BIM M130
- BIM M130 in combination with Arduino UNO
Content
1 About the BIM M130/1/2/5 devices ...................................................................................... 3
1.1 Needed software & hardware ................................................................................3
1.2 About the Opternus Development Tool package ...................................................3
1.3 About the Arduino external microcontrollers ........................................................3
2 Preparation & Test ................................................................................................................ 4
2.1 Install the Minicube2 driver, NEC Debugger and IAR Embedded Workbench ...4
2.2 Install the BIM Tools .............................................................................................4
2.3 Connect & Prepare device .....................................................................................4
2.4 Install the Arduino IDE .........................................................................................4
3 Opternus BIM M13x based solutions ................................................................................... 5
3.1 Hardware Block Diagram ......................................................................................5
3.2 About the example downloads (source code) ........................................................6
3.3 Examples summary ................................................................................................6
3.3.1 Example 1 Simulated actuator (binary output) .................................... 6
3.3.2 Example 2 Actuator (binary output) .................................................... 6
3.3.3 Example 3 Sensor (push button) .......................................................... 6
3.3.4 Example 4 Actuator based on an external C (FT1.2) ........................ 6
3.3.5 Example 5 Sensor based on an external C (FT1.2) ........................... 6
3.4 Example 1 Simulated acutator (binary output) in detail .....................................7
3.5 Example 2 Actuator (binary output) in detail .....................................................8
3.6 Example 3 Sensor (push button) in detail ...........................................................9
3.7 Example 4 Actuator based on an external C in detail ....................................10
3.7.1 Example 4 The Arduino UNO source code ....................................... 11
3.8 Example 5 Sensor based on an external C in detail........................................12
3.8.1 Example 5 The Arduino UNO source code ....................................... 13
4 Internal working of a BIM .................................................................................................. 14
4.1 Processing Bus Telegrams ...................................................................................14
4.2 Processing PEI Events .........................................................................................16
5 AP Development with IAR based on Example 2 (Actuator) ......................................... 18
5.1 The complete file main.c .....................................................................................18
5.1.1 Detailed explanation of main.c ............................................................. 20
5.2 The complete file tables.c ....................................................................................21
5.2.1 Detailed explanation of table.c ............................................................. 22
5.3 Detailed explanation user.h .................................................................................23
5.4 Reserved Memory ................................................................................................23
5.5 Debug ...................................................................................................................24
5.6 Release .................................................................................................................24
5.7 Important note: property compare load control ...................................................28
6 ETS4 product entry creation based on Example 2 (Actuator) ..................................... 29
6.1 Start: Hardware, Catalog, AP/Static Part .............................................................29
6.2 AP Dynamic Part: ................................................................................................29
6.3 Import into ETS4 and Test ..................................................................................30

Copyright 2015, KNX Association page 2 of 30


1 About the BIM M130/1/2/5 devices
1.1 Needed software & hardware
Installed MT4 software and valid license.
Installed ETS4 software and valid license.
An Opternus Development Tool package.
Arduino IDE: only required for the external microcontroller based examples.

1.2 About the Opternus Development Tool package


This product is based on the BIM M132
- KNX Profile Class = System 2
The Opternus Development Tool package containing:
- A development board (PCB)
- NEC Minicube development platform for flash MCU
- IAR Embedded Workbench
- BIM Tools
This solution requires development from scratch, as BIM Modules do not contain predefined Group
Objects; i.e. the AP is developed in the C programming language.
This solution comes with a proprietary (not standardized) API, see document
BIM_M_13x_API_Reference_v1_2_01.pdf.

1.3 About the Arduino external microcontrollers


For the external microcontroller, we opted for the Arduino open source electronics prototyping platform.
More information can be found via this URL: arduino.cc
The main reason for choosing Arduino is the fact that the Arduino Software (compiler/loader) is free of
charge.
Several types of Arduino microcontrollers exist; we have used Arduino UNO.

Copyright 2015, KNX Association page 3 of 30


2 Preparation & Test
2.1 Install the Minicube2 driver, NEC Debugger and IAR Embedded
Workbench
Link: http://www.opternus.com/uploads/media/EVB_Getting_Started_V1.1.pdf.
Install instructions for Minicube2 including NEC Debugger, see section I of
EVB_Getting_Started_V1.1.pdf.
Install instructions for IAR Embedded Workbench, see section II of
EVB_Getting_Started_V1.1.pdf.

2.2 Install the BIM Tools


Run BIM_Tools_v1_1_50.msi.

2.3 Connect & Prepare device


Connect: see section III of EVB_Getting_Started_V1.1.pdf.
Prepare: see section IV of EVB_Getting_Started_V1.1.pdf.
In this particular case, use BIM_M_130__M_135_Debug_v1_08.hex.

2.4 Install the Arduino IDE


Only required for the external microcontroller based examples (i.e. example 4 & 5).
Link: arduino.cc

Copyright 2015, KNX Association page 4 of 30


3 Opternus BIM M13x based solutions
3.1 Hardware Block Diagram
BIM M13x

GND - C1 / EVB24 P70 B5 / EVB07


P71 A6 / EVB01
VCC - D2 / EVB18 P72 B4 / EVB11
P73 A5 / EVB05
VDD - D1 / EVB22 P74 B3 / EVB15
P75 A4 / EVB09
P76 B2 / EVB19
P77 A3 / EVB13

78F053X

TxD D3 / EVB14
TP-UART RxD D4 / EVB10

+Bus E1/EVB25
-Bus E2/EVB26

Figure 1 Hardware Block Diagram

Copyright 2015, KNX Association page 5 of 30


3.2 About the example downloads (source code)
All IAR projects are available as download, they can be found in the same directory where this
very file can be downloaded from, i.e. each example has its dedicated zip file.
The Arduino UNO source code for example 4 & 5 can also be found in the relevant zip file.
The s19 file & MT4 project for example 2 can also be found in the relevant zip file.

3.3 Examples summary


3.3.1 Example 1 Simulated actuator (binary output)
This is the easiest example because there is no additional hardware required.
The output will be simulated by means of the so called test pins.

3.3.2 Example 2 Actuator (binary output)


The AP toggles a LED via an I/O port.
This sample includes the use of a timer.
This sample includes the use of a parameter.

3.3.3 Example 3 Sensor (push button)


The AP detects push button events.
A normal closed push button is connected via an I/O port.
This sample includes the use of a simple debounce function.

3.3.4 Example 4 Actuator based on an external C (FT1.2)


An Arduino UNO external C is connected to the BIM.
Bus events for GO0 will propagated to the external C by the BIM via its TxD/RxD ports.
The external C will switch a LED accordingly.
The communication between the BIM and the external C is based on the FT1.2 serial protocol.

3.3.5 Example 5 Sensor based on an external C (FT1.2)


An Arduino UNO external C is connected to the BIM.
The external C detects push button events.
Each push button event will be propagated to the BIM via its TxD/RxD ports.
The push button events will be further propagated via GO0 onto the bus by the BIM.
The communication between the BIM and the external C is based on the FT1.2 serial protocol.

Copyright 2015, KNX Association page 6 of 30


3.4 Example 1 Simulated acutator (binary output) in detail

BIM M13x

GND - C1 / EVB24 T3 (JP4)

VCC - D2 / EVB18

VDD - D1 / EVB22
470

78F053X
LED

TxD D3 / EVB14
TP-UART RxD D4 / EVB10

+Bus E1/EVB25
GND
-Bus E2/EVB26

Figure 2 Hardware Block Diagram for Example 1

Connect a LED + resistor between test pin 3 and GND of the BIM M13x Evaluation Board.
- Test pin 3 is T3 of JP4 (TEST pins).
- The test pins are not available on regular BIM M13x devices.
- GND is pin 24 of JP2 (BIM Connector).
Compile the sample project contained in: Opternus_Example1-v01.zip
GO0 toggles test pin 3, this GO is by default associated with GA = 0/0/1.
Send GroupData telegrams for GO0 e.g. with ETS Group Monitor.
- Value = 0 (off) should switch off the LED.
- Value = 1 (on) should switch on the LED.

Copyright 2015, KNX Association page 7 of 30


3.5 Example 2 Actuator (binary output) in detail

BIM M13x

GND - C1 / EVB24 P70 B5 / EVB07


P71 A6 / EVB01
VCC - D2 / EVB18 P72 B4 / EVB11
P73 A5 / EVB05
VDD - D1 / EVB22 P74 B3 / EVB15
P75 A4 / EVB09 470
P76 B2 / EVB19
P77 A3 / EVB13

78F053X
LED

TxD D3 / EVB14
TP-UART RxD D4 / EVB10

+Bus E1/EVB25
GND
-Bus E2/EVB26

Figure 3 Hardware Block Diagram for Example 2

Connect a LED + resistor between I/O port P70 and GND of the BIM M13x Evaluation Board.
- P70 is pin 7 of JP2 (BIM Connector), on regular BIM M13x devices P70 is pin B5.
- GND is pin 24 of JP2 (BIM Connector), on regular BIM M13x devices GND is pin C1.
Compile the sample project contained in: Opternus_Example2-v01.zip
The LED can be activated via GO0, which by default is associated with GA = 0/0/1.
- Value = 0 (off) should switch the LED off.
- Value = 1 (on) should make the LED toggle.
The toggle frequency = 1/ (toggle time * toggle factor).
- The Toggle Time is set to 100 ms.
- Toggle factor = 0 means that the LED is continuously lit.
The toggle factor is stored as parameter in the memory of the device (EEPROM).
The toggle factor can be changed via GO1, which by default is associated with GA = 0/0/2.
- E.g. value = 5 will make the LED toggle 2 times per second when activated.
- E.g. value = 10 will make the LED toggle each second when activated.

Copyright 2015, KNX Association page 8 of 30


3.6 Example 3 Sensor (push button) in detail

BIM M13x

GND - C1 / EVB24 P70 B5 / EVB07


P71 A6 / EVB01
VCC - D2 / EVB18 P72 B4 / EVB11
P73 A5 / EVB05
VDD - D1 / EVB22 P74 B3 / EVB15
P75 A4 / EVB09
P76 B2 / EVB19
P77 A3 / EVB13

78F053X

TxD D3 / EVB14 Push


TP-UART RxD D4 / EVB10
Button
+Bus E1/EVB25
-Bus E2/EVB26

GND

Figure 4 Hardware Block Diagram for Example 3

Connect a push button between I/O port P77 and GND of the BIM M13x Evaluation Board.
- P77 is pin 13 of JP2 (BIM Connector), on regular BIM M13x devices P77 is pin A3.
- GND is pin 24 of JP2 (BIM Connector), on regular BIM M13x devices GND is pin C1.
Compile the sample project contained in: Opternus_Example3-v01.zip
The push button events will be propagated via GO0 onto the bus.
- GO0 by default is associated with GA = 0/0/1.
- Each push button event makes the value of GO0 toggle.
P77 initialization:
- P77 is set as output port.
- The pull-up resistor of P77 is set, which makes the value of P77 become logically 1.
The push button events are detected as follows:
- After each AP loop (3.3 ms) the value of P77 is evaluated.
- If the value of P77 = 0 (logically) it means that the button was pushed.
- The value of GO0 is toggled and sent to the bus.
- A timer (200 ms) is started in order to debounce the push button events.
P77 is after each push button event reset as follows:
- Set P77 as input.
- Set P77 as output.
- Set the pull-up resistor of P77, which makes the value of P77 become logically 1 again.

Copyright 2015, KNX Association page 9 of 30


3.7 Example 4 Actuator based on an external C in detail

BIM M13x

GND - C1 / EVB24 P70 B5 / EVB07


P71 A6 / EVB01
VCC - D2 / EVB18 P72 B4 / EVB11
P73 A5 / EVB05
VDD - D1 / EVB22 P74 B3 / EVB15
P75 A4 / EVB09
P76 B2 / EVB19
P77 A3 / EVB13

I/O pin 2
78F053X

TxD D3 / EVB14 RX pin 0


TP-UART RxD D4 / EVB10 TX pin 1 470

+Bus E1/EVB25
Arduino UNO
-Bus E2/EVB26

LED

GND

Figure 5 Hardware Block Diagram for Example 4

Connect the external C:


- GND of the external C with GND of the BIM: pin 24 of JP2 (BIM Connector), on regular
BIM M13x devices GND is pin C1
- RX pin 0 of the external C with TxD of the BIM: pin 14 of JP2 (BIM Connector), on
regular BIM M13x devices TxD is pin D3
- TX pin 1 of the external C with RxD of the BIM: pin 10 of JP2 (BIM Connector), on
regular BIM M13x devices RxD is pin D4
Compile the sample project contained in: Opternus_Example4-v01.zip
The LED can (indirectly) be activated via GO0, which by default is associated with GA = 0/0/1.
- Value = 0 (off) should switch the LED off.
- Value = 1 (on) should make the LED toggle.

For the external C:


- Arduino UNO pin 2 serves as simulation of a KNX binary output channel by means of a LED.
- Depending on the actual content of each received FT1.2 message the LED will either be
switched on or off.

Copyright 2015, KNX Association page 10 of 30


3.7.1 Example 4 The Arduino UNO source code
// 0x68,0x03,0x03,0x68,0xF3,0x00,0x01,0xF4,0x16 -> on
// 0x68,0x03,0x03,0x68,0xF3,0x00,0x00,0xF3,0x16 -> off

const int ledPin = 2;


int incomingByte = 0;

const int maxLen = 20;


int msgState = 0;
int msgCntr = 0;
int msgLen = 0;
int msg[maxLen];

void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(19200, SERIAL_8E1);
}

void loop()
{
if (Serial.available())
{
incomingByte = Serial.read();

if(msgState==0 && incomingByte==0x68)


{
msgState = 1;
msgCntr = 0;
msgLen = 0;

for(int i=0;i<maxLen;i++)
msg[i] = 0;
}
if(msgState==1)
{
msg[msgCntr++] = incomingByte;

if(msgCntr==2)
msgLen = incomingByte + 6;

if(msgCntr==msgLen)
{
if(incomingByte==0x16)
{
msgState = 0;
digitalWrite(ledPin, msg[6]);

Serial.write(0xE5); //ACK
}
}
}
}
}

Copyright 2015, KNX Association page 11 of 30


3.8 Example 5 Sensor based on an external C in detail

BIM M13x

GND - C1 / EVB24 P70 B5 / EVB07


P71 A6 / EVB01
VCC - D2 / EVB18 P72 B4 / EVB11
P73 A5 / EVB05
VDD - D1 / EVB22 P74 B3 / EVB15
P75 A4 / EVB09
P76 B2 / EVB19
P77 A3 / EVB13

VCC

78F053X I/O pin 4

TxD D3 / EVB14 RX pin 0 10K


TP-UART RxD D4 / EVB10 TX pin 1

+Bus E1/EVB25
Arduino UNO
-Bus E2/EVB26

Push
Button

GND

Figure 6 Hardware Block Diagram for Example 5

Connect the external C:


- GND of the external C with GND of the BIM: pin 24 of JP2 (BIM Connector), on regular
BIM M13x devices GND is pin C1
- RX pin 0 of the external C with TxD of the BIM: pin 14 of JP2 (BIM Connector), on
regular BIM M13x devices TxD is pin D3
- TX pin 1 of the external C with RxD of the BIM: pin 10 of JP2 (BIM Connector), on
regular BIM M13x devices RxD is pin D4
Compile the sample project contained in: Opternus_Example5-v01.zip
The push button events will (indirectly) be propagated via GO0 onto the bus.
- GO0 by default is associated with GA = 0/0/1.
- Each push button event makes the value of GO0 toggle.

For the external C:


- Arduino UNO pin 4 serves as input port in order to capture push button events.
- A simple debounce routine is implemented in order to detect the push button events.
- For each push button event an FT1.2 message is sent to the BIM.

Copyright 2015, KNX Association page 12 of 30


3.8.1 Example 5 The Arduino UNO source code
const int msg_odd_1[9] = {0x68,0x03,0x03,0x68,0x73,0x00,0x01,0x74,0x16};
const int msg_even_0[9] = {0x68,0x03,0x03,0x68,0x53,0x00,0x00,0x53,0x16};

const int buttonPin = 4;


int buttonState = HIGH;
int KNXoutput = LOW;
long lastDebounceTime = 0;
long debounceDelay = 200;
int TM = 0;
int i = 0;

void setup()
{
pinMode(buttonPin, INPUT);
Serial.begin(19200,SERIAL_8E1);
}

void loop()
{
if ((millis() - lastDebounceTime) > debounceDelay)
{
buttonState = digitalRead(buttonPin);
lastDebounceTime = millis();
TM = 1;
}
if ((TM == 1) && (buttonState == LOW))
{
if (KNXoutput == LOW)
{
KNXoutput = HIGH;
for(i=0; i < 9; i++)
Serial.write(msg_odd_1[i]);
}
else
{
KNXoutput = LOW;
for(i=0; i < 9; i++)
Serial.write(msg_even_0[i]);
}
buttonState = HIGH;
TM = 0;
}
}

Copyright 2015, KNX Association page 13 of 30


4 Internal working of a BIM
This is explains the relation between KNX bus traffic events and the BIM M13x device resources. It is
especially interesting when a deeper knowledge is required about the BIM based solutions, i.e.
understanding in full detail the relation between the BIM resources, the KNX communication stack and
the AP.

4.1 Processing Bus Telegrams


See: Figure 7.
The system software (KNX Stack) does the following:
It analyses the Group Address and the value of the Telegram.
It determines which GO is involved, by consulting the following Resources:
- the Group Address Table this is the list of GAs
- the Group Object Association Table, which maps between the GAs and the GOs
- the Group Object Table, which is the list of GOs and their descriptions
It updates the value for the involved GO in RAM. The consulted Resources are:
- the Application Info Block to retrieve the pointer to CObjects
- CObjects that contain the pointers for all GO values.
Sets the Update Flag for the involved GO in the RAM Flags.
The AP continuously polls the Update Flags. If at least one is set then it will:
Fetch the GO value as stored in RAM.
Control the PEI (if required and/or applicable).
Reset the Update Flag in the RAM Flags.

Copyright 2015, KNX Association page 14 of 30


Processing Bus Telegrams

PEI

KNX Stack:

1) parses the telegram into GA & data

AP 2) finds the involved GO(s)


-> using the Addres Table, Association Table & Object
Table

RAMFlags Address Table 3) updates the value of the GO with data


-> using CObjects

CObjects Association Table 4) sets the Update Flag in RAMFlags

Object Table The AP:

1) checks if at least 1 Update Flag has been set in


RAMFlags

KNX Stack 2) controls the PEI if required and/or applicable

3) resets the Update Flag

A_GroupValue_Write (GA, data)

KNX

Figure 7 Processing Bus Telegrams

Copyright 2015, KNX Association page 15 of 30


4.2 Processing PEI Events
See: Figure 8.
The AP:
Notices an event at the PEI.
Updates the value for the involved GO in RAM, the consulted resources are:
- the Application Info Block to retrieve the pointer to CObjects
- CObjects contains the pointers for all GO values.
Sets the Transmit Request Flag for the involved GO in the RAM Flags.
The system software (KNX Stack) continuously polls the Transmit Request Flags, if at least one is set,
then it will:
Generate the (group) Telegram, the consulted resources in order to find the appropriate GA are:
- the Object Table = list with GO descriptions
- the Association Table = mapping between GAs & GOs
- the Address Table = list with GAs
In order to find the appropriate data,
- the Application Info Block to retrieve the pointer to CObjects
- CObjects contains the pointers for all GO values.
Transmit the Telegram on the bus.
Reset the Transmit Request Flag for the involved GO in the RAM Flags.

Copyright 2015, KNX Association page 16 of 30


Processing PEI Events

PEI

The AP:

1) notices an event at the PEI

AP 2) updates the value of the GO accordingly


-> using CObjects

3) sets the Transmit Request Flag in RAMFlags


RAMFlags Association Table
KNX Stack:
Address Table Object Table
1) checks if at least 1 Transmit Request Flag has
been set in RAMFlags
CObjects
2) builds up the telegram
-> using the Object Table, Association Table &
Addres Table to get the GA
-> using CObjects to get the data
KNX Stack
3) transmits the telegram on the bus

4) resets the Transmit Request Flag in RAMFlags

A_GroupValue_Write (GA, data)

KNX

Figure 9 Processing PEI Events

Copyright 2015, KNX Association page 17 of 30


5 AP Development with IAR based on Example 2 (Actuator)
This is explains Example 2 on source code level. It is especially interesting when a deeper knowledge is
required about this solution, i.e. understanding the structure of the AP in full detail.
The IAR project (including the s19 file) is together with the MT4 project available as download, it can be
found in the same directory where this file can be downloaded from. File: Opternus_Example2-v01.zip

5.1 The complete file main.c


/******************************************************************************
*
* File: main.c
*
******************************************************************************/
#include "BIM_M13x.h"

// ram flags for communication objects


BYTE RAMFlags[(NUM_OF_COM_OBJ / 2) + 1];

// communication object values


BYTE Data_Obj0; /* this GO is used to activate or deactivate the output (P70) */
BYTE Data_Obj1; /* this GO is used to change the toggle factor via the bus */

#define TOGGLETIME MSEC100


TIMER_TAB UserTimerTab;
BYTE P70_status; /* status of the output (P70) */
BYTE param0; /* to store the value of the toggle factor */

/******************************************************************************/
// parameter: ToggleFactor
// used for TimerTicks = ToggleFactor * TOGGLETIME
#pragma constseg = PARAM
__root const BYTE ToggleFactor;

void AppInit(void)
{
// after initialization a taskswitch is required because
// the task switch is disabled at cstartup
U._TmInit(NUM_OF_TIMERS);

/* set the status of the output (P70) to 'not active' (no toggling) */
P70_status = 0xff;

/* set I/O port P70 to output */


PM7 reset_bit BIT0;

/* set the initial toggle factor value according to the memory parameter */
/* toggle factor = 0 means that the LED is lit continously when active */
param0 = ToggleFactor;

FORCE_TASKSWITCH();
}

//------------------------------------------------------------------------
// this is the main function of the application program
// it is called at the end of cstartup
//------------------------------------------------------------------------
void main (void)
{

// initialization

Copyright 2015, KNX Association page 18 of 30


AppInit();

// start the main loop of the application program


// it will be interrupted every 3.3ms and
// continued after a complete system cycle

for(;;)
{
/* activate or deactivate the output(P70) via GO0 */
if (U._TestAndCopyObject(COM_OBJ0, &Data_Obj0, 1) == TRUE)
{
if (Data_Obj0 == 0)
{
P7 reset_bit BIT0; /* deactivate the output */
P70_status = 0xff;
U._TmStop(&UserTimerTab.Timers[0]);
}
else
{
P7 set_bit BIT0; /* activate the output */
P70_status = 0x01;
U._TmStart(&UserTimerTab.Timers[0], TOGGLETIME * param0);
}
}

/* toggle the output when the timer elapses */


if(U._TmIsRunning(&UserTimerTab.Timers[0]) && U._TmIsExpired(&UserTimerTab.Timers[0]))
{
if(P70_status == 0x00)
{
P7 set_bit BIT0;
P70_status = 0x01;
}
else
{
P7 reset_bit BIT0;
P70_status = 0x00;
}
U._TmAddStart(&UserTimerTab.Timers[0], TOGGLETIME * param0);
}

/* get a new toggle factor value via GO1 */


if (U._TestAndCopyObject(COM_OBJ1, &Data_Obj1, 1) == TRUE)
{
param0 = Data_Obj1;

if (P70_status != 0xff)
U._TmAddStart(&UserTimerTab.Timers[0], TOGGLETIME * param0);
}

}
}

//------------------------------------------------------------------------
// this function is called @ power loss
//------------------------------------------------------------------------
void save()
{
}

//------------------------------------------------------------------------

Copyright 2015, KNX Association page 19 of 30


// this function is called @ AP unload
//------------------------------------------------------------------------
void unload()
{
}

const BYTE NbComsOb = NUM_OF_COM_OBJ;


const CObjPtr CObjects[] = // table for com objects
{
(void*)&NbComsOb, // ptr to number of cobjects
&Data_Obj0,
&Data_Obj1
};

//------------------------------------------------------------------------
// the application info block contains
// information required for the operating system
//------------------------------------------------------------------------
#pragma constseg = APPINFOBLOCK
const AppInfoBlock AIB =
{
Swap(0x0001), // AIBVersion
0x01, 0x01, // ApplFirmwareVersion, ApplFirmwareSubVersion
__program_start, // AppMain
save, // AppSave
unload, // AppUnload
CObjects, // pCObjects
RAMFlags, // pRAMFlags
&UserTimerTab, // pUserTimerTab
NULL, // pUsrIntObjRoot
NULL, // pUsrParamMgmt
0x0000 // WatchDogTime
};
#pragma constseg = default

5.1.1 Detailed explanation of main.c


// ram flags for communication objects
BYTE RAMFlags[(NUM_OF_COM_OBJ / 2) + 1];

// communication object values


BYTE Data_Obj0; /* this GO is used to activate or deactivate the output (P70) */
BYTE Data_Obj1; /* this GO is used to change the toggle factor via the bus */

This reserves the required RAM for the GOs of this AP: flags + values.
This is the operational (live) data for the GOs.
The actual definitions of the GOs are stored in EEPROM and will be set up in tables.c (see further)
in the resource called Object Table.
The address of RAMFlags needs to be specified in the Application Info Block.
BYTE P70_status; /* status of the output (P70) */
BYTE param0; /* to store the value of the toggle factor */

This reserves the required RAM in order to store the status of P70 and the toggle factor.
The exact memory locations depend on the settings stored in BIM_M_130.xcl.
#pragma constseg = PARAM
__root const BYTE ToggleFactor;

This reserves the required EEPROM in order to store the toggle factor.

Copyright 2015, KNX Association page 20 of 30


The exact memory locations depend on the settings stored in BIM_M_130.xcl.
const BYTE NbComsOb = NUM_OF_GOM_OBJ;

This reserves 1 byte in EEPROM in order to store the number of GOs.


const BYTE NbComsOb = NUM_OF_COM_OBJ;
const CObjPtr CObjects[] = // table for com objects
{
(void*)&NbComsOb, // ptr to number of cobjects
&Data_Obj0,
&Data_Obj1
};

This reserves the necessary EEPROM in order to store/set up a table, which consists of:
- a pointer to where the number of GOs is stored, this is a pointer to EEPROM
- pointers to where the GO values are stored, these are pointers to RAM.
The address of GObjects needs to be specified in the Application Info Block.
#pragma constseg = APPINFOBLOCK
const AppInfoBlock AIB =
{
Swap(0x0001), // AIBVersion
0x01, 0x01, // ApplFirmwareVersion, ApplFirmwareSubVersion
__program_start, // AppMain
save, // AppSave
unload, // AppUnload
CObjects, // pCObjects
RAMFlags, // pRAMFlags
&UserTimerTab, // pUserTimerTab
NULL, // pUsrIntObjRoot
NULL, // pUsrParamMgmt
0x0000 // WatchDogTime
};

This reserves the necessary EEPROM in order to store the Application Info Block.
This information stores amongst others:
- the starting address of the AP
- pointers to the save & unload routines
- pointer to the RAM flags
- pointer to the table containing the GO value pointers (= GObjects)

5.2 The complete file tables.c


/******************************************************************************
*
* File: tables.c
*
******************************************************************************/
#include "BIM_M13x.h"

#pragma constseg = ADDRTAB


__root const BYTE AdrTab[] =
{ NUM_OF_COM_OBJ + 1, // for debug: one group address per communication object
0x11, 0xFD, // physical address 1.1.253
// group addresses
0x00, 0x01,
0x00, 0x02,
0x00 // padding

Copyright 2015, KNX Association page 21 of 30


};
#pragma constseg = ASSOCTAB
__root const BYTE AssTab[] =
{ NUM_OF_COM_OBJ + 0, // for debug: one association per communication object
// grp.addr., comobj. num.,
0x01, 0x00,
0x02, 0x01,
0x00 // padding
};
#pragma constseg = COMTAB
__root const BYTE EE_CommsTab[] =
{ NUM_OF_COM_OBJ, // number of communication objects,
0x00, // pointer to RAMFlags is no longer used
// but must be specified for compatibility
/*Obj0*/ NULL, (COMM_ENABLE + WRITE_ENABLE + TRANSMIT_ENABLE + READ_ENABLE + TX_LOW),
UINT1,
/*Obj1*/ NULL, (COMM_ENABLE + WRITE_ENABLE + TRANSMIT_ENABLE + READ_ENABLE + TX_LOW), UINT8

};
#pragma constseg = default

5.2.1 Detailed explanation of table.c


#pragma constseg = ADDRTAB
__root const BYTE AdrTab[] =
{ NUM_OF_COM_OBJ + 1, // for debug: one group address per communication object
// (group addresses must be sorted in ascending order!)
0x11, 0xFD, // physical address 1.1.253
// group addresses
0x00, 0x01,
0x00, 0x02,
0x00 // padding
};

This reserves the required EEPROM for the Address Table of this AP.
- The first two bytes are reserved for the Individual Address IA of the BCU.
- The last byte is always 0x00 in order to indicate the end of this table.
- The GAs for this AP are stored between the IA and the end of table byte.
- In case the AP requires more GAs, they need to be added between the IA and the last byte, two
bytes per extra GA.
#pragma constseg = ASSOCTAB
__root const BYTE AssTab[] =
{ NUM_OF_COM_OBJ + 0, // for debug: one association per communication object
// grp.addr., comobj. num.,
0x01, 0x00,
0x02, 0x01,
0x00 // padding
};

This reserves the required EEPROM for the Association Table of this AP.
This table defines the links between the GAs and the GOs.
The last byte is always 0x00 in order to indicate the end of this table.
Each association contains two bytes:
- first = index of the GA in the Address Table
- second = index of the GO in the Object Table.
In case the AP requires more associations, they need to be added before the end of table byte, two
bytes per extra association.

Copyright 2015, KNX Association page 22 of 30


#pragma constseg = COMTAB
__root const BYTE EE_CommsTab[] =
{ NUM_OF_COM_OBJ, // number of communication objects,
0x00, // pointer to RAMFlags is no longer used
// but must be specified for compatibility
/*Obj0*/ NULL, (COMM_ENABLE + WRITE_ENABLE + TRANSMIT_ENABLE + READ_ENABLE + TX_LOW),
UINT1,
/*Obj1*/ NULL, (COMM_ENABLE + WRITE_ENABLE + TRANSMIT_ENABLE + READ_ENABLE + TX_LOW), UINT8

};

This reserves the required EEPROM for the Object Table of this AP.
This table contains the actual definitions of the individual GOs.
- The first byte contains the number of GOs.
- The second byte is reserved and needs to be set to 0x00 (because of compatibility reason).
Each GO definition contains 3 bytes
- The first byte is not used (set to NULL).
- The second byte is the config byte; it is used to define the communication flags (CRWTU) and
the priority (system, high, low, normal).
- Third byte defines the type (length) of the GO.

5.3 Detailed explanation user.h


/******************************************************************************
*
* File: user.h
*
******************************************************************************/
#ifndef __USER_H
#define __USER_H

#define NUM_OF_TIMERS 1
#define NUM_OF_COM_OBJ 2

#define COM_OBJ0 0
#define COM_OBJ1 1

#endif

This AP has 1 Timer. NUM_OF_TIMERS is therefore set to 1.


This AP has 2 GOs. NUM_OF_GOM_OBJ is therefore set to 2.
Defining COM_OBJx is mandatory! Even if you dont use them in the rest of the source code.

5.4 Reserved Memory


The reserved memory locations in RAM (variables) and EEPROM (parameters) are as mentioned before
defined in the file BIM_M_130.xcl.
/********************************************************************\
|* D A T A *|
\********************************************************************/
-Z(DATA)CSTACK+_CSTACK_SIZE#FBCF
-Z(DATA)NEAR_I,NEAR_Z,NEAR_N=FB00-FBCF

/********************************************************************\
|* C O D E *|
\********************************************************************/
-Z(CODE)PARAM=9C00-9FFF

Copyright 2015, KNX Association page 23 of 30


-Z(CODE)NEAR_ID,CONST,RCODE,CODE=8200-9BFF

-Z(CODE)COMTAB=8190-81FF
-Z(CODE)ASSOCTAB=8140-818F
-Z(CODE)ADDRTAB=8116-813F

-Z(CODE)APPINFOBLOCK=8000-8115
-Z(CODE)ROOTCODE=7800-7FFF
/********************************************************************/
-Z(CODE)BCU2_JMP=7700-77FF

5.5 Debug
Make sure that the Debug option is selected in the Workspace window.

Select Project/Make via the menu to compile and link the project.
Select Project/Debug via the menu in order to start the preparations for a debug session.
Select Debug/Go via the menu to actually start the AP.
This AP should as such work and does not require any real debugging unless you would like to test it with
other (hard-coded) GAs as the ones specified in the Address Table.

5.6 Release
Make sure that the Release option is selected within the Workspace window.
Select Project/Make via the menu to build the project; this will create the file
BIM_M_130_Template.map in the Release\List folder of this project.
As its content is too large to be copied here, only the most important part is shown here.
-------------------------------------------------------------------------
PARAM
Relative segment, address: 9C00 - 9C00 (0x1 bytes), align: 0
Segment part 13. ROOT. Intra module refs: AppInit
ENTRY ADDRESS REF BY
===== ======= ======
ToggleFactor 9C00
-------------------------------------------------------------------------

This means that ToggleFactor will be stored at address 9C00.


Project/Make will also create the file BIM_M_130_Template.s19 in the Release\Exe folder of this
project.
This is its content:
S00C00003F43535441525455503E
S1138000000101010082CA83CB83029C08FB00FBB0
S109801000000000000066
S10B81160311FD000100020049
S10981400201000201002F
S10B81900200005F00005F071C
S1138200712AE661D01600FB100E00D23261613291
S1138210AD0143617197868AFC8BFA0200800216D5
S1138220810240810290819AD382B5B7D4100000B4
S1138230B1B1891CD6C2A220DE0D25DE0DDE0C25CF
S1138240DE0CDE0B25DE0BDE0A25DE0A9D17076138
S11382500C07DE01612DDE01DE026128DE02DE0391
S11382602903DE0321342734352735302730278A84

Copyright 2015, KNX Association page 24 of 30


S1138270C7B2B49B7882B7AF891CD6AE04BE08AE31
S113828005BE09AE02BE06AE03BE0787BE04AE013C
S1138290BE0565616C616A616BE4E2B6B6B6B4AF03
S11382A0FAFEA101B372021277D6629A7682A1FF16
S11382B09E0CFB710B278E009C9E0DFB710B6F7146
S11382C00A6F712AE2712BE6000000000000000032
S11382D000B2AFB3B59AA282FA64A1000B079E0C58
S11382E0FB100000B1A0F0B18E0DFB120000706312
S11382F09A2A82B3B1021677D6C49A768210010004
S1138300A501120BFBB3D2020477D6C2B29A7682CD
S113831051BD2B8E0BFB9E0DFB8E0CFB41AD1F1034
S11383200000B1A0F0B18E0DFB12000070639A2A18
S113833082B3B1A1FB75021677D6C49A7682100077
S113834000A501120AFBB3D2020477D6C2B29A7610
S11383508251BD438E0AFB4D00BD15A1FF0B079E44
S11383600CFB1002FBD4021C77D6C49A7682FA273F
S1138370A1010A079E0CFB100000B1A0F0B18E0D04
S1138380FB12000070639A2A82B3B11002FBD4027C
S11383901477D6C49A76821002FBD4021A77D6C414
S11383A09A76824D00BD039BFD82021877D6C49A4B
S11383B076824D00BD039BFD828E0CFB4D00AD0308
S10F83C09BDA82A1010A079BDE82AFAFAA
S10B9C000002019C0AFB0BFBAE
S90382007A

As such this file is correct but not usable for the MT, as it needs to be modified first.
This can be done automatically via a Post-build command line, by doing the following.
Click Project/Options
Click Build Actions
Copy this: C:\Program Files\Siemens AG\BIM Tools\aioc.exe -t modifier --targs Template_130
"$PROJ_DIR$\config.xml" "$PROJ_DIR$\Release\Exe\BIM_M_130_Template.s19"
"$PROJ_DIR$\Release\Exe\BIM_M_130_Template_mod.s19" into the Post-build command line field.
Building the project will from now on create two extra files in the Release\Exe folder of this project:
BIM_M_130_Template_mod.log, and
BIM_M_130_Template_mod.s19.
BIM_M_130_Template_mod.s19 is the actual modified s19 file and is directly usable (via import) in the
MT. This is its content:
S00F000054656D706C6174655F313330C1
S113000000F00000000000000000000000000000FC
S113E800000101010082CA83CB83029C08FB00FB48
S109E810000000000000FE
S10B01160311FD0001000200C9
S1090140020100020100AF
S10B01900200005F00005F079C
S1130200712AE661D01600FB100E00D23261613211
S1130210AD0143617197868AFC8BFA020080021655
S1130220810240810290819AD382B5B7D410000034
S1130230B1B1891CD6C2A220DE0D25DE0DDE0C254F
S1130240DE0CDE0B25DE0BDE0A25DE0A9D170761B8
S11302500C07DE01612DDE01DE026128DE02DE0311

Copyright 2015, KNX Association page 25 of 30


S11302602903DE0321342734352735302730278A04
S1130270C7B2B49B7882B7AF891CD6AE04BE08AEB1
S113028005BE09AE02BE06AE03BE0787BE04AE01BC
S1130290BE0565616C616A616BE4E2B6B6B6B4AF83
S11302A0FAFEA101B372021277D6629A7682A1FF96
S11302B09E0CFB710B278E009C9E0DFB710B6F71C6
S11302C00A6F712AE2712BE60000000000000000B2
S11302D000B2AFB3B59AA282FA64A1000B079E0CD8
S11302E0FB100000B1A0F0B18E0DFB120000706392
S11302F09A2A82B3B1021677D6C49A768210010084
S1130300A501120BFBB3D2020477D6C2B29A76824D
S113031051BD2B8E0BFB9E0DFB8E0CFB41AD1F10B4
S11303200000B1A0F0B18E0DFB12000070639A2A98
S113033082B3B1A1FB75021677D6C49A76821000F7
S113034000A501120AFBB3D2020477D6C2B29A7690
S11303508251BD438E0AFB4D00BD15A1FF0B079EC4
S11303600CFB1002FBD4021C77D6C49A7682FA27BF
S1130370A1010A079E0CFB100000B1A0F0B18E0D84
S1130380FB12000070639A2A82B3B11002FBD402FC
S11303901477D6C49A76821002FBD4021A77D6C494
S11303A09A76824D00BD039BFD82021877D6C49ACB
S11303B076824D00BD039BFD828E0CFB4D00AD0388
S10F03C09BDA82A1010A079BDE82AFAF2A
S10B1C000002019C0AFB0BFB2E
S113F0000E000000000000000000000000000000EE
S113F01007004E0001010102030405060000000080
S113F02014000000000000000000000000000000C8
S113F03024000000000000000000000000000000A8
S113F0403400000000000000000000000000000088
S113F050110000000000000000000000000000009B
S113F0601300000116013F330300000000000000FC
S113F0701302000116000000000000000000000060
S113F080210000000000000000000000000000005B
S113F0902300000140018F33030000000000000042
S113F0A023020001400000000000000000000000F6
S113F0B0310000000000000000000000000000001B
S113F0C0330000E000E915330300000000000000F5
S113F0D033000001901FFF33030000000000000014
S113F0E03302000000FF00011234010000000000A0
S113F0F03305000000019000000000000000000043
S113F1005302000190000100010000000000000013
S113F11012000000000000000000000000000000D9
S113F12022000000000000000000000000000000B9
S113F1303200000000000000000000000000000099
S113F1400F000000000000000000000000000000AC
S113F150FF000000000000000000000000000000AC
S9030000FC

Not only the content of the first part has indeed been modified, it also has become longer, as the necessary
load controls have been added.

Copyright 2015, KNX Association page 26 of 30


BIM_M_130_Template_mod.log gives a summary of the modifications applied compared to
BIM_M_130_Template.s19, with the following content:
BIM-Tools v1.1.50.27121

Start reading MEMORYCONVERSION entries ...


MEMORYCONVENTRY: 7800 <-> 8115 Offset: +6800
MEMORYCONVENTRY: 8116 <-> 9FFF Offset: -8000
... finished reading MEMORYCONVERSION!

Start reading LOADCONTROLS entries ...


Read load control: CONNECT
Read load control: PROPERTYCOMPARE
Read load control: UNLOAD
Read load control: UNLOAD
Read load control: UNLOAD
Read load control: LOAD
Read load control: DATASEGMENT
Read load control: TABLEPOINTER
Read load control: LOAD
Read load control: DATASEGMENT
Read load control: TABLEPOINTER
Read load control: LOAD
Read load control: DATASEGMENT
Read load control: DATASEGMENT
Read load control: APPDATA
Read load control: TABLEPOINTER
Read load control: LOADCOMPLETED
Read load control: LOADCOMPLETED
Read load control: LOADCOMPLETED
Read load control: DISCONNECT
... finished reading LOADCONTROLS!

Start parsing "C:\Documents and Settings\Administrator\My Documents\dev\Opternus Example 2 -


V1.0\Release\Exe\BIM_M_130_Template.s19" ...
...finished!

Start creating "C:\Documents and Settings\Administrator\My Documents\dev\Opternus Example 2 -


V1.0\Release\Exe\BIM_M_130_Template_mod.s19" ...
Start converting memory ...
... finished!
Start creating load controls ...
... finished!
... finished!

This is important as it is necessary to know where the parameters for the AP will be located in EEPROM.
The log file shows that the offset for the memory locations have been changed:
MEMORYCONVENTRY: 7800 <-> 8115 Offset: +6800
MEMORYCONVENTRY: 8116 <-> 9FFF Offset: -8000

From BIM_M_130_Example_BasicKit.map it is known that the original location for ToggleFactor =


9C00 (see above). This means, because of

Copyright 2015, KNX Association page 27 of 30


MEMORYCONVENTRY: 8116 <-> 9FFF Offset: -8000

that the actual location for this (ETS) parameters shall be calculated as 0x9C00 0x8000, i.e the address
for ToggleFactor is 0x1C00.

5.7 Important note: property compare load control


The second load control of the above mentioned S19 file makes ETS validate a particular device property,
i.e. object 0, property 78 (0x4E). If the value of the target device property does not match with the value
indicated in the load control, being 0x01 0x02 0x03 0x04 0x05 0x06 then ETS will refuse to download
the AP. The default value of this property for off-factory devices is set to 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF.
There are two possibilities to resolve this:
- Either remove the load control from the load procedure (not recommended).
- Or modify the value of device property accordingly with the Device Editor ETS App
(recommended).

Copyright 2015, KNX Association page 28 of 30


6 ETS4 product entry creation based on Example 2 (Actuator)
This MT4 Project is available as part of the same download mentioned above.

6.1 Start: Hardware, Catalog, AP/Static Part


Start MT4
Add Project
- Type = KNX Manufacturer Tool Project
- Target ETS Version = ETS4
Add Hardware
- Version = 1
Define Product (= commercial realization of HW)
Add Application Program
- Number = 1 & Version = 1
- Mask Version = 2.5
Open and edit Hardware in order to link the hardware to the AP
- select Application Programs
- add new Hardware2Program
- Select the AP
AP Properties
- Dynamic Table Management = True
Open the AP
- Import binary data: the (modified) s19 from Example 2 (see above), this will add the:
o Code Segments
o Address Table
o Association Table
o Load Procedure
o Communication Objects
Add Parameter Type
- ParameterTypeNumber, type = unsignedInt, size = 8bit
Add Parameter
- Memory Parameter: Internal Name & Text = Toggle Factor
- Change Code Segment to 0190h
- Change Absolute Address to 1C00h (see above)
- Change Default Value to 5

6.2 AP Dynamic Part:


Add to Channel 1, Page1:
- Add both ComObjectRefRefs
- Add the ParameterRefRef

Copyright 2015, KNX Association page 29 of 30


ETS4 Preview Parameter Dialog:

Figure 10 ETS4 Preview Parameter Dialog

ETS4 Preview Object List:

Figure 11 ETS4 Preview Object List

6.3 Import into ETS4 and Test


Build the project in MT4.
Create a test project via the Edit menu in MT4.
Import the test project in ETS4.
The device is visible in the Device panel under All Devices.
Prior to programming with ETS, the evaluation board needs to be prepared as follows:
- start the NEC Tool ID78K0-QB
- select chip 78F0537_64
- click File/Download from the menu in order to download
BIM_M_130__M_135_Debug_v1_08.hex
- click Run/Go from the menu in order to activate the device

Copyright 2015, KNX Association page 30 of 30


KNX Device Development

Implementation examples for:


- SIM-KNX in combination with Arduino UNO
Contents
1 About the Tapko Technologies KNX-SIM devices ............................................................. 3
1.1 Needed software ............................................................................................................. 3
1.2 About the Tapko Technologies SIM-KNX Evaluation device ....................................... 3
2 Preparation & Test ................................................................................................................ 4
2.1 Connect & Play ............................................................................................................... 4
2.2 ETS Project ..................................................................................................................... 5
2.3 Use the terminal SW to check the device configuration ................................................. 7
2.4 Use the terminal SW in order to simulate the AM ......................................................... 7
3 Tapko Technologies SIM-KNX based solutions .................................................................. 8
3.1 Hardware Block Diagram ............................................................................................... 8
3.2 Arduino Microcontrollers ............................................................................................... 8
3.3 Arduino UNO used as KNX Sensor ............................................................................. 10
3.3.1 Example 1 Sensor: The Arduino UNO Source Code..................................... 11
3.4 Arduino UNO used as KNX Actuator .......................................................................... 12
3.4.1 Example 2 Actuator: The Arduino UNO Source Code ................................. 13

Copyright 2015, KNX Association page 2 of 13


1 About the Tapko Technologies SIM-KNX devices
1.1 Needed software
Installed ETS4 software (Demo is sufficient).
FTDI FT232BL driver.
Any serial terminal software.
Arduino IDE.

1.2 About the Tapko Technologies SIM-KNX Evaluation device


This device is based on the Tapko Technologies SIM-KNX device, details:
KNX Profile Class = System 7
Interface = serial asynchronous.
ASCII protocol.
Tapko Technologies SIM-KNX is available in two editions: 128 or 254 GOs.
Two variants are available: RS232 or USB.
The USB/128 edition has been used as base for this document.
Application Module = PCB based on the FTDI FT232BL chip
The FT232BL chip converts USB into RS232 legacy peripherals.
Tapko Technologies SIM-KNX devices come delivered with 128 pre-defined GOs or in other
words, they are ex-factory delivered with a preloaded certified application program.

Copyright 2015, KNX Association page 3 of 13


2 Preparation & Test
2.1 Connect & Play
Install the FT232BL driver
Link: http://www.ftdichip.com/Drivers/VCP.htm
This will add a virtual com port to your computer
Use any serial terminal software, e.g. Serial Terminal from RealTerm
Link: http://realterm.sourceforge.net/
Connect the PCB with the PC via USB
Screenshot:

Figure 1 Serial Terminal screenshot

Connect
Wire the device.
Open the serial terminal software (see Figure 1).
Click tab page Port.
Select the virtual com port that has been added.
Put its settings to 9600, 8, 1, none.
Play
Click tab page Send.
Make sure to set EOL (end of line) settings to +CR.
Type e.g. dag in the top entry field and click Send ASCII. This command will ask the device to
send back its Individual Address. This is a perfect method to test the principal working of the test
setup.
Other commands that could be used in this context are: das, dpg, dps, dr, dsg, dvg, gci. Consult the
Tapko Technologies SIM-KNX related documentation for more details.

Copyright 2015, KNX Association page 4 of 13


2.2 ETS Project
The purpose is to create an ETS project for testing both the sensor and actuator examples, which are
further down explained in this document.
Download a generic SIM-KNX based ETS project file from this URL: www.tapko.de.
Required Group Object setup for the Sensor example:
- Group Object DPT = DPT 1
- Group Object flags = Communication & Transmit
- Group Object usage = sending
- Group Object sending setup = send on every receive
Required Group Object setup for the Actuator example:
- Group Object DPT = DPT 1
- Group Object flags = Communication & Write
- Group Object usage = receiving
- Group Object indication setup = indication on every receive
Screenshots:

Figure 2 KNX-SIM ETS parameter settings

Copyright 2015, KNX Association page 5 of 13


Figure 3 KNX-SIM ETS group object settings

Copyright 2015, KNX Association page 6 of 13


2.3 Use the serial terminal SW to check the device configuration
Connect via USB.
Send the following ASCII commands:
ocg(0) to check the configuration of GO nr. 0
o expected response for a sensor: $01 $00 $47 $0001 $0000 $00
o expected response for an actuator: $01 $00 $17 $0000 $0802 $00
ogg(0) to check the assigned GA(s) for the same GO
o expected response, e.g.: $0001 for 0/0/1
o expected response, e.g.: $0002 for 0/0/2

Check the Tapko Technologies documentation for more details.

2.4 Use the serial terminal SW in order to simulate the AM


Connect via USB.
For the Sensor example:
Send e.g. the following ASCII command: ovs (0)1 to set the value of Group Object 0 to 1
Expected result: a A_GroupValue_Write telegram sent from the SIM-KNX to the bus

For the Actuator example:


Send an A_GroupValue_Write telegram to the bus with e.g. ETS Group Monitor
Expected result: an indication message from the SIM-KNX in the terminal SW monitor, e.g. oui
$01 $18 1

Check the Tapko Technologies documentation for more details.

Copyright 2015, KNX Association page 7 of 13


3 Tapko Technologies SIM-KNX based solutions
3.1 Hardware Block Diagram

SIM-KNX

+Bus pin 4 TxD pin 6


External C
-Bus pin 1 RxD pin 7

Key pin 2 VCC pin 5

LED pin 3 GND pin 8

Galvanic Separation

Figure 4 Hardware Block Diagram

Details:
Interface: serial ASCII protocol via TxD (pin 6) and RxD (pin 7).
For more details about the serial protocol, please consult the Tapko Technologies related SIM-
KNX documentation. URL: www.tapko.de

3.2 Arduino Microcontrollers


For the external microcontroller, we opted for the Arduino open source electronics prototyping platform.
More information can be found via this URL: arduino.cc
The main reason for choosing Arduino is the fact that the Arduino Software (compiler/loader) is free of
charge.
Several types of Arduino microcontrollers exist; we have used Arduino UNO.
Install the Arduino IDE:
Link: arduino.cc
Screenshot

Copyright 2015, KNX Association page 8 of 13


Figure 5 Arduino IDE

Copyright 2015, KNX Association page 9 of 13


3.3 Arduino UNO used as KNX Sensor

VCC

VCC
I/O pin 4
GND

10K
TX pin 1

Arduino UNO

Push
Button

GND
+Bus pin 4 TxD pin 6

-Bus pin 1 RxD pin 7

Key pin 2 VCC pin 5

LED pin 3 GND pin 8

SIM-KNX

Figure 6 Arduino UNO used as KNX Sensor

Details:
Arduino UNO pin 4 serves as input port in order to capture push button events.
Arduino UNO pin 1 serves as serial transmit port, which is connected to RxD of the SIM-KNX.
A simple debounce routine is implemented in order to detect the push button events.
For each push button event an ASCII command is sent to the SIM-KNX.

Copyright 2015, KNX Association page 10 of 13


3.3.1 Example 1 Sensor: The Arduino UNO source code
const int buttonPin = 4;
int buttonState = HIGH;
int KNXoutput = LOW;
long lastDebounceTime = 0;
long debounceDelay = 200;
int TM = 0;

void setup()
{
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}

void loop()
{
if ((millis() - lastDebounceTime) > debounceDelay)
{
buttonState = digitalRead(buttonPin);
lastDebounceTime = millis();
TM = 1;
}
if ((TM == 1) && (buttonState == LOW))
{
KNXoutput = !KNXoutput;
if (KNXoutput == LOW)
{
Serial.write("ovs(0)0");
Serial.write(13);
}
else
{
Serial.write("ovs(0)1");
Serial.write(13);
}
buttonState = HIGH;
TM = 0;
}
}

Copyright 2015, KNX Association page 11 of 13


3.4 Arduino UNO used as KNX Actuator

VCC
I/O pin 2
GND

RX pin 0 470

Arduino UNO
(*)

LED
74LVCC3245

(**)
+Bus pin 4 TxD pin 6
GND
-Bus pin 1 RxD pin 7

Key pin 2 VCC pin 5

LED pin 3 GND pin 8

SIM-KNX

Figure 7 Arduino UNO used as KNX Actuator

Details:
Arduino UNO pin 2 serves as simulation of a KNX binary output channel by means of a LED.
Arduino UNO pin 0 serves as serial receive port, which is connected to TxD of the SIM-KNX.
A simple serial port read routine is implemented in order to capture and process ASCII commands
from the SIM-KNX.
Depending on the actual content of each received ASCII command the LED will either be switched
on or off.

Remarks:
(*) The voltage translator 74LVCC3245 transfers the 3.3V TxD signal from the SIM-KNX into a 5V
RX signal for the Arduino UNO.
(**) Moreover, we even had to double-loop the connection between SIM-KNX TxD (pin 6) and the
voltage translator, around a clamp-on magnetic noise filter.

Copyright 2015, KNX Association page 12 of 13


3.4.1 Example 2 Actuator: The Arduino UNO source code
//oui $01 $18 0 -> {0x6F,0x75,0x69,0x20,0x24,0x30,0x31,0x20,0x24,0x31,0x38,0x20,0x30,0x20,0x0A,0x0D}
//oui $01 $18 1 -> {0x6F,0x75,0x69,0x20,0x24,0x30,0x31,0x20,0x24,0x31,0x38,0x20,0x31,0x20,0x0A,0x0D}
const int ledPin = 2;
int incomingByte = 0;

const int maxLen = 20;


int msgState = 0;
int msgCntr = 0;
int msg[maxLen];

void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
}

void loop()
{
if (Serial.available())
{
incomingByte = Serial.read();

if(msgState==0 && incomingByte==0x6f) //'o'


{
msgState = 1;
msgCntr = 0;

for(int i=0;i<maxLen;i++)
msg[i] = 0;

}
if(msgState!=0 && msgCntr<maxLen)
{
msg[msgCntr++] = incomingByte;

if(msgState==1 && incomingByte==0x75) //'u'


msgState = 2;

if(msgState==2 && incomingByte==0x69) //'i'


msgState = 3;

if(msgState==3 && msgCntr==13)


{
msgState = 0;
digitalWrite(ledPin, msg[12]-0x30); //0x30='0'
}
}
}
}

Copyright 2015, KNX Association page 13 of 13


KNX Device Development

Implementation examples for:


- SIM-KNX in combination with Texas Instruments
MSP-EXP430FR5739
Contents
1 About the Tapko Technologies SIM-KNX devices ............................................................. 3
1.1 Needed software ............................................................................................................. 3
1.2 About the Tapko Technologies SIM-KNX Evaluation device ....................................... 3
2 Preparation & Test ................................................................................................................ 4
2.1 Connect & Play ............................................................................................................... 4
2.2 ETS Project ..................................................................................................................... 5
2.3 Use the serial terminal SW to check the device configuration ....................................... 7
2.4 Use the serial terminal SW in order to simulate the AM ................................................ 7
3 Tapko Technologies SIM-KNX based solutions .................................................................. 8
3.1 Hardware Block Diagram ............................................................................................... 8
3.2 Texas Instruments MSP-EXP430FR5739 Microcontroller ............................................ 8
3.3 Arduino UNO used as KNX Sensor & KNX Actuator .................................................. 9
3.3.1 Example: The TI C source code, i.e. main.c ................................................... 10

Copyright 2015, KNX Association page 2 of 13


1 About the Tapko Technologies SIM-KNX devices
1.1 Needed software
Installed ETS4 software (Demo is sufficient).
FTDI FT232BL driver.
Any serial terminal software.
Arduino IDE.

1.2 About the Tapko Technologies SIM-KNX Evaluation device


This device is based on the Tapko Technologies SIM-KNX device, details:
KNX Profile Class = System 7
Interface = serial asynchronous.
ASCII protocol.
Tapko Technologies SIM-KNX is available in two editions: 128 or 254 GOs.
Two variants are available: RS232 or USB.
The USB/128 edition has been used as base for this document.
Application Module = PCB based on the FTDI FT232BL chip
The FT232BL chip converts USB into RS232 legacy peripherals.
Tapko Technologies SIM-KNX devices come delivered with 128 pre-defined GOs or in other
words, they are ex-factory delivered with a preloaded certified application program.

Copyright 2015, KNX Association page 3 of 13


2 Preparation & Test
2.1 Connect & Play
Install the FT232BL driver
Link: http://www.ftdichip.com/Drivers/VCP.htm
This will add a virtual com port to your computer
Use any serial terminal software, e.g. Serial Terminal from RealTerm
Link: http://realterm.sourceforge.net/
Connect the PCB with the PC via USB
Screenshot:

Figure 1 Serial Terminal screenshot

Connect
Wire the device.
Open the serial terminal software (see Figure 1).
Click tab page Port.
Select the virtual com port that has been added.
Put its settings to 9600, 8, 1, none.
Play
Click tab page Send.
Make sure to set EOL (end of line) settings to +CR.
Type e.g. dag in the top entry field and click Send ASCII. This command will ask the device to
send back its Individual Address. This is a perfect method to test the principal working of the test
setup.
Other commands that could be used in this context are: das, dpg, dps, dr, dsg, dvg, gci. Consult the
Tapko Technologies SIM-KNX related documentation for more details.

Copyright 2015, KNX Association page 4 of 13


2.2 ETS Project
The purpose is to create an ETS project for testing both the sensor and actuator examples, which are
further down explained in this document.
Download a generic SIM-KNX based ETS project file from this URL: www.tapko.de.
Required Group Object setup for the Sensor example:
- Group Object DPT = DPT 1
- Group Object flags = Communication & Transmit
- Group Object usage = sending
- Group Object sending setup = send on every receive
Required Group Object setup for the Actuator example:
- Group Object DPT = DPT 1
- Group Object flags = Communication & Write
- Group Object usage = receiving
- Group Object indication setup = indication on every receive
Screenshots:

Figure 2 KNX-SIM ETS parameter settings

Copyright 2015, KNX Association page 5 of 13


Figure 3 KNX-SIM ETS group object settings

Copyright 2015, KNX Association page 6 of 13


2.3 Use the serial terminal SW to check the device configuration
Connect via USB.
Send the following ASCII commands:
ocg(0) to check the configuration of GO nr. 0
o expected response for a sensor: $01 $00 $47 $0001 $0000 $00
o expected response for an actuator: $01 $00 $17 $0000 $0802 $00
ogg(0) to check the assigned GA(s) for the same GO
o expected response, e.g.: $0001 for 0/0/1
o expected response, e.g.: $0002 for 0/0/2

Check the Tapko Technologies documentation for more details.

2.4 Use the serial terminal SW in order to simulate the AM


Connect via USB.
For the Sensor example:
Send e.g. the following ASCII command: ovs (0)1 to set the value of Group Object 0 to 1
Expected result: a A_GroupValue_Write telegram sent from the SIM-KNX to the bus

For the Actuator example:


Send an A_GroupValue_Write telegram to the bus with e.g. ETS Group Monitor
Expected result: an indication message from the SIM-KNX in the terminal SW monitor, e.g. oui
$01 $18 1

Check the Tapko Technologies documentation for more details.

Copyright 2015, KNX Association page 7 of 13


3 Tapko Technologies SIM-KNX based solutions
3.1 Hardware Block Diagram

SIM-KNX

+Bus pin 4 TxD pin 6


External C
-Bus pin 1 RxD pin 7

Key pin 2 VCC pin 5

LED pin 3 GND pin 8

Galvanic Separation

Figure 4 Hardware Block Diagram

Details:
Interface: serial ASCII protocol via TxD (pin 6) and RxD (pin 7).
For more details about the serial protocol, please consult the Tapko Technologies related SIM-
KNX documentation. URL: www.tapko.de

3.2 Texas Instruments MSP-EXP430FR5739 Microcontroller


The main reason for choosing this specific microcontroller is the fact that the IDE (compiler/loader) is
free of charge at least for the limited edition, i.e. source code limited to 8K.
The IDE is one of the IAR Starter kits
For more details, see: www.iar.com

Copyright 2015, KNX Association page 8 of 13


3.3 TI C used as KNX Sensor & KNX Actuator

VCC
GND
P2.0

P2.1

MSP-EXP430FR5739

+Bus pin 4 TxD pin 6

-Bus pin 1 RxD pin 7

Key pin 2 VCC pin 5

LED pin 3 GND pin 8

SIM-KNX

Figure 5 TI C used as KNX Sensor & KNX Actuator

Details:
TI C pin P2.0 serves as serial receive port, which is connected to TxD of the SIM-KNX.
TI C pin P2.1 serves as serial transmit port, which is connected to RxD of the SIM-KNX.
A simple debounce routine is implemented in order to detect the onboard push button P4.1 events.
For each push button event an ASCII command is sent to the SIM-KNX.
A simple serial port read routine is implemented in order to capture and process ASCII commands
from the SIM-KNX.
Depending on the actual content of each received ASCII command the onboard LED2 will either
be switched on or off.

Copyright 2015, KNX Association page 9 of 13


3.3.1 Example: The TI C source code, i.e. main.c
//SIM-KNX sensor + actuator

#include "msp430fr5739.h"
#include <string.h>

#define MAXLEN 50

const char command_0[] = "ovs(0)0\r";


const char command_1[] = "ovs(0)1\r";

char rcv_buffer[MAXLEN];
int rcv_cntr;
char rcv_char;
int msgState;
int S1;
int S2;
int LED1;
int LED2;

void EnableSwitches(void)
{
P4IFG = 0; // P4 IFG cleared
P4IE = BIT0+BIT1; // P4 interrupt enabled
}

void DisableSwitches(void)
{
P4IFG = 0; // P4 IFG cleared
P4IE &= ~(BIT0+BIT1); // P4 interrupt disabled
P4IFG = 0; // P4 IFG cleared
}

void StartDebounceTimer(void)
{
// Debounce time = 1500 * 1/8000 = ~200ms
TA1CCTL0 = CCIE; // TACCR0 interrupt enabled
TA1CCR0 = 1500;
TA1CTL = TASSEL_1 + MC_1; // ACLK, up mode
}

void setLEDs(void)
{
// Enable LED1 & LED2
PJOUT &= ~(BIT0+BIT1);
PJDIR |= BIT0+BIT1;

// Clear both LEDs


PJOUT = 0x00;

LED1 = 0;
LED2 = 0;
}

void setSwitches(void)
{
// Set up switches S1 & S2
// P4.0 and P4.1 are configured as switches
// Port 4 has only two pins
P4OUT |= BIT0+BIT1; // Configure pullup resistor
P4DIR &= ~(BIT0+BIT1); // Direction = input

Copyright 2015, KNX Association page 10 of 13


P4REN |= BIT0+BIT1; // Enable pullup resistor
P4IES &= ~(BIT0+BIT1); // Lo/Hi edge interrupt
P4IE = BIT0+BIT1; // Interrupt enabled
P4IFG = 0; // IFG cleared

S1 = 0;
S2 = 0;
}

void setClock(void)
{
CSCTL0_H = 0xA5; // Unlock register
CSCTL1 |= DCOFSEL0 + DCOFSEL1; // Set max. DCO setting
CSCTL2 = SELA_1 + SELS_3 + SELM_3; // set ACLK = vlo; MCLK = DCO
CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0; // set all dividers
CSCTL0_H = 0x01; // Lock register
}

void setUart(void)
{
// Configure UART pins
P2SEL1 |= BIT0 + BIT1;
P2SEL0 &= ~(BIT0 + BIT1);
// Configure UART 0
UCA0CTL1 |= UCSWRST; // keep in reset mode
UCA0CTL1 = UCSSEL_2; // set SMCLK as UCLK
UCA0BR0 = 52; //9600 baud
UCA0BR1 = 0;
UCA0MCTLW |= 0x4911; // BRCLK = 8000000, UCBRFx = 1, UCBRSx = 0x49, UCOS16 = 1
UCA0CTL1 &= ~UCSWRST; // release from reset mode
UCA0IE |= UCRXIE; // Enable RX interrupt
}

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog

setLEDs();
setSwitches();
setClock();
setUart();

while(1)
{
__bis_SR_register(LPM4_bits + GIE); // low power mode4 + general interupt
__no_operation(); // For debugger
}
}

//**********************************************************************
//* Port 4 ISR for S1 & S2
//**********************************************************************
#pragma vector=PORT4_VECTOR
__interrupt void Port_4(void)
{
switch(__even_in_range(P4IV,0x04))
{
case 0x02: // P4.0 interrupt = S1
break;

case 0x04: // P4.1 interrupt = S2

Copyright 2015, KNX Association page 11 of 13


switch(S2)
{
case 0:
for(int i=0; i < 8; i++)
{
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = command_1[i];
}
PJOUT |= 0x01;
S2 = 1;
break;
case 1:
for(int i=0; i < 8; i++)
{
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = command_0[i];
}
PJOUT &= ~0x01;
S2 = 0;
break;
}

DisableSwitches();
StartDebounceTimer();
break;

default:
break;
}
}

//**********************************************************************
//* Timer A1 ISR for debounce Timer
//**********************************************************************
#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer1_A0_ISR(void)
{
TA1CCTL0 = 0;
TA1CTL = 0;
EnableSwitches();
}

//**********************************************************************
//* USCI (universal serial communication interfce) A0 ISR for RX
//**********************************************************************
#pragma vector = USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,0x02))
{
case 0x02: // UCRXIFG = P2.1 = RX
rcv_char = UCA0RXBUF;

switch(rcv_char)
{
case 0x6f: // 'o'
if(msgState == 0)
{
msgState = 1;
rcv_cntr = 0;
}

Copyright 2015, KNX Association page 12 of 13


break;
case 0x75: // 'u'
if(msgState == 1)
msgState = 2;
break;
case 0x69: // 'i'
if(msgState == 2)
msgState = 3;
break;
case 0x0a:
if(msgState == 3)
msgState = 4;
break;
case 0x0d:
if(msgState == 4)
{
if(rcv_buffer[9]-0x30)
PJOUT |= 0x02;
else
PJOUT &= ~0x02;

strcpy(rcv_buffer, "");
rcv_cntr = 0;
msgState = 0;
}
break;
default:
if(msgState == 3 && rcv_cntr < MAXLEN)
rcv_buffer[rcv_cntr++] = rcv_char;
break;
}
break;

default: break;
}
}

Copyright 2015, KNX Association page 13 of 13


KNX Device Development

Implementation examples for:


- KIMaip in combination with Arduino UNO
Contents
1 About the Tapko Technologies KIMaip devices ................................................................. 3
1.1 Needed software ............................................................................................................. 3
1.2 About the Tapko Technologies KIMaip Evaluation board............................................. 3
2 Preparation & Test ................................................................................................................ 4
2.1 Connect & Play ............................................................................................................... 4
2.2 ETS Project ..................................................................................................................... 5
2.3 Use the serial terminal SW to check the device configuration ....................................... 6
2.4 Use the serial terminal SW in order to simulate the AM ................................................ 6
3 Tapko Technologies SIM-KNX based solutions .................................................................. 7
3.1 Hardware Block Diagram ............................................................................................... 7
3.2 Arduino Microcontrollers ............................................................................................... 8
3.3 Arduino UNO used as KNX Sensor ............................................................................... 9
3.3.1 Example 1 Sensor: The Arduino UNO source code ...................................... 10
3.4 Arduino UNO used as KNX Actuator .......................................................................... 11
3.4.1 Example 2 Actuator: The Arduino UNO source code ................................... 12

Copyright 2015, KNX Association page 2 of 12


1 About the Tapko Technologies KIMaip devices
1.1 Needed software
Installed ETS5 software (Demo is sufficient).
FTDI FT232BL driver.
Any serial terminal software.
Arduino IDE.

1.2 About the Tapko Technologies KIMaip Evaluation board


This product is based on the Tapko Technologies KIMaip device, details:
KNX Profile Class = System 7, see Error! Reference source not found..
Interface = IC (Inter-Integrated Circuit).
Proprietary ASCII protocol.
Tapko Technologies KIMaip devices come delivered with 255 pre-defined GOs or in other words,
they are ex-factory delivered with a preloaded certified application program.

Copyright 2015, KNX Association page 3 of 12


2 Preparation & Test
2.1 Connect & Play
Install the FT232BL driver
Link: http://www.ftdichip.com/Drivers/VCP.htm
This will add a virtual com port to your computer
Use any serial terminal software, e.g. Serial Terminal from RealTerm
Link: http://realterm.sourceforge.net/
Connect the PCB with the PC via USB
Make sure all required jumpers are set correctly: please check the KIMaip documentation.
Screenshot:

Figure 1 Serial terminal software screenshot

Connect
Wire the device.
Open the serial terminal software (see Figure 1).
Click tab page Port.
Select the virtual com port that has been added.
Put its settings to 38400, 8, 1, none.
Play
Click tab page Send.
Make sure to set EOL (end of line) settings to +CR.
Type e.g. 03 61 0002 in the top entry field and click Send ASCII. This command will make the
device send back its individual address. This is a perfect method to test the principal working of the
test setup.

Copyright 2015, KNX Association page 4 of 12


Another command that could be used in this context is e.g.: 03 61 0003 in order to check the
programming mode. Consult the Tapko Technologies KIMaip related documentation for more
details and/or other commands.

2.2 ETS Project


The purpose is to use an ETS project for testing both the sensor and actuator examples, which are further
down explained in this document.
Download the generic KIMaip based ETS project file from this URL: www.tapko.de.
Make e.g. the following associations:
- Group Object 0: LED 1 1 bit with e.g. Group Address 0/0/1
- Group Object 1: LED 2 1 bit with e.g. Group Address 0/0/2

Screenshot:

Figure 2 KIMaip group object settings

Copyright 2015, KNX Association page 5 of 12


2.3 Use the serial terminal SW to check the device configuration
Connect via USB.
Send the following ASCII commands:
03 31 0000 to check the configuration of GO nr. 0
o expected response: 05 32 0000 00 D7
o In this example: type = 1 bit, flags = U,T, W, C, priority = low
05 38 0000 00 01 to check the first associated GA of GO nr. 0
o expected response: 07 39 0000 00 01 0001
o In this example: 0/0/1 is indeed the sending GA for GO nr. 0

Check the Tapko Technologies documentation for more details.

2.4 Use the serial terminal SW in order to simulate the AM


Connect via USB.
For the Sensor example:
Send e.g. the following ASCII command: 04 10 0000 01 to set the value of Group Object 0 to 1.
Expected result: a A_GroupValue_Write telegram sent from the KIMaip the bus

For the Actuator example:


Send an A_GroupValue_Write telegram to the bus with e.g. ETS Group Monitor.
Expected result: an indication message from the KIMaip in the terminal SW monitor, e.g. 04 20
0000 01

Check the Tapko Technologies documentation for more details.

Copyright 2015, KNX Association page 6 of 12


3 Tapko Technologies KIMaip based solutions
3.1 Hardware Block Diagram

KIMaip
(*)
+Bus pin 10 SDA pin 2
(*)
-Bus pin 9 SCL pin 3 External C
(**) DR pin 1

Key pin 12 VCC pin 16

LED pin 13 GND pin 9

(*) Pull-ups might be required


(**) DR: data ready - optional

Figure 3 Hardware Block Diagram

Details:
Interface: IC based ASCII protocol via SDA (pin 2) and SCL (pin 3).
For more details about the ASCII protocol, please consult the Tapko Technologies related KIMaip
documentation. URL: www.tapko.de

Important:
Depending on the external C it might be required to use pull-up resistors for SDA and SCL,
please carefully check the documentation of your external C.

Copyright 2015, KNX Association page 7 of 12


3.2 Arduino Microcontrollers
For the external microcontroller, we opted for the Arduino open source electronics prototyping platform.
More information can be found via this URL: arduino.cc
The main reason for choosing Arduino is the fact that the Arduino Software (compiler/loader) is free of
charge.
Several types of Arduino microcontrollers exist; we have used Arduino UNO.
Install the Arduino IDE:
Link: arduino.cc
Screenshot

Figure 4 Arduino IDE

Copyright 2015, KNX Association page 8 of 12


3.3 Arduino UNO used as KNX Sensor

VCC

VCC
I/O pin 4
GND
SDA pin A4
10K
SCL pin A5

Arduino UNO

Push
Button

GND

+Bus pin 10 SDA pin 2

-Bus pin 9 SCL pin 3

Key pin 12 VCC pin 16

LED pin 13 GND pin 9

KIMaip

Figure 5 Arduino UNO used as KNX Sensor

Details:
Arduino UNO pin 4 serves as input port in order to capture push button events.
Arduino UNO pin A4 serves as IC SDA port, which is connected to the KIMaip SDA.
Arduino UNO pin A5 serves as IC SCL port, which is connected to the KIMaip SCL.
A simple debounce routine is implemented in order to process the push button events.
For each push button event an ASCII command is sent to the KIMaip.

Important note:
For the Arduino Uno no pull-up resistors shall be used for SDA and SCL.
IC is based on a master-slave principle and KIMaip is always the slave device.

Copyright 2015, KNX Association page 9 of 12


3.3.1 Example 1 Sensor: The Arduino UNO source code
#include <Wire.h>

const int msg_0[5] = {0x04,0x10,0x00,0x00,0x00};


const int msg_1[5] = {0x04,0x10,0x00,0x00,0x01};
const int buttonPin = 4;
int buttonState = HIGH;
int KNXoutput = LOW;
long lastDebounceTime = 0;
long debounceDelay = 200;
int TM = 0;
int i = 0;

void setup()
{
pinMode(buttonPin, INPUT);
Wire.begin();
}

void loop()
{
if ((millis() - lastDebounceTime) > debounceDelay)
{
buttonState = digitalRead(buttonPin);
lastDebounceTime = millis();
TM = 1;
}

if ((TM == 1) && (buttonState == LOW))


{
KNXoutput = !KNXoutput;
if (KNXoutput == LOW)
{
Wire.beginTransmission(0x08);
for(i=0; i < 5; i++)
Wire.write(msg_0[i]);
Wire.endTransmission();
}
else
{
Wire.beginTransmission(0x08);
for(i=0; i < 5; i++)
Wire.write(msg_1[i]);
Wire.endTransmission();
}
buttonState = HIGH;
TM = 0;
}
}

Copyright 2015, KNX Association page 10 of 12


3.4 Arduino UNO used as KNX Actuator

VCC I/O pin 2


GND I/O pin 4
SDA pin A4

SCL pin A5 470

Arduino UNO

LED

GND
+Bus pin 10 SDA pin 2

-Bus pin 9 SCL pin 3

Data Ready pin 1

Key pin 12 VCC pin 16

LED pin 13 GND pin 9

KIMaip
Figure 6 Arduino UNO used as KNX Actuator

Details:
Arduino UNO pin 2 serves as simulation of a KNX binary output channel by means of a LED.
Arduino UNO pin A4 serves as IC SDA port, which is connected to the KIMaip SDA.
Arduino UNO pin A5 serves as IC SCL port, which is connected to the KIMaip SCL.
Arduino UNO pin 4 serves as Data Ready port, which is connected to the KIMaip Data Ready.
A simple IC read routine is implemented in order to capture and process ASCII commands from
the KIMaip.
Depending on the actual content of each received ASCII command the LED will either be switched
on or off.

Important notes:
For the Arduino Uno no pull-up resistors shall be used for SDA and SCL.
Since IC is based on a master-slave principle, where KIMaip is always the slave, the best practice
for using it as actuator is to involve the Data Ready pin in order to indicate bus events to the
master.

Copyright 2015, KNX Association page 11 of 12


3.4.1 Example 2 Actuator: The Arduino UNO source code
#include <Wire.h>

const int ledPin = 2;


const int dataReadyPin = 4;
int dataReadyState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 200;
int TM = 0;

int msg[5];
int i = 0;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(dataReadyPin, INPUT);
Wire.begin();
}

void loop()
{
if ((millis() - lastDebounceTime) > debounceDelay)
{
dataReadyState = digitalRead(dataReadyPin);
lastDebounceTime = millis();
TM = 1;
}

if ((TM == 1) && (dataReadyState == HIGH))


{
i=0;
Wire.requestFrom(0x08, 5);
while(Wire.available())
msg[i++] = Wire.read();

if(msg[2] == 0 && msg[3] == 0)


digitalWrite(ledPin, msg[4]);

dataReadyState = LOW;
TM = 0;
}
}

Copyright 2015, KNX Association page 12 of 12


KNX Device Development

Implementation examples for:


- KIMaip in combination with Texas Instruments MSP-
EXP430FR5739
Contents
1 About the Tapko Technologies KIMaip devices ................................................................. 3
1.1 Needed software ............................................................................................................. 3
1.2 About the Tapko Technologies KIMaip Evaluation board............................................. 3
2 Preparation & Test ................................................................................................................ 4
2.1 Connect & Play ............................................................................................................... 4
2.2 ETS Project ..................................................................................................................... 5
2.3 Use the serial terminal SW to check the device configuration ....................................... 6
2.4 Use the serial terminal SW in order to simulate the AM ................................................ 6
3 Tapko Technologies KIMaip based solutions ...................................................................... 7
3.1 Hardware Block Diagram ............................................................................................... 7
3.2 Texas Instruments MSP-EXP430FR5739 Microcontroller ............................................ 7
3.3 TI C used as KNX Sensor & KNX Actuator ................................................................ 8
3.3.1 Example: The TI C source code, i.e. main.c ..................................................... 9

Copyright 2015, KNX Association page 2 of 13


1 About the Tapko Technologies KIMaip devices
1.1 Needed software
Installed ETS5 software (Demo is sufficient).
FTDI FT232BL driver.
Any serial terminal software.
Arduino IDE.

1.2 About the Tapko Technologies KIMaip Evaluation board


This product is based on the Tapko Technologies KIMaip device, details:
KNX Profile Class = System 7
Interface = IC (Inter-Integrated Circuit).
Proprietary ASCII protocol.
Tapko Technologies KIMaip devices come delivered with 255 pre-defined GOs or in other words,
they are ex-factory delivered with a preloaded certified application program.

Copyright 2015, KNX Association page 3 of 13


2 Preparation & Test
2.1 Connect & Play
Install the FT232BL driver
Link: http://www.ftdichip.com/Drivers/VCP.htm
This will add a virtual com port to your computer
Use any serial terminal software, e.g. Serial Terminal from RealTerm
Link: http://realterm.sourceforge.net/
Connect the PCB with the PC via USB
Make sure all required jumpers are set correctly: please check the KIMaip documentation.
Screenshot:

Figure 1 Serial terminal software screenshot

Connect
Wire the device.
Open the serial terminal software (see Figure 1).
Click tab page Port.
Select the virtual com port that has been added.
Put its settings to 38400, 8, 1, none.
Play
Click tab page Send.
Make sure to set EOL (end of line) settings to +CR.
Type e.g. 03 61 0002 in the top entry field and click Send ASCII. This command will make the
device send back its individual address. This is a perfect method to test the principal working of the
test setup.

Copyright 2015, KNX Association page 4 of 13


Another command that could be used in this context is e.g.: 03 61 0003 in order to check the
programming mode. Consult the Tapko Technologies KIMaip related documentation for more
details and/or other commands.

2.2 ETS Project


The purpose is to use an ETS project for testing both the sensor and actuator examples, which are further
down explained in this document.
Download the generic KIMaip based ETS project file from this URL: www.tapko.de.
Make e.g. the following associations:
- Group Object 0: LED 1 1 bit with e.g. Group Address 0/0/1
- Group Object 1: LED 2 1 bit with e.g. Group Address 0/0/2

Screenshot:

Figure 2 KIMaip group object settings

Copyright 2015, KNX Association page 5 of 13


2.3 Use the serial terminal SW to check the device configuration
Connect via USB.
Send the following ASCII commands:
03 31 0000 to check the configuration of GO nr. 0
o expected response: 05 32 0000 00 D7
o In this example: type = 1 bit, flags = U,T, W, C, priority = low
05 38 0000 00 01 to check the first associated GA of GO nr. 0
o expected response: 07 39 0000 00 01 0001
o In this example: 0/0/1 is indeed the sending GA for GO nr. 0

Check the Tapko Technologies documentation for more details.

2.4 Use the serial terminal SW in order to simulate the AM


Connect via USB.
For the Sensor example:
Send e.g. the following ASCII command: 04 10 0000 01 to set the value of Group Object 0 to 1.
Expected result: a A_GroupValue_Write telegram sent from the KIMaip the bus

For the Actuator example:


Send an A_GroupValue_Write telegram to the bus with e.g. ETS Group Monitor.
Expected result: an indication message from the KIMaip in the terminal SW monitor, e.g. 04 20
0000 01

Check the Tapko Technologies documentation for more details.

Copyright 2015, KNX Association page 6 of 13


3 Tapko Technologies KIMaip based solutions
3.1 Hardware Block Diagram

KIMaip
(*)
+Bus pin 10 SDA pin 2
(*)
-Bus pin 9 SCL pin 3 External C
(**) DR pin 1

Key pin 12 VCC pin 16

LED pin 13 GND pin 9

(*) Pull-ups might be required


(**) DR: data ready - optional

Figure 3 Hardware Block Diagram

Details:
Interface: IC based ASCII protocol via SDA (pin 2) and SCL (pin 3).
For more details about the ASCII protocol, please consult the Tapko Technologies related KIMaip
documentation. URL: www.tapko.de

Important:
Depending on the external C it might be required to use pull-up resistors for SDA and SCL,
please carefully check the documentation of your external C.

3.2 Texas Instruments MSP-EXP430FR5739 Microcontroller


The main reason for choosing this specific microcontroller is the fact that the IDE (compiler/loader) is
free of charge at least for the limited edition, i.e. source code = max 8K.
The IDE is one of the IAR Starter kits, for more details, see: www.iar.com

Copyright 2015, KNX Association page 7 of 13


3.3 TI C used as KNX Sensor & KNX Actuator

VCC
GND
P1.7

P1.6

MSP-EXP430FR5739

+Bus pin 10 SDA pin 2

-Bus pin 9 SCL pin 3

Key pin 12 VCC pin 16

LED pin 13 GND pin 9

KIMaip

Figure 4 TI C used as KNX Sensor & KNX Actuator

Details:
TI C pin P1.6 serves as IC SDA port, which is connected to the KIMaip SDA.
TI C pin P1.7 serves as IC SCL port, which is connected to the KIMaip SCL.
A simple debounce routine is implemented in order to detect the onboard push button P4.1 events.
For each push button event an ASCII command is sent to the KIMaip.
A simple IC read routine is implemented in order to capture and process ASCII commands from
the KIMaip.
Depending on the actual content of each received ASCII command the LED2 will either be
switched on or off.
Important note:
Since IC is based on a master-slave principle, where KIMaip is always the slave, the best practice
for using it as actuator is to involve the Data Ready pin in order to indicate bus events to the
master. TI C pin 3.7 has been used for this purpose, see source code.

Copyright 2015, KNX Association page 8 of 13


3.3.1 Example: The TI C source code, i.e. main.c
#include "msp430fr5739.h"

char command_0[] = {0x04,0x10,0x00,0x00,0x00};


char command_1[] = {0x04,0x10,0x00,0x00,0x01};
char *snd_msg;
char rcv_msg[5];
int snd_cntr;
int rcv_cntr;
int S1;
int S2;
int LED1;
int LED2;

void EnableSwitches(void)
{
P4IFG = 0; // P4 IFG cleared
P4IE = BIT0+BIT1; // P4 interrupt enabled
}

void DisableSwitches(void)
{
P4IFG = 0; // P4 IFG cleared
P4IE &= ~(BIT0+BIT1); // P4 interrupt disabled
P4IFG = 0; // P4 IFG cleared
}

void StartDebounceTimer(void)
{
// Debounce time = 1500 * 1/8000 = ~200ms
TA1CCTL0 = CCIE; // TACCR0 interrupt enabled
TA1CCR0 = 1500;
TA1CTL = TASSEL_1 + MC_1; // ACLK, up mode
}

void setLEDs(void)
{
// Enable LED1 & LED2
PJOUT &= ~(BIT0+BIT1);
PJDIR |= BIT0+BIT1;

// Clear both LEDs


PJOUT = 0x00;

LED1 = 0;
LED2 = 0;
}

void setSwitches(void)
{
// Set up switches S1 & S2
// P4.0 and P4.1 are configured as switches

Copyright 2015, KNX Association page 9 of 13


// Port 4 has only two pins
P4OUT |= BIT0+BIT1; // configure pullup resistor
P4DIR &= ~(BIT0+BIT1); // direction = input
P4REN |= BIT0+BIT1; // enable pullup resistor
P4IES &= ~(BIT0+BIT1); // low to high transition interrupt
P4IE = BIT0+BIT1; // interrupt enabled
P4IFG = 0; // IFG cleared

S1 = 0;
S2 = 0;
}

void setClock(void)
{
CSCTL0_H = 0xA5; // Unlock register
CSCTL1 = 0x0060u; // Set max. DCO setting = 8MHz
CSCTL2 = 0x0133u; // set ACLK = VLO; MCLK = DCO
CSCTL3 = 0x0000u; // no dividers
CSCTL0_H = 0x01; // Lock register
}

void setI2C(void)
{
UCB0CTLW0 |= UCSWRST; // keep in reset status
UCB0CTLW0 |= 0x0E00u; // I2C master mode
UCB0BRW = 0x0014u; // Set baudrate = 8MHz/20 = 400KHz
UCB0I2CSA = 0x08; // Set slave address
// Configure I2C pins
P1SEL1 |= 0xC0;
P1SEL0 &= ~0xC0;
// P1.7 = SCL
// P1.6 = SDA
UCB0CTLW0 &= ~UCSWRST; // release from reset status

UCB0IE |= UCTXIE; // Enable TX interrupt


UCB0IE |= UCRXIE; // Enable RX interrupt
UCB0IE |= UCNACKIE; // Enable NACK interrupt
UCB0IE |= UCSTPIE; // Enable STOP interrupt
UCB0IE |= UCSTTIE; // Enable START interrupt
}

void sendI2C(void)
{
if(S2==0)
snd_msg = command_0;
else
snd_msg = command_1;

snd_cntr = 0;

if(UCB0STATW&UCBBUSY)
setI2C();

Copyright 2015, KNX Association page 10 of 13


UCB0CTLW0 |= UCTR; // set as transmitter
UCB0CTLW0 |= UCTXSTT; // generate start condition
}

void setDR(void)
{
// set up P3.7 to capture data ready signal
P3SEL1 &= BIT7;
P3SEL0 &= ~BIT7;
P3DIR &= ~BIT7; // direction = input
P3REN |= BIT7; // enable pullup/pulldown resistor
P3IES &= ~BIT7; // low to high transition interrupt
P3IE = BIT7; // interrupt enabled
P3IFG &= ~BIT7; // IFG cleared
}

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog

setLEDs();
setSwitches();
setClock();
setI2C();
setDR();

while(1)
{
__bis_SR_register(LPM0_bits + GIE); // low power mode0 + general interupt
__no_operation(); // For debugger
}
}

//**********************************************************************
//* Port 4 ISR for S1 & S2
//**********************************************************************
#pragma vector=PORT4_VECTOR
__interrupt void Port_4(void)
{
switch(__even_in_range(P4IV,0x04))
{
case 0x02: // P4.0 interrupt = S1
break;

case 0x04: // P4.1 interrupt = S2


switch(S2)
{
case 0:
PJOUT |= 0x01;
S2 = 1;
break;

Copyright 2015, KNX Association page 11 of 13


case 1:
PJOUT &= ~0x01;
S2 = 0;
break;
}
sendI2C();
DisableSwitches();
StartDebounceTimer();
break;

default:
break;
}
}

//**********************************************************************
//* Timer A1 ISR for debounce Timer
//**********************************************************************
#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer1_A0_ISR(void)
{
TA1CCTL0 = 0;
TA1CTL = 0;
EnableSwitches();
}

//**********************************************************************
//* USCI B0 ISR for RX
//**********************************************************************
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
{
switch(__even_in_range(UCB0IV,0x18))
{
case 0x04: // NACK received
UCB0IFG &= ~UCSTPIFG;
UCB0IFG &= ~UCTXIFG0;
break;
case 0x06: // START received
UCB0IFG &= ~UCSTTIFG;
UCB0IFG &= ~UCTXIFG0;
break;
case 0x08: // STOP received
UCB0IFG &= ~UCSTPIFG;
UCB0IFG &= ~UCTXIFG0;
break;
case 0x16:
UCB0IFG &= ~UCRXIFG0;
rcv_msg[rcv_cntr++] = UCB0RXBUF;
if(rcv_cntr == 5)
{
if(rcv_msg[2]==0 && rcv_msg[3]==0)

Copyright 2015, KNX Association page 12 of 13


if(rcv_msg[4])
PJOUT |= 0x02;
else
PJOUT &= ~0x02;

UCB0CTLW0 |= UCTXSTP; // I2C stop condition


}
break;
case 0x18:
if(snd_cntr<5)
{
UCB0TXBUF = *(snd_msg+snd_cntr++);
}
else
{
UCB0CTLW0 |= UCTXSTP; // I2C stop condition
UCB0IFG &= ~UCTXIFG0;
}
break;
default: break;
}
}

//**********************************************************************
//* Port 3 ISR for Data Ready
//**********************************************************************
#pragma vector=PORT3_VECTOR
__interrupt void Port_3(void)
{
switch(__even_in_range(P3IV,0x10))
{
case 0x10: // P3.7 interrupt
P3IFG &= ~BIT7;

if(UCB0STATW&UCBBUSY)
setI2C();

UCB0CTLW0 &= ~UCTR; // set as receiver


UCB0CTLW0 |= UCTXSTT; // generate start condition
rcv_cntr = 0;
break;
default:
break;
}
}

Copyright 2015, KNX Association page 13 of 13


KNX Device Development

Implementation examples for:


- BAOS in combination with Arduino UNO
Contents
1 About the Weinzierl Engineering KNX BAOS devices ...................................................... 3
1.1 Needed software ............................................................................................................. 3
1.2 About the Weinzierl KNX BAOS Starter Kit ................................................................. 3
2 Preparation & Test ................................................................................................................ 4
2.1 Connect & Play ............................................................................................................... 4
2.2 ETS Project ..................................................................................................................... 5
2.3 Use the terminal SW to check the device configuration ................................................. 7
2.4 Use the terminal SW in order to simulate the AM ......................................................... 7
3 Weinzierl Engineering BAOS based solutions .................................................................... 8
3.1 Hardware Block Diagram ............................................................................................... 8
3.2 Arduino UNO used as KNX Sensor ............................................................................. 10
3.2.1 Example 1 Sensor: The Arduino UNO Source Code..................................... 11
3.3 Arduino UNO used as KNX Actuator .......................................................................... 12
3.3.1 Example 2 Actuator: The Arduino UNO Source Code ................................. 13

Copyright 2015, KNX Association page 2 of 13


1 About the Weinzierl Engineering KNX BAOS devices
1.1 Needed software
Installed ETS4 software (Demo is sufficient).
FTDI FT232RL driver.
Any serial terminal software.
Arduino IDE.

1.2 About the Weinzierl KNX BAOS Starter Kit


This product is based on the Weinzierl KNX BAOS device, details:
KNX Profile Class = System 7, see Error! Reference source not found..
Interface = serial asynchronous
FT1.2 based protocol, see Error! Reference source not found..
The Weinzierl KNX BAOS Starter Kit contains:
1 development board (PCB)
1 KNX BAOS 820 Device
1 KNX BAOS 822 Device
1 Power Supply (9 V)
KNX BAOS devices come delivered with 250 pre-defined GOs or in other words, they are ex-
factory delivered with a preloaded certified application program.

Copyright 2015, KNX Association page 3 of 13


2 Preparation & Test
2.1 Connect & Play
Install the FT232RL driver
Link: http://www.ftdichip.com/Drivers/VCP.htm
This will add a virtual com port to your computer
Use any serial terminal software, e.g. Serial Terminal from RealTerm
Link: http://realterm.sourceforge.net/
Connect the PCB with the PC via USB
Screenshot:

Figure 1 Serial Terminal screenshot

Connect
Wire the device.
Open the serial terminal software (see Figure 1).
Click tab page Port.
Select the virtual com port that has been added.
Put its settings to 19200, 8, 1, even.
Play
Click tab page Send.
Type e.g. 0x10,0x40,0x40,0x16 in the top entry field and click Send Numbers. This command
will reset the device. The device confirms by sending an FT1.2 ACK (0xE5). This is a perfect
method to test the principal working of the test setup.

Copyright 2015, KNX Association page 4 of 13


2.2 ETS Project
The purpose is to create an ETS project for testing both the sensor and actuator examples, which are
further down explained in this document.
Download the KNX BAOS Module 820 ETS product template from this URL: www.weinzierl.de.
Required Group Object setup for the Sensor example:
- Type of datapoint = DPT 01 Binary 1 bit
- Group Object flags = Communication & Transmit
Required Group Object setup for the Actuator example:
- Type of datapoint = DPT 01 Binary 1 bit
- Group Object flags = Communication & Write
Screenshots:

Figure 2 ETS KNX BAOS parameter settings

Copyright 2015, KNX Association page 5 of 13


Figure 3 ETS KNX BAOS group object settings

Copyright 2015, KNX Association page 6 of 13


2.3 Use the serial terminal SW to check the device configuration
Connect via USB.
Send the following GetServerItem.Req command, e.g.:
0x68,0x05,0x05,0x68,0x73,0xF0,0x01,0x01,0x01,0x66,0x16 (e.g. after reset).
Expected result: GetServerItem.Res message from the BAOS in the terminal SW monitor, e.g. 68 0D
0D 68 F3 F0 81 01 01 01 06 00 00 C5 08 02 01 3D 16. This will be repeated three times because the
serial terminal SW doesnt send the FT1.2 ACKs (0xE5).

Check the Weinzierl Engineering documentation for more details.

2.4 Use the serial terminal SW in order to simulate the AM


Connect via USB.
For the Sensor example:
Send the following alternating commands, e.g.:
o 0x68,0x08,0x08,0x68,0x73,0xF0,0x06,0x01,0x01,0x01,0x31,0x01,0x9E,0x16
o 0x68,0x08,0x08,0x68,0x53,0xF0,0x06,0x01,0x01,0x01,0x31,0x00,0x7D,0x16
Expected result: A_GroupValue_Write telegrams sent from the BAOS to the bus.

For the Actuator example:


Send an A_GroupValue_Write telegrams to the bus with e.g. ETS Group Monitor.
Expected result: indication messages from the BAOS in the serial terminal SW monitor, e.g. 68 08
08 68 D3 F0 C1 01 01 01 81 01 09 16. This will be repeated three times because the serial terminal
SW doesnt send the FT1.2 ACKs (0xE5).

Check the Weinzierl Engineering documentation for more details.

Copyright 2015, KNX Association page 7 of 13


3 Weinzierl Engineering BAOS based solutions
3.1 Hardware Block Diagram

BAOS

+BUS TX
External C
-BUS RX

KEY VCC

LED GND

Galvanic Separation

Figure 4 Hardware Block Diagram

Details:
Interface: FT1.2 based protocol via TX and RX.
For more details about the serial protocol, please consult the Weinzierl Engineering related BAOS
documentation. URL: www.weinzierl.de

3.2 Arduino Microcontrollers


For the external microcontroller, we opted for the Arduino open source electronics prototyping platform.
More information can be found via this URL: arduino.cc
The main reason for choosing Arduino is the fact that the Arduino Software (compiler/loader) is free of
charge.
Several types of Arduino microcontrollers exist; we have used Arduino UNO.
Install the Arduino IDE:
Link: arduino.cc
Screenshot

Copyright 2015, KNX Association page 8 of 13


Figure 5 Arduino IDE

Copyright 2015, KNX Association page 9 of 13


3.3 Arduino UNO used as KNX Sensor

VCC

VCC
I/O pin 4
GND

10K
TX pin 1

Arduino UNO

Push
Button

GND
+BUS TX
RX
-BUS

KEY VCC

LED GND

BAOS

Figure 6 Arduino UNO used as KNX Sensor

Details:
Arduino UNO pin 4 serves as input port in order to capture push button events.
Arduino UNO pin 1 serves as serial transmit port, which is connected to RX of the BAOS.
A simple debounce routine is implemented in order to detect the push button events.
For each push button event an ASCII command is sent to the BAOS.

Copyright 2015, KNX Association page 10 of 13


3.3.1 Example 1 Sensor: The Arduino UNO source code
const int msg_odd_0[14] = {0x68,0x08,0x08,0x68,0x73,0xF0,0x06,0x01,0x01,0x01,0x31,0x00,0x9D,0x16};
const int msg_odd_1[14] = {0x68,0x08,0x08,0x68,0x73,0xF0,0x06,0x01,0x01,0x01,0x31,0x01,0x9E,0x16};
const int msg_even_0[14] = {0x68,0x08,0x08,0x68,0x53,0xF0,0x06,0x01,0x01,0x01,0x31,0x00,0x7D,0x16};
const int msg_even_1[14] = {0x68,0x08,0x08,0x68,0x53,0xF0,0x06,0x01,0x01,0x01,0x31,0x01,0x7E,0x16};

const int buttonPin = 4;


int buttonState = HIGH;
int KNXoutput = LOW;
long lastDebounceTime = 0;
long debounceDelay = 200;
int TM = 0;
int i = 0;

void setup()
{
pinMode(buttonPin, INPUT);
Serial.begin(19200,SERIAL_8E1);
}

void loop()
{
if ((millis() - lastDebounceTime) > debounceDelay)
{
buttonState = digitalRead(buttonPin);
lastDebounceTime = millis();
TM = 1;
}
if ((TM == 1) && (buttonState == LOW))
{
if (KNXoutput == LOW)
{
KNXoutput = HIGH;
for(i=0; i < 14; i++)
Serial.write(msg_odd_1[i]);
}
else
{
KNXoutput = LOW;
for(i=0; i < 14; i++)
Serial.write(msg_even_0[i]);
}
buttonState = HIGH;
TM = 0;
}
}

Copyright 2015, KNX Association page 11 of 13


3.4 Arduino UNO used as KNX Actuator

VCC
I/O pin 2
GND

RX pin 0 470

Arduino UNO

LED

+BUS TX
RD GND
-BUS

KEY VCC

LED GND

BAOS

Figure 7 Arduino UNO used as KNX Actuator

Details:
Arduino UNO pin 2 serves as simulation of a KNX binary output channel by means of a LED.
Arduino UNO pin 0 serves as serial receive port, which is connected to TX of the BAOS.
A simple serial port read routine is implemented in order to capture and process ASCII commands
from the BAOS.
Depending on the actual content of each received ASCII command the LED will either be switched
on or off.

Remark:
In the source code (see further) an acknowledge byte (0xE5) is sent after each received BAOS
message. This obviously is only effective if the Arduino UNO pin 1 (TX) is connected to RD of the
BAOS (which is not the case in the above figure).

Copyright 2015, KNX Association page 12 of 13


3.4.1 Example 2 Actuator: The Arduino UNO source code
const int ledPin = 2;
int incomingByte = 0;

const int maxLen = 20;


int msgState = 0;
int msgCntr = 0;
int msgLen = 0;
int msg[maxLen];

void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(19200 , SERIAL_8E1);
}

void loop()
{
if (Serial.available())
{
incomingByte = Serial.read();

if(msgState==0 && incomingByte==0x68)


{
msgState = 1;
msgCntr = 0;
msgLen = 0;

for(int i=0;i<maxLen;i++)
msg[i] = 0;
}
if(msgState==1)
{
msg[msgCntr++] = incomingByte;

if(msgCntr==2)
msgLen = incomingByte + 6;

if(msgCntr==msgLen)
{
if(incomingByte==0x16)
{
msgState = 0;

if(msg[5]==0xF0 && msg[7]==0x01)


digitalWrite(ledPin, msg[11]);

Serial.write(0xE5); //ACK
}
}
}
}
}

Copyright 2015, KNX Association page 13 of 13


KNX Device Development

Implementation examples for:


- BAOS in combination with Texas Instruments MSP-
EXP430FR5739
Contents
1 About the Weinzierl Engineering KNX BAOS devices ...................................................... 3
1.1 Needed software ............................................................................................................. 3
1.2 About the Weinzierl KNX BAOS Starter Kit ................................................................. 3
2 Preparation & Test ................................................................................................................ 4
2.1 Connect & Play ............................................................................................................... 4
2.2 ETS Project ..................................................................................................................... 5
2.3 Use the serial terminal SW to check the device configuration ....................................... 7
2.4 Use the serial terminal SW in order to simulate the AM ................................................ 7
3 Weinzierl Engineering BAOS based solutions .................................................................... 8
3.1 Hardware Block Diagram ............................................................................................... 8
3.2 Texas Instruments MSP-EXP430FR5739 Microcontroller ............................................ 8
3.3 TI C used as KNX Sensor & KNX Actuator ................................................................ 9
3.3.1 Example: The TI C source code, i.e. main.c ................................................... 10

Copyright 2015, KNX Association page 2 of 13


1 About the Weinzierl Engineering KNX BAOS devices
1.1 Needed software
Installed ETS4 software (Demo is sufficient).
FTDI FT232RL driver.
Any serial terminal software.
Arduino IDE.

1.2 About the Weinzierl KNX BAOS Starter Kit


This product is based on the Weinzierl KNX BAOS device, details:
KNX Profile Class = System 7
Interface = serial asynchronous
FT1.2 based protocol
The Weinzierl KNX BAOS Starter Kit contains:
1 development board (PCB)
1 KNX BAOS 820 Device
1 KNX BAOS 822 Device
1 Power Supply (9 V)
KNX BAOS devices come delivered with 250 pre-defined GOs or in other words, they are ex-
factory delivered with a preloaded certified application program.

Copyright 2015, KNX Association page 3 of 13


2 Preparation & Test
2.1 Connect & Play
Install the FT232RL driver
Link: http://www.ftdichip.com/Drivers/VCP.htm
This will add a virtual com port to your computer
Use any serial terminal software, e.g. Serial Terminal from RealTerm
Link: http://realterm.sourceforge.net/
Connect the PCB with the PC via USB
Screenshot:

Figure 1 Serial Terminal screenshot

Connect
Wire the device.
Open the serial terminal software (see Figure 1).
Click tab page Port.
Select the virtual com port that has been added.
Put its settings to 19200, 8, 1, even.
Play
Click tab page Send.
Type e.g. 0x10,0x40,0x40,0x16 in the top entry field and click Send Numbers. This command
will reset the device. The device confirms by sending an FT1.2 ACK (0xE5). This is a perfect
method to test the principal working of the test setup.

Copyright 2015, KNX Association page 4 of 13


2.2 ETS Project
The purpose is to create an ETS project for testing both the sensor and actuator examples, which are
further down explained in this document.
Download the KNX BAOS Module 820 ETS product template from this URL: www.weinzierl.de.
Required Group Object setup for the Sensor example:
- Type of datapoint = DPT 01 Binary 1 bit
- Group Object flags = Communication & Transmit
Required Group Object setup for the Actuator example:
- Type of datapoint = DPT 01 Binary 1 bit
- Group Object flags = Communication & Write
Screenshots:

Figure 2 ETS KNX BAOS parameter settings

Copyright 2015, KNX Association page 5 of 13


Figure 3 ETS KNX BAOS group object settings

Copyright 2015, KNX Association page 6 of 13


2.3 Use the serial terminal SW to check the device configuration
Connect via USB.
Send the following GetServerItem.Req command, e.g.:
0x68,0x05,0x05,0x68,0x73,0xF0,0x01,0x01,0x01,0x66,0x16 (e.g. after reset).
Expected result: GetServerItem.Res message from the BAOS in the terminal SW monitor, e.g. 68 0D
0D 68 F3 F0 81 01 01 01 06 00 00 C5 08 02 01 3D 16. This will be repeated three times because the
serial terminal SW doesnt send the FT1.2 ACKs (0xE5).

Check the Weinzierl Engineering documentation for more details.

2.4 Use the serial terminal SW in order to simulate the AM


Connect via USB.
For the Sensor example:
Send the following alternating commands, e.g.:
o 0x68,0x08,0x08,0x68,0x73,0xF0,0x06,0x01,0x01,0x01,0x31,0x01,0x9E,0x16
o 0x68,0x08,0x08,0x68,0x53,0xF0,0x06,0x01,0x01,0x01,0x31,0x00,0x7D,0x16
Expected result: A_GroupValue_Write telegrams sent from the BAOS to the bus.

For the Actuator example:


Send an A_GroupValue_Write telegrams to the bus with e.g. ETS Group Monitor.
Expected result: indication messages from the BAOS in the serial terminal SW monitor, e.g. 68 08
08 68 D3 F0 C1 01 01 01 81 01 09 16. This will be repeated three times because the serial terminal
SW doesnt send the FT1.2 ACKs (0xE5).

Check the Weinzierl Engineering documentation for more details.

Copyright 2015, KNX Association page 7 of 13


3 Weinzierl Engineering BAOS based solutions
3.1 Hardware Block Diagram

BAOS

+BUS TX
External C
-BUS RX

KEY VCC

LED GND

Galvanic Separation

Figure 4 Hardware Block Diagram

Details:
Interface: FT1.2 based protocol via TX and RX.
For more details about the serial protocol, please consult the Weinzierl Engineering related BAOS
documentation. URL: www.weinzierl.de

3.2 Texas Instruments MSP-EXP430FR5739 Microcontroller


The main reason for choosing this specific microcontroller is the fact that the IDE (compiler/loader) is
free of charge at least for the limited edition, i.e. source code = max 8K.
The IDE is one of the IAR Starter kits, for more details, see: www.iar.com

Copyright 2015, KNX Association page 8 of 13


3.3 TI C used as KNX Sensor & KNX Actuator

VCC
GND
P2.0

P2.1

MSP-EXP430FR5739

+BUS TX

-BUS RX

KEY VCC

LED GND

BAOS

Figure 5 TI C used as KNX Sensor & KNX Actuator

Details:
TI C pin P2.1 serves as serial receive port, which is connected to TX of the BAOS.
TI C pin P2.0 serves as serial transmit port, which is connected to RX of the BAOS.
A simple debounce routine is implemented in order to detect the onboard push button events.
For each onboard push button event an ASCII command is sent to the BAOS.
A simple serial port read routine is implemented in order to capture and process ASCII commands
from the BAOS.
Depending on the actual content of each received ASCII command the onboard LED2 will either
be switched on or off.

Copyright 2015, KNX Association page 9 of 13


3.3.1 Example: The TI C source code, i.e. main.c
//BAOS sensor + actuator

#include "msp430fr5739.h"
#include <string.h>

#define MAXLEN 50

const char command_0[] = {0x68,0x08,0x08,0x68,0x73,0xF0,0x06,0x01,0x01,0x01,0x31,0x00,0x9D,0x16};


const char command_1[] = {0x68,0x08,0x08,0x68,0x53,0xF0,0x06,0x01,0x01,0x01,0x31,0x01,0x7E,0x16};

char rcv_buffer[MAXLEN];
int rcv_cntr;
char rcv_char;
int msgState;
int S1;
int S2;
int LED1;
int LED2;

void EnableSwitches(void)
{
P4IFG = 0; // P4 IFG cleared
P4IE = BIT0+BIT1; // P4 interrupt enabled
}

void DisableSwitches(void)
{
P4IFG = 0; // P4 IFG cleared
P4IE &= ~(BIT0+BIT1); // P4 interrupt disabled
P4IFG = 0; // P4 IFG cleared
}

void StartDebounceTimer(void)
{
// Debounce time = 1500 * 1/8000 = ~200ms
TA1CCTL0 = CCIE; // TACCR0 interrupt enabled
TA1CCR0 = 1500;
TA1CTL = TASSEL_1 + MC_1; // ACLK, up mode
}

void setLEDs(void)
{
// Enable LED1 & LED2
PJOUT &= ~(BIT0+BIT1);
PJDIR |= BIT0+BIT1;

// Clear both LEDs


PJOUT = 0x00;

LED1 = 0;
LED2 = 0;
}

void setSwitches(void)
{
// Set up switches S1 & S2
// P4.0 and P4.1 are configured as switches
// Port 4 has only two pins

Copyright 2015, KNX Association page 10 of 13


P4OUT |= BIT0+BIT1; // Configure pullup resistor
P4DIR &= ~(BIT0+BIT1); // Direction = input
P4REN |= BIT0+BIT1; // Enable pullup resistor
P4IES &= ~(BIT0+BIT1); // Lo/Hi edge interrupt
P4IE = BIT0+BIT1; // Interrupt enabled
P4IFG = 0; // IFG cleared

S1 = 0;
S2 = 0;
}

void setClock(void)
{
CSCTL0_H = 0xA5; // Unlock register
CSCTL1 |= DCOFSEL0 + DCOFSEL1; // Set max. DCO setting
CSCTL2 = SELA_1 + SELS_3 + SELM_3; // set ACLK = vlo; MCLK = DCO
CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0; // set all dividers
CSCTL0_H = 0x01; // Lock register
}

void setUart(void)
{
// Configure UART pins
P2SEL1 |= BIT0 + BIT1;
P2SEL0 &= ~(BIT0 + BIT1);
// Configure UART 0
UCA0CTL1 |= UCSWRST; // keep in reset mode
UCA0CTL1 = 0x80; // SMCLK
UCA0CTL0 = 0xc0; // parity enabled + even parity
UCA0BR0 = 26; //19200 baud
UCA0BR1 = 0;
UCA0MCTLW |= 0xb601; // BRCLK=8000000 UCOS16=1 (UCBR=26) UCBRF=0 UCBRS=0xb6

UCA0CTL1 &= ~UCSWRST; // release from reset mode


UCA0IE |= UCRXIE; // Enable RX interrupt
}

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog

setLEDs();
setSwitches();
setClock();
setUart();

while(1)
{
__bis_SR_register(LPM4_bits + GIE); // low power mode4 + general interupt
__no_operation(); // For debugger
}
}

//**********************************************************************
//* Port 4 ISR for S1 & S2
//**********************************************************************
#pragma vector=PORT4_VECTOR
__interrupt void Port_4(void)
{
switch(__even_in_range(P4IV,0x04))
{

Copyright 2015, KNX Association page 11 of 13


case 0x02: // P4.0 interrupt = S1
break;

case 0x04: // P4.1 interrupt = S2


switch(S2)
{
case 0:
for(int i=0; i < 14; i++)
{
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = command_1[i];
}
PJOUT |= 0x01;
S2 = 1;
break;
case 1:
for(int i=0; i < 14; i++)
{
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = command_0[i];
}
PJOUT &= ~0x01;
S2 = 0;
break;
}

DisableSwitches();
StartDebounceTimer();
break;

default:
break;
}
}

//**********************************************************************
//* Timer A1 ISR for debounce Timer
//**********************************************************************
#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer1_A0_ISR(void)
{
TA1CCTL0 = 0;
TA1CTL = 0;
EnableSwitches();
}

//**********************************************************************
//* USCI (universal serial communication interfce) A0 ISR for RX
//**********************************************************************
#pragma vector = USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,0x02))
{
case 0x02: // UCRXIFG = P2.1 = RX
rcv_char = UCA0RXBUF;

switch(rcv_char)
{
case 0x68:
if(msgState == 0)

Copyright 2015, KNX Association page 12 of 13


{
msgState = 1;
rcv_cntr = 0;
}
if(rcv_cntr == 2)
msgState = 2;
break;
case 0x16:
if((msgState == 2) && (rcv_cntr == rcv_buffer[0]+3))
{
if(rcv_buffer[3] == 0xf0 && rcv_buffer[5] == 0x01)
if(rcv_buffer[9])
PJOUT |= 0x02;
else
PJOUT &= ~0x02;

strcpy(rcv_buffer, "");
rcv_cntr = 0;
msgState = 0;
}
break;
default:
if(msgState > 0 && rcv_cntr < MAXLEN)
rcv_buffer[rcv_cntr++] = rcv_char;
break;
}
break;

default: break;
}
}

Copyright 2015, KNX Association page 13 of 13