Home

BACHELORARBEIT Connecting an Arduino UNO to KNX

image

Contents

1. Display value of the object depending on its byte size YES Data arriving YES Read value_obj_2 over UART UART Mode_READ ARUDINO code Num_byte s arriving Initialize serial communication Read num_bytes from PC Send num_bytes to BIM Initialize variables Display num bytes command arriving Read command from PC Send commant to BIM num_bytes arriving Display command Read value_obj from PC Send value_obj to BIM object arriving Display value obj Read object from PC Send object to BIM 1 Display object 2 YES arriving YES Read value_obj_1 from PC Send value_obj 1 to BIM YES Data arriving YES Read value obj 2 from PC Send value obj 2 to BIM NO 1 Num byte 4 NO Data arriving Read value_obj_ 2 from PC Send value_obj_2 to BIM Display value of the object depending on its byte size UART main ARUDINO code Initialize serial communication with BIM and PC Receive from from PC YES Read data Mode_read Receive from from BIM YES Read data Mode_read NO 7 4 Results As a result of the developing of everything exposed in this memory the following results were found On the BIM part Send data to Arduino related to a specified communication object available on SPI and UART c
2. Before data is sent users have to be careful of the way that transmission is configured because as can be seen in figure 5 0 bit is LSB and 7 bit is MSB Bit 7 6 5 4 3 2 1 0 02E E me OIII s Read Write RW R W R W R W R W R W RW R W Initial Value x Xx X X x x X X Undefined Figure 5 SPDR register structure 4 p 174 gt SPI Status Register SPSR This register indicates information about the transmission state As in previous registers explained all bits default value are 0 Although it is an 8 bit register five of these bits are non care state which means that it is not important if the value is O or 1 As figure 6 shows bits 7 and 6 only have read permission This is due to the fact that depending on the state of the transmission bits will be represented in one way or another and memory changes them when a particular event happens Bit 7 6 5 4 3 2 1 0 oe oa SPF woo I s Read Write R R R R R R R R W Initial Value 0 0 0 0 0 0 0 0 Figure 6 SPSR register structure 4 p 175 Three bits of interest are analyzed in the following SPIF when serial transfer is complete SPI flag is set WCOL sets when read and write actions in SPDR register try to access at the same time 4 pp 175 2 2 SPI software on Arduino Uno Arduino contains in its hardware more than one way to implement SPI communication As only Arduino Uno is used in this project this will be the only reference It is pos
3. It is also important that KNX association assure 100 compatibility of equipment 2 e aOR y Figure 11 KNX installation As can be seen in the image above KNX protocol has a distributed topology This type of system does not have a central unit Every unit is smart and knows what to do This makes the system more reliable because if one unit fails it does not affect the other units and the system can keep working 8 p 10 11 KNX also can be implemented on diverse transmission media each media can be used in combination with others These medias are Twisted Pair TP Power Line PL Radio Frequency RF and Ethernet IP 5 In this project the communication media used is twisted pair Twisted Pair TP 1 In this media KNX has a transmission speed defined as approximately 9600 bits s All products works on the same bus thats the way they exchange information Twisted pair is used to power devices and to transfer information but it is not available to power controlled devices as it can be with lights heating and so on Therefore there has to be a connection to electricity grids 3 3 Group Address It can be considered as a virtual wired among system components When a sensor and an actuator are required to make a function the same group address is assigned to both of them It does not exist strong rules about it except that maximum numbers or addresses are 28 000 The structure followed in this proj
4. our code Toggle Compile Break t Make de dd Download and Debug Figure 27 Toolbar for debugging and uploading code Once the code was debugged and downloaded it is time to make it running handling the following toolbar pa ur 4 _ EL A aLLS a a 4L Reset Step over Step into eS Break Step into Next Stop statement debupaine Run to cursor Figure 28 Toolbar for running code 15 p 3 4 3 Arduino software Arduino UNO is programmed on specific software It is very simple and intuitive to use After writing the code it is necessary to compile it by selecting the Verify button representing in the figure below If the code was correctly compiled it is required to upload it into the microcontroller For that it is necessary to select the type of the microcontroller used This is done on Tools gt Board gt Arduino Uno And also the USB port where the Arduino is connected Tools gt Serial Port gt COM XX Now the code can de uploaded into the board by selecting the bottom Upload represented in the figure below too ES siave Arduino 19 ELE Archivo Editar Sketch Herramientas Ayuda slave oid setup Upload Serial begin 9600 pinMode 3 OUTPUT Compile m void loop int command ant 0 int command 0 object 0 value obj 0 test int buffer command 30 buffer obj 30 buffer value obj 30 int i 0 int j 0 int z 0 int aux 0 Serial printl
5. 17 p 438 The aim is to have a baud rate of 9600 bauds It is known that hardware information such as fPRS 9 830 400 Hz We select TPSO1 1 TPSO1 1 That means fPRS has to be divided by 2 gt fXCLKO fPRS 2 307 200 Hz Now a parameter k is determined by bits MDLO4 MDLOS MDLO2 MDLO1 and MDLOO So the value selected is 10000 which gave us k 16 This means fXCLKO has to be divided by 16 With a result of 19 200 Hz As it is said on the datasheet the baud rate value is the output clock on the 5 bit counter divided by 2 Finally we have a 9600 bits s as baud rate value The register BRGCO has the value 11010000 in binary which is OxDO in hexadecimal which is the one to put in the function FT12Init 13 p 18 amp amp 17 p 438 439 gt ASIMO By this register the UART communication can be configured Address FF70H Afterreset 01H R W Symbol lt T gt 6 5 4 3 2 1 0 Aso powero txeo mxeo Pss eso co so Figure 14 ASIMO register in NEC78K0 KE2 microcontroller 17 p 436 Where POWERDO the value 1 is set so enables the clock on the UART It is necessary if activating UART is desired TXEO the value 1 enables the transmission O disables it RXEO the value 1 enables the transmission O disables it PS01 AND PS00 define the parity of the received and transmit data For no parity PS00 0 and PASO1 0 CLO 1 set 8 bit per character O set 7
6. value obj 3 value obj gt gt 24 value value obj value 1 value obj 1 value 2 value obj 2 value 3 value obj 3 SPI write Mode ARDUINO code Initialize serial communication Initialize variables NO Read command over SPI Read object over UART Read num_bytes over UART Read value_obj over SPI wait 20 ms NO YES Read value_obj_1 over SPI wait 20 ms NO YES Read value_obj_2 over SPI wait 20 ms Num_byte 4 NO YES Read value_obj_3 over SPI wait 20 ms Display value of the object depending on its byte size UART write Mode BIM code Funtions Send command over UART wait 200 ms object_change_send_data Send object over UART wait 200 ms Initialize variables Send num_bytes over UART wait 200 ms NO I lt YES NUM_OF_COM _OBJ Send value over UART Object i Ne changed NO Send value_1 over UART wait 200 ms Object 0 Object 1 Object 34 NO Assigns correct Assigns correct Assigns correct Send value_2 over UART values to values to values to wait 200 ms variables variables variables command command command object object object num_bytes num_bytes num_bytes B value object value object value object Num Bytes 4 command 0x80 object Send value_3 over UART NO value obj 1 value_obj gt gt 8 wait 200 ms value_obj_2 value_obj gt gt 16 value_obj_3 value_obj gt gt 24 value value_obj value_1 value_o
7. Master Out Slave In MOSI this line is the output from the master microcontroller and also the input to the SPI slave e Serial Clock SCK or SCLK the line is the serial clock line This line designates when data on the MISO and MOSI are valid e Slave Select SS is the chip select line There is one for each SPI device The master microcontroller imposes the SS line for when the device wants to communicate the signal has to be turned to low When the signal of this pin is high the slave device will not respond to any SPI communication on the other three pins 1 p 261 Once SPI protocol is known it is necessary to know how hardware connection must be joint As we see in figure 1 all pins must be connected in both microcontrollers to the same pin name Figure 1 SPI wire connection 1 4 2 UART communication UART is the acronym of Universal Asynchronous Receiver Transmitter As with SPI it is mainly used to communicate two or more integrated circuits The UART takes bytes of data and transmits the individual bits in a sequential way At the destination a second UART re assembles the bits into complete bytes Serial transmission of data is cheaper because only one wire is required in comparison with parallel communication which uses several wires Synchronization data transmission takes place by putting first start bit and then data bits are sent usually between five and nine always starting on the LSB and
8. must be removed from the connection The 20 MHz external oscillator must be mounted Figure 21 Oscillator mounted In the following figure it is presented how KNX bus which also powered the board and the connector from the MINICUBE2 must be mounted on EVB Figure 22 EVB connections Software Here is represented a small guide about how to get started with the software used on the KNX part Two programs are used to make this project work BimTools used mainly to create the communication objects AR Embedded Workbench have compiler and debugger functions to develop the code required Arduino is programmed on Arduino specific software explained in paragraph 3 1 BIM Tools Once the program is running the next step is create the communication objects required on a particular project Firstly BIM Wizard which is situated in the toolbar of the bottom should be clicked After that the screen in the figure below appears We have to specify which kind of BIM board we want to be programmed In this case it is the BIM M132 board Once this is decided the location and the name of the project want to be created have to be inserted After that to continue press on Next File Connection Tools Window Help a Folder will be created if it doesn t exist a Name for your BIM project a a D i Y B A ES Connect Disconnect Only active S19 Viewer 19Comparer ElBCalc BIM Wizard S19 Mod
9. 26 227 Another possibility is to create a new software serial port For that task lt SoftwareSerial h gt library must be referenced The utility of this strategy is to declare another two pins which now will be able to support the UART communication By using this the collision is solved due to pin O and 1 shared to the USB are used to communicate Arduino to a computer and the new ones in this case to communicate Arduino to BIM Using those new UART pins are not that much more complicated you only have to switch in all calls Serial for the name assigned to the new pin s communication In this case it is mySerail So if the function calls to communicate Arduino to a computed is Serial begin the function call to communicate Arduino to BIM is mySerial begin In the following table it is referenced the pin and its function on UART communication to BIM UART function Arduino Uno Pin RX 5 TX 6 Table 4 Arduino Uno UART pins list For making UART communication supported on Arduino Uno no library has to be included in SPI had to be included For making UART communication work firstly the speed of transmission must be declared This speed is represented in terms of bits per second baud For communicating in this project 9600 bauds are used As default is set 8 data bits no parity and one stop bit For this it is necessary to include in the sketch the following function call Seri
10. BACHELORARBEIT Technikum Wien Degree Program Informations und Kommunikationssysteme Connecting an Arduino UNO to KNX By Leticia Vizan Tundidor Student Number ic14x001 Supervisor Mag DI Friedrich Praus Wien 26 01 2015 FACHHOCHSCHULE TECHNIKUM WIEN Declaration l confirm that this paper is entirely my own work All sources and quotations have been fully acknowledged in the appropriate places with adequate footnotes and citations Quotations have been properly acknowledged and marked with appropriate punctuation The works consulted are listed in the bibliography This paper has not been submitted to another examination panel in the same or a similar form and has not been published declare that the present paper is identical to the version uploaded Vienna 26 01 2015 Place Date Signature Table of Contents MEN A RS 3 ded JMIODVABOne sede cu od M Lu O e aaa a ERER 3 MEE DO Of WOK dci tits 3 13 QUIN 3 1 4 Serial COMMUNICAIO Mead ec eee e eder OM hetero E 4 1 4 1 SPI Communiball lic sus edet totes cious ne ei qt id 4 1 4 2 UART comririunicallOn riore rune ena en EX Ene re ek eL ERE eu ee 5 2 APO UNO eet bei eto saat den PED e talc 6 X MEE Too ita aa 7 2 2 SPI software on Arduino Dno on 9 2 3 UART software on Ardulno Uno uc cce iaa 11 CENE KNX ROTO CON ieee EE 13 A a PED toate eased de 13 32 Olaractersli S quet es tod iue ERU I rotto e ot hi eos Eos
11. COL Bus Interface Module Clock Polarity Data Order Electrically Erasable Programmable Read Only Memory Input output Konnex Less Significant Bit Master In Slave Out Master Out Slave In Most Significant Bit Master Slave Select Power line Pulse Width Module Radio Frequency Serial Clock SPI Control Register SPI Data Register SPI Enable Clock Phase Serial Peripheral Interface SPI interrupt Enable SPI interrupt Flag SPI Clock Rate Select SPI Status Register Slave Select Twisted Pair Universal Asynchronous Receiver and Transmitter Write COLlision Flag B Bibliography 1 2 3 4 5 6 7 8 9 10 11 12 C Steiner 2005 The 8051 8052 Microcontroller Architecture Assembly Language and Hardware Interfacing Chapter 20 page 261 R Anderson D Cervo Pro Arduino Arduino expert topics and techniques Arduino website Products Arduino Arduino Uno Available http arduino cc en Main ArduinoBoardUno Accessed 25 10 2014 Atmel Datasheet ATmega48PA 88PA 168PA 328P 10 2014 Knx website Available www knx org Accessed 17 11 2014 H Merz T Hansemann C H bner Building Automation Communication Systems with EIB KNX LON and BACnet 2009 Chapter 6 KNX Communication KNX Association KNX Basic Course Available http www knx org media docs KNX Tutor files Summary KNX Communication pdf Accessed 18 11 2014 Buses Protocols and Systems for Home and Bu
12. Embedded Workbench Firstly we have to open the Workspace of what is wanted to work For that the following sequence must be done File gt Open gt Workspace and then select the file with eww extension o e YE IAR Embedded Workbench File Edit View Project Tools Window Help New FI o Y 3 uc OHM AHH Wo SS 2 Open File CTRL O to rx Close Workspace z Save Workspace Header Source File CTRL MAYUSCULAS H Close Workspace Save CTRL S Save As i Ri AR Information Center for Renesas 78K ve e fi orials example projects user Page Setup Print CTRL P Recent Files pann Zi Ej B bit TTING STARTED USER GUIDES EXAMPLE PROJECTS INTEGRATED RTOSes Guidelines for setting up Complete product Example applications Information evaluation your project adding documentetioninPDF that demonstrate versions and example files compiling linking format gives you all the hardware peripherals for projects for integrated and debugging it usar and reference specific devices and RTOS and middleware information you need evaluation boards solutions D E T ic TUTORIALS SUPPORT RELEASE NOTES My Pages Tutorials to make you For questions about how All about the latest Hare you can download familiar with the IDE to use your IAR product features new device product updates and the features ofthe reporting a problem or support and program manage licenses an
13. al begin speed When read on UART bus is necessary the predefined function for that can be used This function returns the first byte of incoming serial data available or 1 if there are no data available Serial read Besides this it is useful to know when Arduino is receiving data For this task the next function can be inserted This function returns the number of bytes available to read Serial available When it is necessary to write another function it is predefined as well The following function prints data to the serial port on the base specified format Values permitted are BIN binary OCT octal DEC decimal HEX hexadecimal When it is inserted as print it returns the number of bytes written though reading that number is optional Serial print data format There is an improvement of the previous function It reachs the same characteristics as Serial print but also prints a carriage return character r and a newline character n This function is Serial println data format 3 KNX protocol 3 1 Protocol definition A protocol is communication rules that permit information flows between equipment Normally these rules are classified as public or private In this case KNX is an open protocol to which everyone can access It is essential that if two or more devices have to be communicated they have to speak the same language KNX is a standard protocol because all its elem
14. ansceiver will fit the voltage levels between the card and the KNX bus BIM M13x modules comply with the KNX specification The evaluation board is programmed via the intermediary of MINICUBE2 from the IAR Embedded System software This allows the application developer to use the IAR tool which includes powerful debugging tools All these development tools have been installed on a virtual machine of Windows 7 Evaluation board EVB is used to write the code for any application EVB has the largest memory of any of the BIM chips This provides the option of writing the code without memory restrictions and then choosing the correct BIM to put in the installation Memory restrictions of every BIM are in the figure below BIM Microcontroller Flash M130 78F0534 8Kbyte for approx 40 communication objects M131 78F0535 16Kbyte for approx 100 communication objects M132 78F0537 48Kbyte for approx 250 communication objects M135 BIM M130 with extended temperature range 25 to 70 C Figure 19 BIM M13x Bus interfaces modules It is necessary assemble correctly all BIM software It has to be done as it is shown in the figure below valuation Board AL 3 Figure 20 How to connect BIM system Before making the physical connection all running software must be installed before Firstly EVB must be connected to MINICUBE2 Although in the documentation provided by the manufacturer it is said the external oscillator
15. bits SLO 1 set 2 stop bits O set 1 stop bit So finally our register ASIMO has the value 11100101 in binary and OxE5 in hexadecimal which is the one to insert in the function FT12Init 13 p 19 amp amp 17 p 436 439 gt TXSO This 8 bit register is used to transmit data When this register is complete the transmission begins and data is sent over pin 14 It is an only read register gt RXBO When the register RXSO is full by the data received over pin 10 data are copied to register RXBO because RXSO is an only write memory and users cannot have access to it 5 Arduino Uno and BIM135 board connection In this paragraph the proper way to connect both boards physically will be discussed 5 1 SPI hardware connection SPI hardware connection has to be done as specified in figure 1 NI DOTYNY ONN ONINGYV ye SS Se P BIM 13x GND pin 24 IOIEN MOSI pin 14 MISO pin 10 CLK pin 16 BIM 135 S eie Digital I O Figure 15 Wire connection between BIM board and Arduino Wire connections must be done paying special attention to connect MISO pin in Arduino Board with MISO pin in BIM135 Once each datasheet is examined it would not be difficult to find the correct connections Basically connections have to be done on the same way that were specified in paragraph one SPI connection especially on figure 1 SPI wire connection SPI pin Ard
16. bj_1 value_2 value_obj_2 value 3 value obj 3 UART write Mode BIM code Initialize variables Object_change_send_data lt gt YES Data RXBO Count 1 Count 2 Count 3 Command Object num_bytes data data data NO num_bytes gt 1 amp count 4 YES value_rcv data count 0 final_value_rcv value_ rcv num bytes 28 count 5 YES value_rcv_1 data final_value_rcv value_rcv lt lt 8 num_bytes gt 38 count 6 count 0 final_value_rcv value_rcv lt lt 16 value_rcv_1 lt lt 8 value_rcv_2 value_ rcv_1 num_bytes gt 4 amp count 7 YES value_rcv_3 data count 0 final_value_rcv value_rcv lt lt 8 Change state of the communication object specified void int_UART_RX void BYTE c c RXBO STATE TRUE count UART Mode_Write ARUDINO code Initialize serial communication Initialize variables NO command arriving Read command over UART Display command object arriving Read object over UART Display object 2 NO num_bytes arriving YES Read num_bytes over UART Display num bytes NO data arriving YES Read object over UART data arriving Read value_obj over UART 1 2 Num_byte 4 NO Data arriving YES NO data arriving YES Read value_obj_1 Read value_obj 3 over UART over UART
17. ctuator change to its value 7 3 Function modes As was mentioned before there are two function modes on this project which involve different utilities The first one is Write Mode in this mode KNX send via BIM board to Arduino information related to the state of the different objects of communication This mode has a command associated which length is one byte This command has the following format ID Object The second mode sent from Arduino to KNX via BIM information related to the state of any different objects This mode has also a command that define this mode and has the following shape ID Object 32 SPI write Mode BIM code Send command over SPI wait 20 ms Initialize Send object over SPI 3 wait 30 ms variables Send num_bytes over SPI wait 20 ms NO I lt YES NUM_OF_COM _OBJ Send value over SPI wait 3 ms Object i v changed NO Send value 1 over SPI wait 30 ms Object 0 Object 1 Object 34 NO Assigns correct Assigns correct Assigns correct Send value 2 over SPI values to values to values to wait 30 ms variables variables variables command command command object object object num_bytes num_bytes num_bytes B value object value object value object Num Bytes 4 NO command 0x80 object Send value 3 over SPI value obj 1 value obj gt gt 8 value obj 2 value_obj gt gt 16
18. d IAR C SPY debugger finding support comections contact information and resources check your SUA status Open a Workspace MAY NUM Figure 25 IAR Embedded Workbench Before starting the programming the properties of debug operations must be set For that task we can follow the Getting started paper of BIM at its paragraph 1 5 Set BIM M13 Debug Operating System Workspace x main ox Debug BERRA EER ERED ER EEREREEREEE TREE EEEEREREREEEREREEEED SEER EER EEEE ER ER ERR ERERER ERIE a 3 Files File main c BOProject D v R BIM_M13xh Description This module contains the main function s of the user application H D config xml program Ehostartup s26 La E Date 12 10 2014 Ha D tables c I R userh Generates BIM Mi3x Wizard a C3 Output PIOPPI IIIT IAE G GIA include BIM M13x h ram flags for communication objects BYTE RAMFlags NUM OF COM OBJ 2 1 communication objects BYTE Objecti BYTE Object2 L EA void AppInit void ri Messages File Line main c Done 0 error s 0 warning s Errors 0 Warnings 0 NUM Ready Figure 26 IAR Embedded Workbench space of work After that the project has to be Make before it can be charged into BIM tool If previous steps were successful we just have to Download and Debug
19. eceiver The synchronous peripherals need a physical line cable dedicated to the clock signal providing synchronization between the two devices Asynchronous peripherals do not use a clock signal the synchronized information is extracted from the same data Start bit and stop are added as well as a precise format for a fixed transfer rate 1 4 1 SPI communication SPI is the acronym of Serial Peripheral Interface It is mainly used to transfer information between two or more integrated circuits SPI is a full duplex synchronous protocol This indicates that data can be sent and received simultaneously The bus interface of serial peripheral or bus SPI is a standard to control almost any digital electronic device which is able to accept serial bit stream controlled by a clock SPI consists of a clock data incoming data outgoing and a selected pin which enable or disable the communication between both devices Several SPl compatible devices can share communication wires however each device must have its own chip select line When SPI communication starts master microcontroller has complete control of it and is able to settle SPI communication with the slave required That means that slave devices only can communicate when master allows it The lines of the SPI data communication are the following e Master In Slave Out MISO this line is the input of the master microcontroller and also the output of the slave microcontroller e
20. ect is the one referenced as three level addressing M IM M M M Mi Mi Mi IS S S S IS S S JS SS A AA SS aa Main group Subgroup 5 bit O 31 Middle group 8 bit 0 255 3 bit 0 7 Figure 12 Group Address 3 levels Main Group functional area basically make reference to the full installation e g 1 First floor 2 second floor Middle Group function inside that area eg 0 lights 1 blinds 2 heating Subgroup load or group of loads e g 09 kitchen light 20 living room heating Actuators can listen to several group addresses as well as having several group addresses Sensors however can only send one group address per telegram 7 p 6 7 4 BIM 13x The board programmed is an evaluation board EVB that contains different debuggers depending of the microcontroller which want to be programmed 4 1 SPI software on BIM13x The BIM board has a SPI communication as a feature of the controller On the hardware side the board has a pin which plays the role of Clock on SPI communication and pins which play the role of MOSI MISO For the Slave Selected pin any digital I O could be use in this case pin 7 on Port7 will be used 14 p 4 Concerning the software side there are mainly two defined functions regulating SPI communication The first function initializes the driver for transmitting data over SPI It has the following format void SPlInit
21. ents in the installation use a common protocol to communicate And it is worldwide because there are more than 120 country partners KNX Association is the creator and owner of the KNX technology the worldwide STANDARD for all applications in home and building control ranging from lighting and shutter control to various security systems heating m ventilation air conditioning monitoring alarming water control energy management metering as well as K X household appliances audio and lots more The technology can be used in new as well as in existing home and buildings 5 In KNX system data transmit is done through a cable or bus connected to all devices The bus allows all components on home automation installation to be communicated in this way it is possible that any component can control another independent of the location or length between them 3 2 Characteristics KNX EIB has 321 members in 34 countries 5 KNX uses a bus typology that means KNX installation figure 11 has some advantages over any conventional connection figure 10 The most remarkable benefit is that using KNX the energy consumption can be reduced thanks to illumination and heating besides controlling the most consuming peaks of energy costs can be reduced Also planning the installation on KNX communication makes it possible to reduce cabling Besides this it is simpler to introduce some changes or even expand the installation
22. enum SPISpeed speed BYTE CKDAP BOOL MSBFirst Where enum SPISpeed speed has the value SPI_BAUD_9600 which indicates SPI communication will have a speed of 9600 bauds BYTE CKDAP in this case has the value 0x00 which indicates clock is idle high data is valid if clock is high BOOL MSBFirst has the value TRUE which means the first bit transmitted is the most significant one 13 p 24 The second one is the function used to send and receive data over SPI bus It has the following format BOOL SPISend BYTE pData BYTE length Where BYTE pData is a pointer that data wants to be transmitted over SPI and where received data is stored BYTE length number of bytes sent over SPI This function returns true is the exchange was successful and false if it was not 13 p 24 4 2 UART software on BIM13x For programming UARTO on the BIM board there exists no predefined function as happens on SPI Instead it is necessary to know the register of the NEC78K0 KE2 microcontroller used by this kind of serial communication gt BRGO The Baud rate of the transmission is specified as the modified register BRGCO in NEC78K0 KE2 microcontroller The aim is to have a baud rate of 9600 bauds Because this is the typical Arduino Uno speed Address FF71H A ter reset 1FH R W Symbol 7 6 2 1 5 4 3 0 eneco mesm mso o mos mocos wao mocos wo 00 Figure 13 BRGCO register in NEC78K0 KE2 microcontroller
23. finally a stop bit It is important to emphasize that RX and TX pins in UART communication are switched as seen in the following diagram Figure 2 UART wire connection 2 Arduino UNO Arduino UNO specification can be found on the official web site of Arduino In the below diagram the main features are represented um ARDUINO ea eo ER y i m Figure 3 Arduino Board ATmega328 5V 7 12V 6 20 V 12 of which 6 provide PWM output 6 40 mA 50 mA 32 KB ATmega328 2 KB ATmega328 1 KB ATmega328 16 MHz Table 1 Arduino Uno main characteristics 3 2 1 ATmega328 As stated before ATmega328 is the microcontroller on which Arduino Uno is based ATmega328 has three registers that are of a great importance on a SPI communication They are SPI Control Register SPCR SPI Status Register SPSR and SPI data Register SPDR gt SPI Control Register SPCR In this register all SPI communication configurations are specified each bit representing a different field of the communication The following displays the structure Bit 7 6 5 4 3 2 1 0 occ 0x0 SPE se BORD msm cor T CPHA SPRI_ SPRO_ SPCR Read Write RW R W RIW RW RIW R W R W R W Initial Value 0 0 0 0 0 0 0 0 Figure 4 SPCR register structure 4 p 173 As figure 4 shows all bits have value O as default value When SPI is used this register has different
24. h the following data sent Secondly the data exchange specifies the identifier of the group of communication object that changed its value Then the number of bytes that the value of the group of communication has Finally Arduino know the value of the group of communication right before being received After every data received Arduino makes known to the BIM board that data was well received by sending an acknowledgement message defined as 0x01 on the protocol back This acknowledgement message is dispatched after receiving new data In this way the BIM board knows data already sent was well received and can proceed to send the next one Command Object Num_butes Value_Object 1 byte 1byte 1byte 1bye co pe sbe gt Figure 18 Data sent over SPI 6 2 Communication protocol over UART Basically this protocol works the same way as the protocol for SPI The change is that the acknowledgment now is not sent back There are two modes write and read basically both protocols have the same structure but in different ways BIM 13X Arduino UNO Command Value of the object Figure 19 Sequence diagram of the communication protocol over FT12 Time 7 Proof of concept Physical connection between BIM board and PC BIM M13x bus interface module is a module composed of a microcontroller NEC78K0 Kx2 containing in its memory API to communicate the KNX bus transceiver associated with a TP UART The tr
25. ifier 4 m n BIM Tools Readv BIM M13x Wizard Readv 4 Figure 23 BIM Wizard screen Location Now it is time to declare how many communication objects are needed in our project and which kind of data is each For that task only the name of the object in the corresponding box and specified on the dropdown menu the kind of data can be selected In our project the kind of data will be UINT1 because of the addresses of the communication object are stipulate on one byte If more communication objects are necessary select the green cross menu options to add them For continuing select Next um eleli B Na Na A is Connect Disconnect Only active S19 Viewer 19Comparer EIBCalc BIM Wizard 19 Modifier BIMTools Ready BIM_MI2Wizard Ready y Figure 24 BIM Wizard screen Objects After that a new screen appears but in this screen it is not necessary change anything Just select Create amp a e o 3 FI S Connect Disconnect Only active S19 Viewer 19Comparer EIBCalc BIM Wizard 519 Modfier Figure 25 BIM Wizard screen Entries Now the project is created That means that in the folder specified a few default documents necessary for star to program on IAR Embedded Workbench appear 15 p 2 2 IAR Embedded Workbench Once the project was created by BIM Tools we can start working on the code on IAR
26. ilding Automation Online Available http Awww ib cvut cz sites default files Studijni_materialy SZS Buses 20Protoc ols 20and 20Systems 20for 20Home 20and 20Building 20Automation pdf Accessed 18 11 2014 Building automation with KNX and BIMs 2012 Available http Awww endrekatona eu BIM Introduction Accessed 10 10 2014 Building automation based on KNX BIMs The development tool package 2012 Available http www endrekatona eu BlIM_ Introduction Accessed 10 10 2014 Building automation based on KNX BIMs The first application program 2012 Available http www endrekatona eu BIM_Application_Program Accessed 10 10 2014 Building automation based on KNX BIMs Programming the communication 2012 Available http www endrekatona eu KNX_ Communication Accessed 10 10 2014 13 14 15 16 17 API Reference for Bus Interface Modules M130 M131 M132 and M135 KNX Processors 184 01 184 11 and 184 21 Datasheet 03 2014 Technical Data for Bus Interface Modules M130 M131 M132 and M135 KNX Processors 184 01 184 11 and 184 21 Datasheet 03 2014 Getting Started for Bus Interface Modules M130 M131 M132 and M135 KNX Processors 184 01 184 11 and 184 21 Datasheet 03 2014 Blum J 2012 Exploring Arduino Tools and Techniques for Engineering Wizardry Part Ill Renesas Datasheet 78K0 Kx2 User s Manual Hardware 8 Bit Single Chip Microcontrollers 07 2010
27. in TETFRERERRAERARRERARRA RARA H while Serial available Serial print Command for aux 0 aux i 3 aux Lee las replicas de comando 4 w r Arduino Uno on COMS Figure 29 Arduino Software 7 1 Arduino Uno Code In this project Arduino microcontroller has to read data which is dispatched over SPI or UART from the BIM board although it can be done on the other way That data is information read from different sensors in the Smart Home It has to read correctly the information dispatched save it and show it properly Besides this the communication can happen in the opposite direction dispatch data to make the actuators change their state According to the protocol developed in the paragraph 6 Arduino receives three data command object and value_obj over SPI or UART and sends back the byte 0x01 as confirmation that the previous data were correctly received 7 2 BIM 13x Code One of the goals of the BIM 13x part is to recognize when a Communication object changes and what is its new value To make this task possible every communication object is checked one by one If one of them is changed the value for both is changed the object and its new value are sent over SPI or UART to Arduino UNO Every value is sent after receiving a conformation from Arduino indicating the preceding data was sent successfully The second part is to read information sent from Arduino Uno and interpret it to make any a
28. ino Uno It is also possible send data from Arduino to KNX for changing the value of the communication object 1 2 Scope of work The scope of this project is to implement communications between a BIM 132 board which supports KNX and another microcontroller which for this project was Arduino UNO The final goal is to be able to dispatch data to Arduino UNO from a BIM board and vice versa This data contained information about the value of the object communication related to different measures as lights temperature humidity which when changed resulted in a change of the corresponding value Depending on the requirements two protocols of communication can be used One based on SPI communication or the other based on UART communication 1 3 Outline The thesis will start with a short introduction about SPI and UART communications followed by details about Arduino UNO and its communication All internal registers required for the communication and how to implement it are specified Before going into a description of the BIM board KNX protocol is broadly explained After that communication over the BIM board is also explained The hardware connection between both boards defined as well as the protocol created will also be explained 1 4 Serial Communication The main difference between a synchronous interface as SPI and an asynchronous one as UART is the way in which synchronization information is sent from transmitter to r
29. lable on SPI and UART communication In this figure it is implemented only for one byte but it can be done for one to four bytes de de d d n Mode read Introduce any character Mode write wait for receiving data RRR Mode read OFF Mode write ON Command 80 Object 0 num bytes 1 value 1 Figure 31 Prove communication from BIM to Arduino Sends data that it is introduced on Monitor Serial and available only in UART communication Mode read Introduce any character Mode write wait for receiving data o e d e n x Mode read ON Mode write OFF Introduce all data in decimal Object 0 Command 0 Num bytes 1 4 1 Value obj 1 Figure 31 Prove communication from Arduino to BIM 8 Conclusion Sometimes it is important to have a well regulated home automation system and make the state known by the user And also make possible for the user to change the state of the system if that is desired This project has focused on completing those two tasks Communication between Arduino and KNX is done via SPI or UART the most used In this process both microcontrollers exchange useful data for the system As result Arduino can know the values of the communication objects in KNX and change the state of some of them A Abbreviation BIM CPOL DORD EEPROM I O KNX LSB MISO MOSI MSB MSTR PL PWM RF SCK or SCLK SPCR SPDR SPE SPHA SPI SPIE SPIF SPR SPSR SS TP UART W
30. n is specified on the EEPROM memory datasheet see table 4 And as can be seen MOSI SCK and SS must be inputs However MISO has to be defined by the user It will be defined as output PIN Direction Master SPI Direction Slave SPI MOSI Output Input MISO Not defined User Defined SCK Output Input SS Output Input Table 3 SPI Pin Overrides 4 p 168 2 3 UART software on Arduino Uno In the case of Arduino UNO there is only one available UART and it is duplexed to the USB serial communication that is used for communicating to a computer mainly for programming and debugging The derivate problem of this is that some collisions can appear when the sketch is been debugged and the UART connection with another electronic device in our case the BIM board wants to be used In this case the connection between RX and TX pin could be as is shown in the following figure Computer Arduino Figure 8 Colliding UART communication lines 16 pp 227 The diagram above shows what would happen if both connection the BIM board and the computer tried to transmit data to the Arduino at the same time Due to this situation it is determined that Arduino cannot be programmed nor talking to the computer while BIM is connected to the Arduino s serial port To avoid this problem it was determined that a way around this could be unplugging the BIM shield every time Arduino need to be programmed 16 pp 2
31. ommunication For prove this is working see figure 31 Receives data from Arduino about a concrete communication object and change its state value on KNX available only on UART communication poral T Ej coma znne sis a File Options View Help pereen Disconnect Port COMS R Baud 9600 Data s y stop 1 y Mode read Introduce any character Mode write wait for receiving data f Rx 6 Tx 0 count 0 E 7 New 7 TA TA Newline every Please introduce data in Decimal las Hex Mec Msn save output J y Cldearat 0277 daras o Mode read ON Sequence Overview x Te vem o Mode write OFF Introduce all data in decimal 12 3 4 5 6 7 8 910 11 12 13 14 15 16 17 18 19 20 Object D OD OD 03 OA OB 0C Command D Num bytes 1 4 3 Value_obj A Second byte of the value object B Third byte of the value object C Mode read Introduce any character Mode write wait for receiving data I 1 Selection Input control x Input options ea Hex Eoee Een sendon enter ene d Type asc x f ASend Transmitted data x V Desplazamiento autom tico E Nohay fin de l nea 9600baud History 0 10 Connect to COMS b 9600 d 8 s 1 p None On the Arduino part Figure 30 Prove communication from Arduino to BIM Receives data from BIM and it can be seen in a Monitor Serial avai
32. reete gan dois 13 33 Group AUdleSS oe o eet ne rte nde tede t eed melee ada eie dena da 15 A A tusi sa dent eto ES manana ae sis acti c sit Ct tar anced 16 41 SP sonware on BIMTSX aida 16 4 2 UART software on BIM13X seseeeseeeseeeeeeneeee nennen nemen nnne 17 5 Arduino Uno and BIM135 board connection sseeeeeee 19 bi SPI hardware connection nce nad eere eet RI dt is 19 52 UART hardware connect 20 6 Communication protocol between Arduino and BIM ccccncccnnnnncnnnnnnnnnnnnnnnnnnss 22 61 Communication protocol over SPI nai 22 6 2 Communication protocol over UART ssssseee 23 OMNE Viro Keen RE m ria 24 7 1 Arduino Uno Gode epe eg unde aa 32 3 2 BIMRISXGOdO uA outer bie add vais ie t 32 Ta Function modes usto ot E te bes ut cU E CM 32 TA Rel cc 43 sammie O16 9 1 2 0 A oi coeunt cu rE e nea Mu M N ery Pe 45 A SOD MON sto tit EC 46 B Bibliography ceeded Ee eee A iren enia uiences 47 1 Introduction The project outlines the communication between a BIM board which supports KNX and a second microcontroller which is an Arduino UNO Two ways of communication are supported SPI and UART communications 1 1 Motivation The motivation for this project is to develop the communication between Arduino to KNX The aim is to know the value of the different modules implemented for other students The data is sent from KNX and then collected via Ardu
33. sible to develop SPI by digital pins In the following table the pin and its function on SPI communication are referenced SPI function Arduino Uno Pin MOSI 11 MISO 12 SCK 13 SS slave 10 Table 2 Arduino Uno SPI pins list Otherwise ICSP connector can be used to implement SPI communication 1 MISO 6 6 3 SCK 00 5 Reset 0 lt H eN ON i J Figure 7 ICSP header Master Slave communication Master mode is supported by a specific Arduino library so it has to be included in all code related to the SPI protocol Zinclude lt SPI h gt The following configuration could be changed by the next function calling or by changing the registers specified in paragraph 2 1 Besides the order in which the bits are received it is important Two ways are possible MSBFIRST most significant bit first or LSBFIRST less significant bit first This can be specified by inserting the next function SPI setBitOrder If itis not inserted it is the most significant bit as default That is the specification selected in this project It is possible to set data mode as well This means the polarity and phase of the clock This is made by inserting the next function SPI setDataMode Four modes are possible but in this project default value is used that means that the clock is normally low and that the data is read in the transmission from low to high SPI setClockDivider This configuratio
34. uino Uno BIM135 MOSI 11 14 MISO 12 10 SCK 13 16 SS 10 7 GND GND 24 Table 5 Pins connections between Arduino and BIM board on SPI communication 5 2 UART hardware connection Proceeding in a similar way than in SPI connection SPI pin Arduino Uno BIM135 RX 11 10 TX 12 14 GND GND 24 Table 6 Pins connections between Arduino and BIM board on UART communication A 2D P 1D 1D Om WAN oO NI SO WNY ONN ONINGYV BIM 13x GND pin 24 TX pin 14 RX pin 10 BIM 135 aaa gt Digital I O Figure 16 Wire connection between BIM board and Arduino 6 Communication protocol between Arduino and BIM 6 1 Communication protocol over SPI Essentially communication between the BIM board and Arduino has as goal exchange information about state changes of different Group of Communication For making this communication understandable for both parts it is necessary to create a protocol to regulate the flow and interpretation of the information To create Protocol is simple It s based on send data on acknowledgement Sequence diagram BIM 13X Arduino UNO Value of the object Time Figure 17 Sequence diagram of the communication protocol By seeing the figure above we can appreciate that the logic of the protocol is quite simple Basically at least four bytes are sent over SPI bus Firstly a command that specifies to Arduino what to do wit
35. values depending if it is in slave or master mode Master Mode SPIE the reason of SPI interrupts when bit SPIF in SPSR register is set SPE is HIGH in that way SPI mode is enabled It has to be 1 in any operation requiring SPI communication DORD In this case it is settled as 0 that means the most significant bit MSB is transmitted first MSTR this bit is selected if master mode is on or off For master mode must be 1 Besides if SS is configured at LOW input while MSTR is set MSTR will be cleared and SPFI in SPSR will become set CPOL default value is used 0 That means SCK is low when idle CPHA Sample data when the value is 1 will set a falling edge on the data clock when 0 it will set a rising edge SPR1 and SPR2 these bits control the SCK rate on the microcontroller configured as master they have no effect on the slave It is left as default value 0 0 Slave Mode As most parts of the registers stay in the same state when in master mode to assure that communication protocol is working in the same language In slave mode only changes from master mode will be explained MSTR slave mode is defined when the bit value is 0 4 pp 173 174 gt SPI data Register SPDR In this register data 1 byte is saved so it can be said that this register could be used as a buffer It is possible to read and write on it Data is read from this register because when data is sent it is saved on here

Download Pdf Manuals

image

Related Search

Related Contents

Panas。ni6 イ氏電圧 トランス用ライ トコン トロール 取扱説明書  ホットプレートTHP-301  HDS-5x Gen2 Kurzbedienungsanleitung  Adore Softphone Premium  Bedienungsanleitung easyRESCUE-PRO  AOC 2230 Computer Monitor User Manual  Instrucciones de servicio Operating instructions    取扱説明書 PF-P470 / PF-P450  Catalogue des creusets  

Copyright © All rights reserved.
Failed to retrieve file