Korenix JetBox 8152 User manual

JetBox 8152 Linux CANBus
User Manual
www.korenix.com
StockCheck.com

Korenix | Table of Content
2
Copyright Notice
Copyri ht© 2012 Korenix Technolo y Co., Ltd.
All ri hts reserved.
Reproduction without permission is prohibited.
Information provided in this manual is intended to be accurate and reliable.
However, the ori inal manufacturer assumes no responsibility for its use, or for
any infrin ements upon the ri hts of third parties that may result from its use.
The material in this document is for product information only and is subject to
chan e without notice. While reasonable efforts have been made in the
preparation of this document to assure its accuracy, Korenix assumes no liabilities
resultin from errors or omissions in this document, or from the use of the
information contained herein.
Korenix reserves the ri ht to make chan es in the product desi n without notice
to its users.
Acknowledgments
Korenix is a re istered trademark of Korenix Technolo y Co., Ltd.
All other trademarks or re istered marks in the manual belon to their respective
manufacturers.
StockCheck.com

Korenix | Table of Content
3
Table of Content
Copyright Notice ............................................................................................2
Acknowledgments..........................................................................................2
Table of Content.............................................................................................................3
Chapter Introduction ...............................................................................................4
Chapter 2 Hardware Configuration.............................................................................6
2- Pin Assignment...........................................................................................6
2-2 Jumper Setting: JP6....................................................................................6
Chapter 3 Software Configuration ..............................................................................7
3- Installation..................................................................................................7
3-2 Example......................................................................................................8
Chapter 4 Korenix Library Reference ..........................................................................9
4- How to Use Library.....................................................................................9
4-2 Functions....................................................................................................9
4-3 Structure .................................................................................................. 5
Chapter 5 Appendix .................................................................................................. 7
5- Baud Rate Table........................................................................................ 7
5-2 Error Code Table....................................................................................... 8
5-3 Notes ........................................................................................................ 9
5-4 Revision history ........................................................................................20
5-5 Customer Service .....................................................................................20
StockCheck.com

Korenix | Introduction
4
Chapter 1 Introduction
The JetBox 8 52 has two ports for I/O communications, One RS-232/422/485 port and
one CANBUS port. The CAN (Controller Area Network) is a serial bus system
especially suited for networking "intelligent" I/O devices as well as sensors and
actuators within a machine or plant. Characterized by its multi-master protocol,
real-time capability, error correction, high noise immunity, and the existence of many
different silicon components, the CAN serial bus system, originally developed by
Bosch for use in automobiles, is increasingly being used in industrial automation.
CANbus
This section describes how to program and use the CANBUS. It provides a description
of the I/O memory map of the chip and discussion of the internal registers to aid you
in programming your CAN controller chip.
Defined Memory Mapping and Interrupt
The CANBUS occupies 2 bytes of memory space. You can set the base address and
access to the internal resources of the SJA 000 CAN controller chip. The SJA 000
chip access is multiplexed in such a way that the host must first write to 300h the
internal address of the CAN chip and after that perform a write to address 301h with
the actual data to be written into the desired memory location. Address 302h is a
hardware-reset function of the SJA 000. Performing a read or write to this address
StockCheck.com

Korenix | Introduction
5
will cause a hardware reset to the CAN controller. You may need to reset the chip in
case of an unrecoverable error in the CAN controller chip. And your can use interrupt
the main processor when a message is received or transmitted if interrupts are
enabled on the JetBox 8 52. By using interrupts you can write powerful code to CAN.
Example Programming
Write 300H to the CAN controller Control byte located in the on-chip address 0.
The Example is listed below:
Outportb (0x300, 0x00) : Write CAN Address 0 (Control Register )
Outportb (0x30 , 0x78) : Write Data of CAN Address 0 (Control Register )
And please see “SJA 000.pdf” for further information of the SJA 000 chip.
Description Factory Setting
Base Address 300H
Data Of Address 30 H
Hardware Reset Of SJA 000 Chips
302H
Interrupt Require Quest
StockCheck.com

Korenix | Hardware Configuration
6
Chapter 2 Hardware Configuration
2-1 in Assignment
The CANBUS is use DB9 standard connector. The following tables show the
CANBUS signal connections of this connector.
Note : The CANBUS DB9-pin out conforms to the ISO 898/2 standard
2-2 Jumper Setting: J 6
JP6: CANBUS Ter inal Resistor Selection
Note 2: The JP6 is the CANbus termination jumper. Only two termination
jumpers should be closed at the endpoints of the CANbus. Value Terminator Resistor
( 20 Ω). The ini u speed is 20k bps. The axi u speed is 1M bps. But when
CANBUS terminator is disabled, the maximize speed of CANBUS is 125k bps. If you
want to use high speed ( M bps), please enable terminator.
DB-9
CANBUS
CANBUS
Signal
CANBUS
Description
N.C -
6 N.C -
2 CAN-L Dominant Low
7 CAN-H Dominant High
3 CAN-Ground Isolated Ground
8 N.C -
4 N.C -
9 N.C -
5 Ground Digital Ground
Case Case Ground
Factory preset
StockCheck.com

