august 2013 industrial berry€¦ · i i “industrialberry_datasheet” — 2013/8/14 — 18:52...

25
CanBarry PI V 1.0 INDUSTRIAL BERRY www.industrialberry.com August 2013

Upload: others

Post on 06-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 1 — #1 ii

ii

ii

CanBarry PI V 1.0

INDUSTRIALBERRY

www.industrialberry.com

August 2013

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 2 — #2 ii

ii

ii

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page i — #3 ii

ii

ii

Contents

1 License 1

2 Introduction 3

3 Hardware implementation 5

4 Software implementation 94.1 Real Time Clock . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.1.1 RTC with shell . . . . . . . . . . . . . . . . . . . . . . . 94.1.2 RTC with a compiled C code . . . . . . . . . . . . . . . 11

5 Components list 15

Bibliography 17

i

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page ii — #4 ii

ii

ii

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page iii — #5 ii

ii

ii

List of Figures

2.1 CanBerry PI on Raspberry . . . . . . . . . . . . . . . . . . . . 4

3.1 Electric diagram of CanBus block . . . . . . . . . . . . . . . . . 63.2 Electric diagram of RTC block . . . . . . . . . . . . . . . . . . 73.3 CanBerry Connector . . . . . . . . . . . . . . . . . . . . . . . . 7

iii

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page iv — #6 ii

ii

ii

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page v — #7 ii

ii

ii

List of Tables

5.1 CanBerry Pi V 1.0 . . . . . . . . . . . . . . . . . . . . . . . . . 16

v

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page vi — #8 ii

ii

ii

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 1 — #9 ii

ii

ii

Chapter 1

License

Open-source hardware shares much of the principles and approach of free andopen-source software. In particular, we believe that people should be ableto study our hardware to understand how it works, make changes to it, andshare those changes. To facilitate this, we release all of the original design files(Eagle CAD) for the IndustrialBerry hardware. These files are licensed undera Creative Commons Attribution Share-Alike license, which allows for bothpersonal and commercial derivative works, as long as they credit Industrial-Berry and release their designs under the same license. The IndustrialBerrysoftware/firmware is also open-source.

1

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 2 — #10 ii

ii

ii

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 3 — #11 ii

ii

ii

Chapter 2

Introduction

CanBerry Pi V 1.0 is an extension board for RaspBerry Pi. It is an OpenHardware Design. It has two functionalities: a can bus module and an onboardReal Time clock powered by a 12 mm battery. In fig 2.1 is shown the Boardon Raspberry PI.The CanBus is based on MCP2515 [1] SPI controller and the MCP2551 [2]

tranceiver. All functionalities are full integrated in standard linux kernel, so,they can be avaible on fly, or at last recompiling linux kernel to add canbusfunctionalities. The real time clock is based on PCF8523 [3] I2C controller. It isfull compatible with linux too. Using I2C Kernel module, and standard kernelfunctions, date and hour can be set/get by simple commands. On the bottomside is located an on board battery to guarantee a data autonomy more than 20years. In chapter hardware there are all informations on principal components,schematics to rebuild and modify RaspBerry PI board. In chapter Software isreported how all hardware can be used: as recompile kernel, build simple userspace function to set and get I2C data, etc... In chapter application is reporteda typical example of how to use the board.

3

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 4 — #12 ii

ii

ii

Chapter 2 Introduction

Figure 2.1: CanBerry PI on Raspberry

4

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 5 — #13 ii

ii

ii

Chapter 3

Hardware implementation

CanBarry PI 1.0 is composed bu two blocks: a CanBus Module shown in Fig.3.1 and a Real Time Clock shown in 3.2MCP2515 is a stand alone SPI canbus controller full integrated in linux

kernel. At the start, the driver was implemented as a block device. Recently itis assumed to be a network module into the kernel. It is supplied by 3.3V fromraspberry connector (fig 3.3 ). MCP2551 is supplied by 5V from Raspberryconnector insted. So, to match voltage physical level between the two chips, avoltage matching made by R3 and R4 has been used.

5

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 6 — #14 ii

ii

ii

Chapter 3 Hardware implementation

14/0

4/20

13 1

6:50

:38

D:\R

aspb

erry

_har

dwar

e\C

AN&R

TC\C

AN&R

TC1v

0\C

AN&R

TC.s

ch (S

heet

: 1/1

)

Bat

tery

Hol

der C

R20

32

GN

DG

ND

10k

