CanBerryDual PI V 2.1.2 INDUSTRIAL BERRY www.industrialberry.com March 2016
Contents 1 License 1 1.1 Disclaimer.............................. 1 1.2 EVALUATION BOARD/KIT IMPORTANT NOTICE..... 1 2 Introduction 5 3 Hardware implementation 7 4 Software implementation 15 4.1 Real Time Clock.......................... 17 4.1.1 RTC with shell....................... 18 4.2 LED Control............................ 19 5 Components list 21 Bibliography 23 iii
List of Figures 2.1 DualCanBerry V2.1.2 on Raspberry PI.............. 6 2.2 DualCanBerry V2.1.2 Bottom view................ 6 3.1 Electric diagram of CanBus 1 block................ 8 3.2 Electric diagram of CanBus 2 block................ 9 3.3 Electric diagram of RTC block.................. 10 3.4 DualCanBerry Connector..................... 11 3.5 Raspberry HAT Eeprom...................... 12 3.6 CAN Bus example, image from http://en.wikipedia.org/wiki/ File:CAN-Bus_Elektrische_Zweidrahtleitung........ 12 3.7 CANH Bus monitoring....................... 13 4.1 CAN1 on SPI0.0 and CAN0 on SPI0.1.............. 16 4.2 can0 and can1 loaded....................... 17 4.3 can1 dump............................. 18 v
List of Tables 5.1 CanBerryDual Pi V 2.1.2..................... 22 vii
Chapter 1 License Open-source hardware shares much of the principles and approach of free and open-source software. In particular, we believe that people should be able to study our hardware to understand how it works, make changes to it, and share those changes. To facilitate this, we release all of the original design files (Eagle CAD) for the IndustrialBerry hardware. These files are licensed under a Creative Commons Attribution Share-Alike license, which allows for both personal and commercial derivative works, as long as they credit Industrial- Berry and release their designs under the same license. The IndustrialBerry software/firmware is also open-source. 1.1 Disclaimer In no event shall Industrialberry be liable to the buyer or to any third party for any indirect, incidental, special, consequential, punitive or exemplary damages (including without limitation lost profits, lost savings, or loss of business opportunity) arising out of or relating to any product or service provided or to be provided by Industrialberry, or the use or inability to use the same, even if Industrialberry has been advised of the possibility of such damages. 1.2 EVALUATION BOARD/KIT IMPORTANT NOTICE Industrialberry Team provides the enclosed product(s) under the following conditions: This evaluation board/kit is intended for use for ENGINEERING DEVELOPMENT, DEMONSTRATION, OR EVAL- UATION PURPOSES ONLY and is not considered by Industrialberry Team to be a finished end product fit for general consumer use. Persons handling the product(s) must have electronics training and observe good engineering practice standards. As such, the goods being provided are not intended to be complete in terms of required 1
Chapter 1 License design, marketing, and/or manufacturing related protective considerations, including product safety and environmental measures typically found in end products that incorporate such semiconductor components or circuit boards. This evaluation board/kit does not fall within the scope of the European Union directives regarding electromagnetic compatibility, restricted substances (RoHS), recycling (WEEE), FCC, CE or UL, and therefore may not meet the technical requirements of these directives or other related directives. Should this evaluation board/kit not meet the specifications indicated in the Datasheet Documents, the board/kit may be returned within 30 days from the date of delivery for a full refund. THE FOREGOING WARRANTY IS THE EXCLUSIVE WARRANTY MADE BY SELLER TO BUYER AND IS IN LIEU OF ALL OTHER WARRANTIES, EXPRESSED, IM- PLIED, OR STATUTORY, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. The user assumes all responsibility and liability for proper and safe handling of the goods. Further, the user indemnifies Industrialberry Team from all claims arising from the handling or use of the goods. Due to the open construction of the product, it is the user s responsibility to take any and all appropriate precautions with regard to electrostatic discharge. EXCEPT TO THE EXTENT OF THE INDEMNITY SET FORTH ABOVE, NEITHER PARTY SHALL BE LIABLE TO THE OTHER FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUEN- TIAL DAMAGES. Industrialberry Team currently deals with a variety of customers for products, and therefore our arrangement with the user is not exclusive. Industrialberry Team assumes no liability for applications assistance, customer product design, software performance, or infringement of patents or services described herein. Please read the User s Guide and, specifically, the Warnings and Restrictions notice in the User s Guide prior to handling the product. No license is granted under any patent right or other intellectual property right of Industrialberry Team covering or relating to any machine, process, or combination in which such Industrialberry Team products or services might be or are used. FCC WARNING This evaluation board/kit is intended for use for ENGINEERING DEVELOPMENT, DEMONSTRATION, OR EVALUATION PURPOSES ONLY and is not considered by Industrialberry Team to be a finished end product fit for general consumer use. It generates, uses, and can radiate radio frequency energy and has not been tested for compliance with the limits of computing devices pursuant to part 15 of FCC rules, which are designed to provide reasonable protection against radio frequency interference. Operation of this equipment in other environments may cause interference with radio communications, in which case the user at his own expense will be required to take whatever measures may be required 2
1.2 EVALUATION BOARD/KIT IMPORTANT NOTICE to correct this interference. Mailing Address: info@industrialberry.com This development kit is NOT certified as Confirming to Technical Regulations of Radio Law of Japan. If you use this product in Japan, you are required by Radio Law of Japan to follow the instructions below with respect to this product: Use this product in a shielded room or any other test facility as defined in the notification #173 issued by Ministry of Internal Affairs and Communications on March 28, 2006, based on Sub-section 1.1 of Article 6 of the Ministry s Rule for Enforcement of Radio Law of Japan, Use this product only after you obtained the license of Test Radio Station as provided in Radio Law of Japan with respect to this product, or Use of this product only after you obtained the Technical Regulations Conformity Certification as provided in Radio Law of Japan with respect to this product. Also, please do not transfer this product, unless you give the same notice above to the transferee. Please note that if you could not follow the instructions above, you will be subject to penalties of Radio Law of Japan. 3
Chapter 2 Introduction CanBerryDual Pi V 2.1.2 is an extension board for RaspBerry Pi. It is an Open Hardware Design. It has two functionalities: a can bus module and an on board Real Time clock powered by a 12 mm battery. In fig 2.1 is shown the Board on Raspberry PI B2. The CanBus is based on MCP2515 [1] SPI controller and the MCP2551 [2] transceiver for both Can Bus. All functionalities are full integrated in standard linux kernel, so, they can be available on fly, or at last recompiling linux kernel to add canbus functionalities. The real time clock is based on DS3231 [3] an I2C controller with internal oscillator. It is full compatible with linux too. Using I2C Kernel module, and standard kernel functions, date and hour can be set/get by simple commands. On the bottom side is located an on board battery to guarantee a data autonomy more than 20 years. In chapter hardware there are all informations on principal components, schematics to rebuild and modify RaspBerry PI board. In chapter Software is reported how all hardware can be used: as recompile kernel, build simple user space function to set and get I2C data, etc... In chapter application is reported a typical example of how to use the board. 5
i i industrialberry_datasheet 2016/2/10 17:24 page 6 #16 i i Chapter 2 Introduction Figure 2.1: DualCanBerry V2.1.2 on Raspberry PI Figure 2.2: DualCanBerry V2.1.2 Bottom view 6 i i i i
Chapter 3 Hardware implementation CanBerryDual PI 2.1.2 is composed by three blocks: two CanBus Modules (CAN 1 shown in Fig. 3.1 and CAN 2 shown in Fig. 3.2) and a Real Time Clock shown in 3.3 The SMD Jumper JP2 must be used to connect the RTC Int pin to Raspberry GPIO17. MCP2515 is a stand alone SPI canbus controller full integrated in linux kernel. At the start, the driver was implemented as a block device. Recently it is assumed to be a network module into the kernel. It is supplied by 3.3V from raspberry connector (fig 3.4 ). MCP2551 is supplied by 5V from Raspberry connector instead. So, to match voltage physical level between the two chips, a voltage matching made by R3 and R4 has been used. The SMD Jumpers JP3 and JP5 must be used for the first and the last device of CAN Bus, this jumper provides the 120 Ω termination (see fig 3.6). The Raspberry Pi B+/B2 has been designed specifically with add-on boards in mind and today we are introducing HATs (Hardware Attached on Top). A significant feature of HATs is the inclusion of a system that allows the B+/B2 to identify a connected HAT and automatically configure the GPIOs and drivers for the board, making life for the end user much easier! The automatic configuration is achieved using 2 dedicated pins (ID SD and ID SC) on the 40W B GPIO header that are reserved for an I2C EEPROM CAT24C32WI. The EEPROM (see fig 3.5). You can see in fig.3.7 the signal on pin CANH 7
Chapter 3 Hardware implementation Figure 3.1: Electric diagram of CanBus 1 block 8
Figure 3.2: Electric diagram of CanBus 2 block 9
Chapter 3 Hardware implementation Figure 3.3: Electric diagram of RTC block le Drive\Eagle_File\DualCAN 2.1.2\DualCanberry 2.1.2.sch (Sheet: 1/1) 10
Figure 3.4: DualCanBerry Connector 11 30/11/2015 12:35:05 C:\Users\p.scorrano\Google Drive\Eagle_File\DualCAN 2.1.2\DualCanberry 2.1.2.sch (Sheet: 1/
Chapter 3 Hardware implementation Figure 3.5: Raspberry HAT Eeprom Figure 3.6: CAN Bus example, image from http://en.wikipedia.org/wiki/ File:CAN-Bus_Elektrische_Zweidrahtleitung 12
Figure 3.7: CANH Bus monitoring 13
Chapter 4 Software implementation Download ready to use ISO kernel 4.1.7+ for Rpi B2 and B+. To enable the driver can0 e can1 open the file /boot/config.txt and add the following lines in Overlay section: dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=22 dtoverlay=mcp2515-can1-overlay,oscillator=16000000,interrupt=25 Save the file /boot/config.txt connect SD card to Raspberry and power on. Connect via telnet with raspberry, to identify the name of can interface associated with the spi. Run the following command: pi@raspberrypi ~ $ dmesg grep -i can This is the output: CAN device driver interface mcp251x spi0.0 can1: bit-timing not yet defined mcp251x spi0.1 can0: bit-timing not yet defined Respect the board shown in figure 4.1 the interface can0 is located in SPI0.1 (X2 connector) and can1 in SPI0.0 (X1 connector). After your raspberry has been booted, go to home directory: cd /home/pi/ nano can-start.sh add these lines to the script #!/bin/sh #Can ip link set can0 up type can bitrate 1000000 ip link set can1 up type can bitrate 1000000 Run the script: 15
Chapter 4 Software implementation Figure 4.1: CAN1 on SPI0.0 and CAN0 on SPI0.1 16
4.1 Real Time Clock Figure 4.2: can0 and can1 loaded sudo sh can-start.sh So the system is ready (see fig.4.2), then you can use standard canbus command to use the peripheral: candump can0 -> to monitoring canbus0 traffic cansend can0 7DF#0201050000000000 -> to send canbus0 commands candump can1 -> to monitoring canbus1 traffic cansend can1 7DF#0201050000000000 -> to send canbus1 commands 4.1 Real Time Clock It is possible use the RTC IC with the terminal or with a compiled program. The DS1307Z is a device I2C, and then we must install i2c-tool 17
Chapter 4 Software implementation Figure 4.3: can1 dump sudo aptitude install i2c-tool and libi2c-dev before use it. sudo aptitude install libi2c-dev 4.1.1 RTC with shell The following code allow the management of the RTC with the i2c-tool directly from the shell. Verify the DS1307Z address 0x68 with sudo i2cdetect -y 0 for Raspberry Rev 1 or sudo i2cdetect -y 1 for Rev 2 and B+, because the I2C bus address changed from 0 to 1. Run the scripts as root: modpro be rtc-ds1307 Then, run echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device (if you have a Rev 1 Pi) echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device (if you have a Rev 2 Pi) Set RTC with 18
4.2 LED Control hwclock -w Read RTC with hwclock -r 4.2 LED Control Go to home directory: cd /home/pi/ nano gpio_on.sh add these lines to the script #!/bin/sh # Set up GPIO 27 and set to output echo "27" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio27/direction # Set up GPIO 4 and set to output echo "4" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio4/direction # Write output #Led1 On echo "1" > /sys/class/gpio/gpio27/value #Led2 On echo "1" > /sys/class/gpio/gpio4/value # Clean up echo "27" > /sys/class/gpio/unexport echo "4" > /sys/class/gpio/unexport nano gpio_off.sh add these lines to the script #!/bin/sh 19
Chapter 4 Software implementation # Set up GPIO 27 and set to output echo "27" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio27/direction # Set up GPIO 4 and set to output echo "4" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio4/direction # Write output #Led1 Off echo "0" > /sys/class/gpio/gpio27/value #Led2 Off echo "0" > /sys/class/gpio/gpio4/value # Clean up echo "27" > /sys/class/gpio/unexport echo "4" > /sys/class/gpio/unexport Run the scripts as root: sh gpio_on.sh sh gpio_off.sh 20
Chapter 5 Components list In the table 5.1 we can see the Bill of Material for the board Normal and Isolated, all the components are available on-line. For simplicity, every component has a DigiKey order code (www.digikey.com). 21
Chapter 5 Components list Qty Value Package Parts Digikey-cod Cost N Cost T $ 2 Yellow 1206 LED1, LED2 754-1144-1-ND 0,21 0,42 2 120 Ω 0603 R1, R10 RMCF0603JT120RCT- ND 2 499 Ω 0603 R13, R14 RMCF0603FT499RCT- ND 0,02 0,04 0,04 0,08 4 10 kω 1206 RN1, RN2, RN3, RN4 CAT16-103J4LFCT 0,10 0,40 2 18 kω 0603 R2, R4 P18KGCT-ND 0,10 0,20 4 22pf 0603 C5, C7, C12, C13 445-1273-1-ND 0,10 0,40 6 100nf 0603 C1,C2, C4, C8, C10, C13 445-1316-1-ND 0,10 0,60 4 1uf 0603 C9 445-1322-1-ND 0,10 0,40 2 PESD1CAN SOT-23 D1, D2 568-10731-1-ND 0,42 0,84 2 16MHz HC49/US Q1, Q2 535-10226-1-ND 0,41 0,82 2 MCP2551 SOIC8 IC1, IC5 MCP2551-I/SN-ND 1,12 2,24 2 MCP2515 SOIC18 IC2, IC3 MCP2515-I/SO-ND 1,98 3,96 1 DS3231 SOIC16 IC4 DS3231S#-ND 8,35 8,35 1 CAT24C32WI- GT3 SOIC8 IC6 CAT24C32WI- GT3CT-ND 0,57 0,57 1 RETAINER COIN 12MM BAT100 BAT-HLD-012-SMT- 0,27 0,27 ND 3 X 3.5mm X1, X2 277-8807-ND 0,37 0,74 2 TERMINAL-3- PCB 1 Header 40 pos 2 x 20 SAM1086-20-ND 3,30 3,30 1 PCB 4,20 4,20 Tot 27,83 Table 5.1: CanBerryDual Pi V 2.1.2 22
Bibliography [1] Microchip. MCP2515 Datasheet. http://ww1.microchip.com/downloads/en/ devicedoc/21801e.pdf. [2] Microchip. MCP2551 Datasheet. http://ww1.microchip.com/downloads/en/ devicedoc/21667d.pdf. [3] Maxim. DS3231 Datasheet. http://datasheets.maximintegrated.com/en/ ds/ds3231-ds3231s.pdf. 23