Korenix | Software Configuration
7
Chapter 3 Software Configuration
3-1 Installation
Prerequisites
To make CANBus work correctly. We have to install three components first.
Make sure your network is connected.
. GCC : call “yu install gcc”
2. OpenSSL : call “yu install openssl”
3. OpenSSL-devel : call “yu install openssl-devel.i386”
After install these components, the CANBUS library and follow example code
will work successfully.
Do the following steps to setup the driver
. Login in as root. ( username : root, password : korenix )
2. Default CanBus code are built-in jetbox linux environment. Go to the path
/CanBus and you will see the follow directory.
3. In the “library” directory. You will see the two files below.
libmycanbus.so. .0.0 :
It contains all CanBus functions that user can use it to program.
mycanbus.h :
It defines CanBus structure, message type and baud rates settings.
All details will be shown in Chapter 4.
4. In the “example” directory. You will see the files below.
StockCheck.com

Korenix | Software Configuration
8
Call “ ake” to compile files and “ ake install” to install library to /usr/lib.
All details will be shown in next session.
3-2 Example
CANBus example for Linux is a simple CAN monitor for viewing and transmitting CAN
messages. When you call “make” and “make install” to compile/install all need files.
It will generate two sample files, “cantest” and “canrcv”.
cantest
There will be four command as below :
cantest -i : Initial CanBus Chip and set baud rate to 25K.
cantest -r : Reset CanBus Chip
cantest -s : Get CanBus status
cantest -w : Write CAN message. We use standard message type in this example.
canrcv
This example show you how to receive CAN message from other CANBus. Before
to receive CAN messages, you have to reset CAN chip first and initial it.
StockCheck.com

Korenix | Korenix Library Reference
9
Chapter 4 Korenix Library Reference
This section shows how to use Korenix CANbus Library to develop your program.
When you call “make install” in the example directory, the library will be installed to
the /usr/lib path.
4-1 How to Use Library
We use dlopen to load CANBus library. You will see it in the example. Like this
handle = dlopen ("/usr/lib/lib ycanbus.so.1", RTLD_NOW);
Use dlsy to take a "handle" of a dynamic library returned by dlopen and the null
terminated symbol name, returning the address where that symbol is loaded.
Init_CanBus = dlsy (handle, "Init_Can");
Call “ an dlopen” to detail infor ation of dlopen, dlsy .
All functions (sy bol) are listed in next session.
4-2 Functions
The CanPort library provides the following functions
Init_Can
void Init_Can(BYTE BTR0, BYTE BTR )
Para eters
BTR0
BUS TIMING REGISTER 0
BTR
BUS TIMING REGISTER
This function sets configuration parameters to initialize the CAN controller.
Configuration parameters include baud rate. Valid Baud rate codes can be taken from
the Baud Rate Table.
StockCheck.com

Korenix | Korenix Library Reference
0
This function will also set up the Interrupt Enable Register, Acceptance Code Register,
Acceptance Mask Register and Output Control Register.
Can_Chip_Reset
void Can_Chip_Reset(void)
This function resets the CAN controller to default state.
The transmitting and receiving of messages will be canceled, and messages
in the driver buffer will be cleared as well.
Can_Send_Message
void Can_Send_Message(CANMsg *MsgToSend)
Para eters
MsgToSend
Message to transmit. Please refer to Structure for details.
Can_Receive_Message
void Can_Receive_Message(CANMsg *MsgToRead)
Para eters
MsgToRead
Returns a CAN message from the receive queue.
Can_Status_Report
BYTE Can_Status_Report(void)
Return
Status of CAN controller
Get the current status of the CAN controller.
StockCheck.com