10k

100n

F

32.7

68kH

z

GN

D

V+

GN

D

GN

DV+

MC

P25

15-I/

SO

GR

B2

RS

C 6

28-3

548

120R

18k

10k 10

0nF

100n

F

22pF22pF

GN

D

GN

D

GN

DG

ND

V+

GN

D

GN

D

4k7

GN

D

4k7V+

GN

D

n.c.

n.c. GN

Dn.c.

n.c. GN

D

GN

DG

ND

500R

500R

V+

V+

V+

V+

V+

1uF

16Mhz

GN

D

1 2 3 4

JP1

R8

R11

C8

X11

X22

Q2

1 2

JP2

OSC

IO

SCO

VBAT

GN

DSD

ASC

L

INT

VDD

IC3

F

F1

F

F2

1-+3

V31

2-+5

V2

3-SD

A03

4-D

NC

4

5-SC

L05

6-G

ND

6

7-G

PIO

77

8-TX

8

9-D

NC

910

-RX

10

11-G

PIO

011

12-G

PIO

112

13-G

PIO

213

14-D

NC

14

15-G

PIO

315

16-G

PIO

416

17-D

NC

1718

-GPI

O5

18

19-S

PI-M

OSI

1920

-DN

C20

21-S

PI-M

ISO

2122

-GPI

O6

22

23-S

PI-S

CLK

2324

-SPI

-CE0

-N24

25-D

NC

2526

-SPI

-CE1

-N26

RES

ET17

CS

16

SO15

SI14

SCK

13

INT

12

RX0

BF11

RX1

BF10

TX0R

TS4

TX1R

TS5

TX2R

TS6

VDD

18

TXC

AN1

RXC

AN2

CLK

OU

T3

OSC

27

OSC

18

VSS

9

IC2

1JP32 R10

TXD

1

RXD

4

VSS

2

VDD

3C

ANH

7

CAN

L6

RS

8

VREF

5

IC1

R4

R3

C4

C2

C7C5

R7

R5

C6

R9C3

R6

LED2

R1

LED1

R2

BAT100

C1

Q1

22

11

33

SD

A

SD

A

SD

AS

CL

SC

L

SC

L

LED

1LE

D2

OU

T

OU

T

OS

CI

OSCI

OS

CO

OSCO

PI_

5V

PI_

5VP

I_S

PI_

CE

0

PI_

SP

I_C

E0

PI_

SP

I_S

CLK

PI_

SP

I_S

CLK

PI_

SP

I_M

ISO

PI_

SP

I_M

ISO

PI_

SP

I_M

OS

I

PI_

SP

I_M

OS

I

PI_

GP

IO_P

IN22

PI_

GP

IO_P

IN22

MCP2551

Dra

wn

By:

Title

:Ve

rsio

n:

JP4

Figure 3.1: Electric diagram of CanBus block

6

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 7 — #15 ii

ii

ii

14/04/2013 16:50:16 D:\Raspberry_hardware\CAN&RTC\CAN&RTC1v0\CAN&RTC.sch (Sheet: 1/1)

Battery Holder CR2032

GNDGND

10k

10k

100nF

32.768kHz

GND

V+

GND

GND

V+

MCP2515-I/SOGRB2 RSC 628-3548

120R

18k

10k

100nF

100nF

22pF

22pF

GND

GND

GNDGND

V+

GND

GND

4k7GND

4k7

V+

GND

n.c.

n.c.

GND

n.c.

n.c.

GND

GND GND

500R

500R

V+

V+V

+

V+

V+

1uF

16M

hz

GND

1234

JP1

R8

R11

C8

X1 1X22

Q2

12

JP2OSCIOSCO

VBATGND SDA

SCL

INTVDD

IC3

F

F1

F

F2

1-+3V31 2-+5V 2

3-SDA03 4-DNC 4

5-SCL05 6-GND 6

7-GPIO77 8-TX 8

9-DNC9 10-RX 10

11-GPIO011 12-GPIO1 12

13-GPIO213 14-DNC 14

15-GPIO315 16-GPIO4 16

17-DNC17 18-GPIO5 18

19-SPI-MOSI19 20-DNC 20

21-SPI-MISO21 22-GPIO6 22

23-SPI-SCLK23 24-SPI-CE0-N 24

25-DNC25 26-SPI-CE1-N 26

RESET17

CS16

SO15

SI14

SCK13

INT12

RX0BF11

RX1BF10

