Developing new smart home appliances based on bus interface modules (BIMs) is comfortable not only because of the provided firmware and application programming interface, or the hardware for the easy KNX-bus connection. Using the provided development toolpackage also saves the developer from creating the application program from scratch.
The BIM-Tools include the BIM Wizard, the tool which prepares the code, namely the declarations of the KNX communication objects are automatically generated.
In a former article I’ve presented how to set up the development toolpackage (delivered by Opternus) and get ready to develop and download the first application program.
The first step towards developing application programs for BIMs is creating the project using the BIM Wizard. Through this step, the needed , BIM related header files will be automatically included in the project, and the code for declaring the communication objects is also generated.
Step 1: Open the BIM Tools and click on the BIM Wizard icon or choose from the main menu Tools\BIM Wizard. Select the used family member, and set the path where the project should be saved. Click “next>>”.
Step 2: Define the needed KNX communication objects. Give a name to each object, and set the data type for each. An example is shown on the figure below. Click “next>>”.
Step 3: Now choose the number of entries in the address and association tables. The minimum number of entries has already been calculated, more entries can be added by using the arrows, or writing larger numbers into the list boxes. The configuration may be saved in an XML file, by clicking on “Save Conf”. Click on “Create” to create the project.
Step 4: Open the new project using the IAR Embedded Workbench and implement the application specific program.
The first application program
When the project, created with the BIM Wizard, is opened with IAR Embedded Workbench, the following files are already included in the workspace (not exclusively):
- BIM_M13x.h, header file containing defines and data structure definitions which are specific for the BIM M13x systems. (e.g. definition of the TIMER strucutre, system specific time constants: MSEC500)
- config.xml, configuration file for adding the ‘load controls’ and making the memory conversion in the post-build phase
- main.c, containing the application program
- tables.c, contains the address table, association table and communication object table (group addresses are defined here)
- user.h, defines for timers and communication objects
- Configure the hardware pins to be in output mode.
- Disable the use of pull-up resistors.
- Define one timer.
- Modify the main() function, so that one hardware pin is activated for 1 seconds, then deactivated for 1 second.
BIM-Connector pin | Microcontroller pin |
1 | P71 |
5 | P73 |
7 | P70 |
9 | P75 |
11 | P72 |
13 | P77 |
15 | P74 |
19 | P76 |
25 | GND |
Step 1: The API provided by the BCU 2.5 operating system makes it possible to use timers in the application program. For this, the number of timers must be defined in the file user.h.
#define NUM_OF_TIMERS 1
In main.c a timer table must be declared. This can be done easily, as the structure of a timer, as well as the structure of the timer table have been defined in the BIM_M13x.h header file.
TIMER_TAB UserTimerTab;
In the application info block (a constant declared at the end of the main.c file) the application program gives some necessary information for the operating system. In this application info block, the declared timer table must also be mentioned:
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
};
Step 2: Initialize the user application timer table. The already created AppInit() function is just perfect to do this:
void AppInit(void)
{
// init the user application timer table
U._TmInit(NUM_OF_TIMERS);
// after initialization a taskswitch must be done because
// the task switch is disabled at cstartup
FORCE_TASKSWITCH();
}
Step 3: Set the pins of PORT7 as output pins. Disable the pull-up resistors. Start the timer. Write the code, so that one pin is activated for one second and deactivated for one second.
void main (void)
{
// Do some initializations
AppInit();
int count = 0;
PM7 = 0x00; // pin modes
PU7 = 0x00; // disable pull-up resistors
U._TmStart(&UserTimerTab.Timers[0], SEC1); // SEC1 defined in BIM_M13x.h
// Start the main loop of the application program
// it will be interrupted every 3.3ms and
// continued after a complete system cycle
for(;;)
{
if ( U._TmIsExpired( &UserTimerTab.Timers[0] ) )
{
count = 1 – count;
U._TmStart(&UserTimerTab.Timers[0], SEC1);
}
if ( count )
{
P7 = 0x01;
}
else
{
P7 = 0x00;
}
}
}
Building the downloadable object file
To provide compatibility with ETS 3, the BIM operating system does a memory translation from bus addresses to the internal addresses of the microcontroller. That means that, for example, the start of the address table for the ETS is 0x0116 and in reality it is 0x8116 in the microcontroller.
To generate an S19 file that could be imported in an ETS 3 (manufacturer version) database entry, it is necessary to convert the memory and to add ‘load controls’. The memory conversion has to be done because, as mentioned above, the BIM operating system does a memory translation for ETS compatibility. Therefore a byte located at 0x8116 in the microcontroller has to be set at 0x0116 in the S19 file for bus download, because the BIM operating system will set it back to 0x8116.
The ‘load controls’ are necessary to control the processing of the address, association and communication object description table and of the application program.
- Using the S19 modifier provided by the BIM Tools.
- Using a post-build command in IAR Embedded Workbench.
I’ve chosen to use a post-build command, which is automatically executed by the development environment at the end of the release build process.
If the toolchain has been prepared as described in the former post, this post-build command should be already added in IAR Embedded Workbench. This setting can be checked by choosing Project/Options… from the main menu of the IAR Embedded Workbench. Choose ‘Build Actions’ from the list on the right in the ‘Options’ window, as shown in the picture below (if the ‘Build Actions’ item does not appear in your list, it is very probable that your IAR Embedded Workbench limited evaluation license has been expired).
On my machine the Post-build command line is:
“C:\Program Files\Siemens AG\BIM Tools\aioc.exe” -t modifier –targs “KNX_LightControl” “$PROJ_DIR$\config.xml” “$PROJ_DIR$\Release\Exe\KNX_LightControl.s19” “$PROJ_DIR$\Release\Exe\KNX_LightControl_mod.s19”
“Hint: in the config.xml file there is the following entry:
<PropertyCompare>
<ObjectIndex>00</ObjectIndex>
<PropertyID>4E</PropertyID>
<StartIndex>001</StartIndex>
<NumOfElements>1</NumOfElements>
<Data>010203040506</Data>
</PropertyCompare>
This entry tells the ETS to read the property PID_HARDWARE_TYPE and compare the value (the hardware type has 6 bytes) with the value specified in the config.xml entry. If the values doesn’t match the download will not continue. This feature can be used to ensure that only the right application program of one manufacturer is loaded in the right hardware. If you do not want to use this feature you can leave out the complete ‘PropertyCompare’ element, but keep in mind if you will develop a new product with the BIM the ETS will only check the manufacturer and will load the application program of your actual product in the new product which could possibly damage it.”
Now select Release in IAR Embedded Workbench and rebuild your project. In the Release folder of you project library, the new .s19 file will be created, which is ready to be downloaded via the KNX-bus to the new hardware.
Downloading the application program
The just created .s19 object file can be downloaded to the target system using the BIM Tools.
For that, connect your PC and the BIM M13x Evaluation Board to the KNX-Bus. To check if the connection is recognized by your PC, the ETS Connection Manager from the BIM Tools can be used:
Before the Evaluation Board (or any other BIM M13x family member) can be directly accessed over the bus, it needs to get a unique bus-address. To assign this unique address to the new component, use the Connectionless Mode (Main menu: Connection/Connect…).
If the connection succeeds, choose the Addressing option (Main menu: Connection/Addressing).
Find your evaluation board (or BIM) via the programming button. Activate the programming button on your device (red LED is switched on), and click on ‘Get Devices in Programming Mode’.
If the new device has been found (listed at Available Devices), enter a new unique address (e.g. 15.15.19) in the New Address field and click on ‘Set Device in Programming Mode’. Now your Evaluation Board has its unique bus-address.
Now, the connection in Connectionless Mode must be terminated, so that your PC can access directly the EVB (or BIM). To do this, use the Device Connection Mode. The programming-button still needs to be activated on the Bus Interface Module / EVB. Select the option Find via Programming Button. After a few seconds, the new address, that has just been assigned to the evaluation board, is listed. Select it, and click on Connect.
At this moment the PC is able to download the application program to the evaluation board. Click on ‘Download’ (Main menu: Connection/Download). In the downloader window choose ‘Open’ and select your newly created and modified .s19 file (ProjectName_mod.s19).
Click on ‘Download’ (Note: the evaluation board must be in programming mode throughout the download process). The application program is downloaded to the evaluation board. The download process lasts 30-60 seconds.
References
- The sources of the citations are different documents published by Opternus GmbH at http://www.opternus.com/en/siemens/knx-bus-interfacemodules/bim-m130-135.html, documents containing technical description of the BIM M13x systems.
- The source of the illustration representing the BIM Connector (JP2) (26 pin connector) is the website of Pacific Custom Cable Inc, http://www.pacificcable.com/
Add Comment