Korenix | Korenix Library Reference
Note 3: More information of Status is given in the data sheet of SJA 000 in
section 6.4.5 Status Register (SR).
Can_Set_Filter
void Can_Set_Filter(DWORD dwACR, DWORD dwAMR)
This function sets the Acceptance Code and Acceptance Mask of the CAN controller.
The CAN controller must set to reset mode when calling the function.
Note 4: More information of Status is given in the data sheet of SJA 000 in
section 6.4. 5 Acceptance Filter.
Para eters
dwACR
Acceptance Code Register
dwAMR
Acceptance Mask Register
Exa ple
The following example shows the parameter values for dwACR and dwAMR in order
to accept only the Data messages of standard frame in the range 0h to 3h.
dwACR: 00 000 0000
dwAMR: 000 0000 00
Valid IDs: 00 000 00xx
ID 0h: 00 000 0000
ID h: 00 000 000
ID 2h: 00 000 00 0
ID 3h: 00 000 00
So the value of dwACR is 0x22 FFFFF and the value of dwAMR is 0x007FFFFF.
StockCheck.com

Korenix | Korenix Library Reference
2
Can_Reset_Filter
void Can_Reset_Filter(void)
This function reset the Acceptance Code and Acceptance Mask Register of the CAN to
default value (It means accept all CAN message).
Can_Interrupt_Status
BYTE Can_Interrupt_Status(void)
Return
The value of Interrupt Register
Note 5: More information of Status is given in the data sheet of SJA 000 in
section 6.4.6 Interrupt Register (IR).
Can_Mode_Set
void Can_Mode_Set(BYTE bMode)
Para eters
bMode
operation mode
Description Value
SLEEP_MODE 0x 0
ACCEPT_FILTER_MODE 0x08
SELF_TEST_MODE 0x04
LISTEN_ONLY_MODE 0x02
RESET_MODE 0x0
NORMAL_MODE 0x00
StockCheck.com

Korenix | Korenix Library Reference
3
Note 6: More information of Status is given in the data sheet of SJA 000 in
section 6.4.3 Mod Register (MOD).
Can_Set_BTR
void Can_Set_BTR(BYTE BTR0, BYTE BTR )
Para eters
BTR0
BUS TIMING REGISTER 0
BTR
BUS TIMING REGISTER
This function only sets the baud rate to CAN controller.
Can_Set_Co and
void Can_Set_Command(BYTE bCmd)
Para eters
bCmd
Command mode
Description Value
CLEAR_DATA_OVERRUN 0x08
RELEASE_RECEIVE_BUFFER 0x04
ABORT_TRANSMISSION 0x02
TRANSMISSION_REQUEST 0x0
Note 7: More information of Status is given in the data sheet of SJA 000 in
section 6.4.4 Command Register (CMR).
StockCheck.com

Korenix | Korenix Library Reference
4
Can_Get_ECR
BYTE Can_Get_ECR(void)
Return
The value of Error Code Capture Register.
Note 8: Please refer to Error Code Table for details.
Note 9: More information of Status is given in the data sheet of SJA 000 in
section 6.4.9.
Can_Get_ALC
BYTE Can_Get_ALC(void)
Return
The value of Arbitration Lost Capture Register.
Can_Get_EWL
BYTE Can_Get_EWL(void)
Return
The value of Error Warning Limit Register.
The error warning limit can be defined within this register. The default value (after
hardware reset) is 96.
Note 0: More information of Status is given in the data sheet of SJA 000 in
section 6.4. 0.
StockCheck.com

Korenix | Korenix Library Reference
5
Can_Get_TXERROR_COUNTER
BYTE Can_Get_TXERROR_COUNTER(void)
Return
The value of transmit error.
The TX error counter register reflects the current value of the transmit error counter.
Note : More information of Status is given in the data sheet of SJA 000 in
section 6.4. 2.
Can_Get_RXERROR_COUNTER
BYTE Can_Get_RXERROR_COUNTER(void)
Return
The value of receive error.
The RX error counter register reflects the current value of the receive error counter.
Note 2: More information of Status is given in the data sheet of SJA 000 in
section 6.4. .
4-3 Structure
The CanPort API defines the following structures
CANMsg :Defines a CAN message
typedef struct {
DWORD ID;
BYTE MSGTYPE;
BYTE LEN;
BYTE DATA[8];
} CANMsg;
StockCheck.com

Korenix | Korenix Library Reference
6
ID
/29-bit CAN identifier.
MSGTYPE
Bit mask indicating the type of the message. Several message types can be
combined.
Identifer Value Description
MSGTYPE_STANDARD 00h Data Frame. CAN message with data contents
and an -bit CAN ID.
MSGTYPE_RTR 0 h Remote Transmit Request (RTR).
MSGTYPE_EXTENDED 02h Data Frame. CAN message with data contents
according to CAN 2.0B standard (29-bit CAN ID).
LEN
Number of data bytes in a data message (Data Length Code).
DATA
Data bytes of a CAN message. The size can be 0 to 8 bytes.
StockCheck.com