TX0RTS4

TX1RTS5

TX2RTS6

VDD 18

TXCAN 1

RXCAN 2

CLKOUT 3

OSC2 7

OSC1 8

VSS 9

IC2

1JP

32

R10

TXD1

RXD4

VSS2

VDD3 CANH 7

CANL 6

RS 8

VREF 5

IC1

R4

R3

C4

C2

C7

C5

R7

R5

C6

R9

C3

R6

LED

2

R1

LED

1

R2

BAT

100

C1

Q1

22

11

33

SDA

SDA

SDASCL

SCL

SCL

LED1 LED2

OUT

OUT

OSCI

OS

CI

OSCOOS

CO

PI_5V

PI_5VPI_SPI_CE0

PI_SPI_CE0PI_SPI_SCLK

PI_SPI_SCLK

PI_SPI_MISO

PI_SPI_MISO

PI_SPI_MOSI

PI_SPI_MOSI

PI_GPIO_PIN22

PI_GPIO_PIN22

MC

P25

51

Drawn By:

Title:Version:

JP4

Figure 3.2: Electric diagram of RTC block

14/04/2013 16:51:00 D:\Raspberry_hardware\CAN&RTC\CAN&RTC1v0\CAN&RTC.sch (Sheet: 1/1)

Battery Holder CR2032

GNDGND

10k

10k

100nF

32.768kHz

GND

V+

GND

GND

V+

MCP2515-I/SOGRB2 RSC 628-3548

120R

18k

10k

100nF

100nF

22pF

22pF

GND

GND

GNDGND

V+

GND

GND

4k7GND

4k7

V+

GND

n.c.

n.c.

GND

n.c.

n.c.

GND

GND GND

500R

500R

V+

V+V

+

V+

V+

1uF

16M

hz

GND

1234

JP1

R8

R11

C8

X1 1X22

Q2

12

JP2OSCIOSCO

VBATGND SDA

SCL

INTVDD

IC3

F

F1

F

F2

1-+3V31 2-+5V 2

3-SDA03 4-DNC 4

5-SCL05 6-GND 6

7-GPIO77 8-TX 8

9-DNC9 10-RX 10

11-GPIO011 12-GPIO1 12

13-GPIO213 14-DNC 14

15-GPIO315 16-GPIO4 16

17-DNC17 18-GPIO5 18

19-SPI-MOSI19 20-DNC 20

21-SPI-MISO21 22-GPIO6 22

23-SPI-SCLK23 24-SPI-CE0-N 24

25-DNC25 26-SPI-CE1-N 26

RESET17

CS16

SO15

SI14

SCK13

INT12

RX0BF11

RX1BF10

TX0RTS4

TX1RTS5

TX2RTS6

VDD 18

TXCAN 1

RXCAN 2

CLKOUT 3

OSC2 7

OSC1 8

VSS 9

IC2

1JP

32

R10

TXD1

RXD4

VSS2

VDD3 CANH 7

CANL 6

RS 8

VREF 5

IC1

R4

R3

C4

C2

C7

C5

R7

R5

C6

R9

C3

R6

LED

2

R1

LED

1

R2

BAT

100

C1

Q1

22

11

33

SDA

SDA

SDASCL

SCL

SCL

LED1 LED2

OUT

OUT

OSCI

OS

CI

OSCOOS

CO

PI_5V

PI_5VPI_SPI_CE0

PI_SPI_CE0PI_SPI_SCLK

PI_SPI_SCLK

PI_SPI_MISO

PI_SPI_MISO

PI_SPI_MOSI

PI_SPI_MOSI

PI_GPIO_PIN22

PI_GPIO_PIN22

MC

P25

51

Drawn By:

Title:Version:

JP4

Figure 3.3: CanBerry Connector

7

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 8 — #16 ii

ii

ii

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 9 — #17 ii

ii

ii

Chapter 4

Software implementation

4.1 Real Time ClockIt is possible use the RTC IC with the terminal or with a compiled program.The PCF8523 is a device I2C, and then we must install i2c-tool

sudo aptitude install i2c-tool

and libi2c-dev before use it.

sudo aptitude install libi2c-dev

4.1.1 RTC with shellThe following code allow the management of the RTC with the i2c-tool directlyfrom the shell.

### BEGIN INIT INFO#RTC Set### END INIT INFO

#! /bin/sh# /record.sh

USER=piHOME=/pi

export USER HOME

case "$1" inset)

echo "Setting time on PCF8523"#Set Control Reg 1i2cset -y 0 0x68 0x00 0x10 b

9

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 10 — #18 ii

ii

ii

Chapter 4 Software implementation

#Set Control Reg 3i2cset -y 0 0x68 0x02 0x20 becho "Year"i2cset -y 0 0x68 0x09 13 becho "Month"i2cset -y 0 0x68 0x08 3 becho "Day"i2cset -y 0 0x68 0x06 16 becho "Hour"i2cset -y 0 0x68 0x05 22 becho "Min"i2cset -y 0 0x68 0x04 50 becho "Second"i2cset -y 0 0x68 0x03 25 b

;;

get)echo "Getting register value"echo "Year"i2cget -y 0 0x68 0x09echo "Month"i2cget -y 0 0x68 0x08echo "Day"i2cget -y 0 0x68 0x06echo "Hour"i2cget -y 0 0x68 0x05echo "Min"i2cget -y 0 0x68 0x04echo "Second"i2cget -y 0 0x68 0x03;;

*)echo "Usage: record.sh set|get"exit 1;;

esac

exit 0

10

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 11 — #19 ii

ii

ii

4.1 Real Time Clock

4.1.2 RTC with a compiled C code

The following code allow the management of the RTC with the libi2c-dev froma C program.

/* pcf8523.cpcf8523_i2c_rtc.c - example of accessing a PCF8563 viathe BSC0 (I2C) peripheral on a BCM2835 (Raspberry Pi)

*/#include <linux/i2c-dev.h>#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <stdint.h>#include <errno.h>#include <string.h>

#define ADDR 0x68int fd;int year;int month;int day;int hour;int min;int sec;

void open_i2c()

fd = open( "/dev/i2c-0", O_RDWR );if( ioctl( fd, I2C_SLAVE, ADDR ) < 0 )

fprintf( stderr, "Failed to set slave address: %m\n" );

void set_time()

if( i2c_smbus_write_byte_data( fd, 0x09, year ) < 0 )fprintf( stderr, "Failed to write YEAR to I2C device: %m\n" );if( i2c_smbus_write_byte_data( fd, 0x08, month ) < 0 )fprintf( stderr, "Failed to write MONTH to I2C device: %m\n" );if( i2c_smbus_write_byte_data( fd, 0x06, day ) < 0 )fprintf( stderr, "Failed to write DAY to I2C device: %m\n" );

11

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 12 — #20 ii

ii

ii

Chapter 4 Software implementation

if( i2c_smbus_write_byte_data( fd, 0x05, hour ) < 0 )fprintf( stderr, "Failed to write HOUR to I2C device: %m\n" );if( i2c_smbus_write_byte_data( fd, 0x04, min ) < 0 )fprintf( stderr, "Failed to write MIN to I2C device: %m\n" );if( i2c_smbus_write_byte_data( fd, 0x03, sec ) < 0 )fprintf( stderr, "Failed to write SEC to I2C device: %m\n" );if( i2c_smbus_write_byte_data( fd, 0x02, 0x20 ) < 0 )fprintf( stderr, "Failed to write Reg3 to I2C device: %m\n" );if( i2c_smbus_write_byte_data( fd, 0x00, 0x10 ) < 0 )fprintf( stderr, "Failed to write Reg1 to I2C device: %m\n" );printf("RTC pcf8523 setted \n");

void get_time(void)year = i2c_smbus_read_byte_data(fd, 0x09);month = i2c_smbus_read_byte_data(fd, 0x08);day = i2c_smbus_read_byte_data(fd, 0x06);hour = i2c_smbus_read_byte_data(fd, 0x05);min = i2c_smbus_read_byte_data(fd, 0x04);sec = i2c_smbus_read_byte_data(fd, 0x03);printf("PCF8523 Time ");if (hour <10)

printf("0%i:", hour);else

printf("%i:", hour);

if (min <10)printf("0%i:", min);

elseprintf("%i:", min);

if (sec <10)printf("0%x", sec);

elseprintf("%x", sec);

if (day <10)printf(" Date 0%i/", day);

elseprintf(" Date %i/", day);

if (month <10)printf("0%i/", month);

else

12

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 13 — #21 ii

ii

ii

4.1 Real Time Clock

printf("%i/", month);

printf("20%i\n", year);

void get_data(void)

printf ("Input Day: ");while (!(scanf("%d", &day) != 0 && day <= 31 && day > 0))