Korenix | Appendix
7
Chapter 5 Appendix
5-1 Baud Rate Table
Baud Rate (bps) Predefined BTR0 BTR BTR0 BTR
5K BAUD_5K 7F 7F
0K BAUD_ 0K 67 2F
20K BAUD _20K 53 2F
50K BAUD _50K 47 2F
00K BAUD _ 00K 43 2F
25K BAUD _ 25K 03 C
250K BAUD _250K 0 C
500K BAUD_500K 00 C
000K BAUD_ M 00 4
The following Baud Rates are also common:
Baud Rate (bps) BTR0 BTR
33.33K D 4
47.6K 4 4
83.33K 4B 4
95.23K C3 4E
800K 00 6
Note 3: More information on setting the bit rate is given in the data sheet of SJA
000 in section 6.5.
StockCheck.com

Korenix | Appendix
8
5-2 Error Code Table
BIT 7
BIT 6
BIT 5
BIT 4
BIT 3
BIT 2
BIT
BIT 0
Description
0 0 bit error
0 form error
0 stuff error
other type of error
0 error occurred during reception
error occurred during transmission
0 0 0 start of frame
0 0 0 0 ID.28 to ID.2
0 0 0 ID.20 to ID. 8
0 0 0 0 bit SRTR
0 0 0 bit IDE
0 0 ID. 7 to ID. 3
0 ID. 2 to ID.5
0 0 ID.4 to ID.0
0 0 0 bit RTR
0 0 reserved bit
0 0 0 reserved bit0
0 0 data length code
0 0 0 data field
0 0 0 0 CRC sequence
0 0 0 CRC delimiter
0 0 acknowledge slot
0 acknowledge delimiter
0 0 end of frame
StockCheck.com

Korenix | Appendix
9
0 0 0 intermission
0 0 0 active error flag
0 0 passive error flag
0 0 tolerate dominant bits
0 error delimiter
0 0 overload flag
5-3 Notes
Note : The CANBUS DB9-pin out conforms to the ISO 898/2 standard ..6
Note 2: The JP6 is the CANbus termination jumper. Only two termination
jumpers should be closed at the endpoints of the CANbus. Value
Terminator Resistor ( 20 Ω). The ini u speed is 20k bps. The
axi u speed is 1M bps. But when CANBUS terminator is disabled,
the maximize speed of CANBUS is 125k bps. If you want to use high
speed ( M bps), please enable terminator. ..........................................6
Note 3: More information of Status is given in the data sheet of SJA 000 in
section 6.4.5 Status Register (SR).........................................................
Note 4: More information of Status is given in the data sheet of SJA 000 in
section 6.4. 5 Acceptance Filter. .........................................................
Note 5: More information of Status is given in the data sheet of SJA 000 in
section 6.4.6 Interrupt Register (IR)..................................................... 2
Note 6: More information of Status is given in the data sheet of SJA 000 in
section 6.4.3 Mod Register (MOD). ..................................................... 3
Note 7: More information of Status is given in the data sheet of SJA 000 in
section 6.4.4 Command Register (CMR). ............................................. 3
Note 8: Please refer to Error Code Table for details. ................................... 4
Note 9: More information of Status is given in the data sheet of SJA 000 in
section 6.4.9......................................................................................... 4
Note 0: More information of Status is given in the data sheet of SJA 000
in section 6.4. 0................................................................................... 4
Note : More information of Status is given in the data sheet of SJA 000
in section 6.4. 2................................................................................... 5
StockCheck.com

Korenix | Appendix
20
Note 2: More information of Status is given in the data sheet of SJA 000
in section 6.4. ................................................................................... 5
Note 3: More information on setting the bit rate is given in the data sheet
of SJA 000 in section 6.5. ................................................................... 7
Note: You can get the SJA1000 datasheet fro following website:
http://www.nxp.com/documents/data_sheet/SJA 000.pdf
5-4 Revision history
V0. by 20 2/9/4
-Change default CANbus terminator jump setting (JP6) to enable
5-5 Customer Service
Korenix Technolo ies Co., Ltd.
Business service: [email protected]
Customer service: koreCARE@korenix.com
StockCheck.com
Table of contents
Other Korenix Network Hardware manuals
Popular Network Hardware manuals by other brands

WatchNet
WatchNet ENM-04 POE Quick connection guide

Johnson Controls
Johnson Controls Metasys NAE55 installation guide

ADTRAN
ADTRAN Total Reach TRDDB Installation and Maintenance

Orolia
Orolia GNSSource-1000 user manual

Cisco
Cisco ONS 15454 SDH Procedure guide

NComputing
NComputing OfficeStation L110 user guide