while (getchar() != ’\n’);printf ("Try again: ");

printf ("Input Month: ");while (!(scanf("%d", &month) != 0 && month <= 12 && month > 0))

while (getchar() != ’\n’);printf ("Try again: ");

printf ("Input Year: ");while (!(scanf("%d", &year) != 0 && year <= 99 && year > 0))

while (getchar() != ’\n’);printf ("Try again: ");

printf ("Input Hour: ");while (!(scanf("%d", &hour) != 0 && hour <= 24 && hour >= 0))

while (getchar() != ’\n’);printf ("Try again: ");

printf ("Input Min: ");while (!(scanf("%d", &min) != 0 && min <= 60 && min >= 0))

while (getchar() != ’\n’);printf ("Try again: ");

printf ("Input Sec: ");while (!(scanf("%x", &sec) != 0 && sec <= 60 && sec >= 0))

while (getchar() != ’\n’);

13

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 14 — #22 ii

ii

ii

Chapter 4 Software implementation

printf ("Try again: ");

int main(int argc, char *argv[]) if (argc < 2)

open_i2c(); // Open i2cget_time();printf("Type pcf8523 -s for set RTC\n");

else if (argc == 2)if (!strcmp (argv[1],"-s"))

open_i2c(); // Open i2cget_time();printf("Setting RTC pcf8523 \n");get_data();set_time();

else printf("Argument error\n");

else printf("Too many arguments\n");// Done!

The program pcf8523 allows simple operations on the RTC, for example, wecan set and read the time and the date. We can see how the PCF8523 works:

pi@raspberrypi ~/compiler_test $ ./pcf8523PCF8523 Time 17:24:29 Date 28/04/2013Type pcf8523 -s for set RTCpi@raspberrypi ~/compiler_test $ ./pcf8523 -sPCF8523 Time 17:25:13 Date 28/04/2013Setting RTC pcf8523Input Day: 30Input Month: 4Input Year: 13Input Hour: 18Input Min: 10Input Sec: 12RTC pcf8523 settedpi@raspberrypi ~/compiler_test $ ./pcf8523PCF8523 Time 18:10:16 Date 30/04/2013Type pcf8523 -s for set RTC

14

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 15 — #23 ii

ii

ii

Chapter 5

Components list

In the table 5.1 we can see the Bill of Material for the board, all the componentsare available on-line. For simplicity, every component has a DigiKey order code(www.digikey.com).

15

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 16 — #24 ii

ii

ii

Chapter 5 Components list

Quantity

ValuePackage

PartsDigikey-cod

Unit

Price$

2Yellow

1206LED

1,LED2

754-1144-1-ND

0,210,42

1120

Ω0603

R10

RMCF0603JT

120RCT-N

D0,02

0,022

499Ω

0603R1,R

2RMCF0603FT

499RCT-N

D0,04

0,082

4.7kΩ

0603R5,R

7RMCF0603JT

4K70C

T-N

D0,02

0,043

10kΩ

0603R3,R

8,R11

P10KGCT-N

D0,10

0,301

18kΩ

0603R4

P18KGCT-N

D0,10

0,102

22pf0603

C5,C

7445-1273-1-N

D0,10

0,203

100nf0603

C2,C

4,C8

445-1316-1-ND

0,100,30

11uf

0603C1

445-1322-1-ND

0,100,10

132.768kH

zQ2

X801-N

D0,49

0,491

16MHz

Q1

535-10226-1-ND

0,410,41

1PC

F8523SO

IC8

IC3

568-5306-1-ND

1,361,36

1MCP2515

SOIC

18IC

2MCP2515-I/SO

-ND

1,981,98

1MCP2551

SOIC

8IC

1MCP2551-I/SN

-ND

1,121,12

1RETA

INER

COIN

12MM

BAT

100BK-890-N

D0,32

0,321

TER

MIN

AL-3-PC

B3X

3.5mm

X1

277-5749-ND

1,511,51

1Header

26pos

2X

13SA

M1086-13-N

D2,97

2,971

PCB

2,502,50

Total14,22

Table5.1:C

anBerry

PiV1.0

16

ii

“industrialberry_datasheet” — 2013/8/14 — 18:52 — page 17 — #25 ii

ii

ii

Bibliography

[1] Microchip. MCP2515 Datasheet.

[2] Microchip. MCP2551 Datasheet.

[3] NXP. PCF8523 Datasheet.

17