background image

Chapter 3   Software Programming   

19

Example program

The following example program, can84 I.lib, implements the sending
and receiving of messages over the CAN controller. The program is
written in C.

#include "can841.h" /*Library function declaration*/

/*------------------------------------------------*/

/* CAN controller interrupt connection */

#define CAN1_IRQ 12 /* 0 means polling */

#define CAN2_IRQ 15 /* 0 means polling */

#define PORT1 0

#define PORT2 1

#define FAIL 0

#define SUCCESS 1

void main(void)

(

/* Declare the CAN card segment address. */

UI gSegment=OxDA00;

CAN_STRUCT canl, can2;

MSG_STRUCT smsql, smsg2;

MSG_STRUCT rmsql, rmsg2;

UI i;

if(canInitHW(gSegment,CANl_IRQ,CAN2 IRQ)==FAIL)

{

clrscr();

cprintf(“\n\n Hardware Initialization Error.’);

return;

}

/* Reset CAN controller */

canReset(PORT1);

canReset(PORT2);

canl.acc_code=0;

/*

*/

canl.acc mask=Oxff;

/*

*/

canl.btO=03;

/* baud rate lMbps

*/

canl.btl=0xlc;

if(canConfig(PORTl,canl)==FAIL)

{

clrscr();

cprintf("\n\n CAN Port %d Configuration Error",1);

return;

{

Summary of Contents for PCL-841 Series

Page 1: ...locations 7 Card configuration 8 Chapter 3 SoftwareProgramming 13 Library functions 14 Exampleprogram 19 Chapter 4 DataMonitor Utility 21 Software overview 22 Main Menu 22 Chapter 5 Wiring 27 Pin assignments 28 CAN signal wiring 29 Appendix A Register structure 31 CAN controller address allocation 32 Register address map 33 Register descriptions 34 ...

Page 2: ...1 Introduction C H A P T E R ...

Page 3: ...rea Network is a serial bus systcm cspecially suitcd for networking intelligent 1 0 deviccs as well as sensors and actuators within a machine or plant Characterized by its multi mastcr protocol rcal time capability error correction high noise immunity and thc cxistencc of many different silicon components the CAN serial bus system originally developed by Bosch for use in automo biles is increasing...

Page 4: ...s IRQ3 4 5 6 7 9 10 11 12 15 LED indicates Transmit Receive status on each port Direct memory mapping enables speedy access to the CAN controllers C library and examples included Specifications Ports 2 CAN controller SJA 1000 CANtransceiver 82C250 Signal support CAN L CAN H Memoryaddress FromC800HtoEFOOH IRQ 3 4 5 6 7 9 10 11 12 15 Isolationvoltage 1000VDC Power consumption 5 V 400 mA typical 950 ...

Page 5: ...4 PCL 841 Series User s Manual ...

Page 6: ...2 Hardware Installation C H A P T E R ...

Page 7: ...in the ship ping carton and packing material for inspection by the carrier After inspection we will make arrangements to repair or replace the unit When you handle the PCL 841 remove it from its protective packag ing by grasping the rear metal panel Keep the anti vibration packing Whenever you remove the card from the PC store it in this package for protection Warning Modern electronic devices are...

Page 8: ...Chapter 2 Hardware Installation 7 Jumper and switch locations ...

Page 9: ... previous page for jumper and switch locations Switch and jumper functions CAN controllers JP1 Po rt 1 JP2 Port 2 Mennory base address SW1 Port 1 Port 2 Default settings Port I is set for COMI IRQ 12 Memory address DA00 0000 Port 2 is set for COM2 IRQ IS Memory address DA00 0200 If you need to change these settings see the following sections Otherwise you can simply install the card Note that you ...

Page 10: ...ress for the PCL 841 which requires 4 KB of address space is made up of the memory segment and its associated offset The address for the memory segment is set through SWI a six position DIP switch You can choose any base address from C800 to EFOO The following table shows the DIP switch settings and the corresponding base addresses Memory address configUration SW1 Address DIPswitch A12 A13 A14 A15...

Page 11: ... off on off off on DBOOH off off on off off on DCOOH on on off off off on DDOOH off on off off off on DEOOH on off off off off on DFOOH off off off off off on EOOOH on on on on on off E100H off on on on on off E200H on off on on on off E300H off off on on on off E400H on on off on on off ESOOH off on off on on off E600H on off off on on off E700H off off off on on off E800H on on on off on off E9O...

Page 12: ...y assigned for Port 1 Port 2 and hardware reset The following table shows the base addresses of the CAN controllers Base address hex CAN controller base 0000h base 00FFh Basic Port 1 base 0100h base 01FFh HW reset Basic Port 1 base 0200h base 02FFh Basic Port 2 base 0300h base 03FFh HW reset Basic Port 2 base 0400h base 0FFFh Not used ...

Page 13: ...12 PCL 841 Series User s Manual ...

Page 14: ...3 Software Programming C H A P T E R ...

Page 15: ...sets CAN port 4 canConfig Controls CAN port settings 5 canNormalR n Sets mode 6 canSendMsg Sends message 7 canReceiveMsg Reads data Complete function description Function 1 Sets an IRQ number for Port I and Port 2 Command canluitHW Ulsegment BYTEIRQI BYTEIRQ2 Argument UIsegment BYTEIRQI BYTEIRQ2 segment c000 df00 step 0x100 IRQI Port I IRQ number 0 polling 3 4 5 6 7 8 9 10 1 1 12 14 15 IRQ2 Port 2...

Page 16: ...ntf HARDWAREINITIALIZATIONERROR n Function 2 Releases all seuings of the CAN card Command canExitHW Argument None Response l successful 0 fail Example include can84 1 h main if canExitHW 0 printf CAN RELEASE FAIL n Function 3 Resets CAN port and flushes the TX RX buffers Command int canReset BYTE port Argument BYTE port port port number 0 or 1 Response l successful 0 fail ...

Page 17: ...ort CAN STRUCTcan Argument BYTE port CAN_STRUCT can port port number 0 or 1 can CAN struct pointer Response l successful 0 fail Example include canB4 1 h main CAN_STRUCT canl can2 can 1 acc_code 0 can 1 acc_mask 0xff can 1 bt0 0 can 1 bt I 0x 1 c if canConfig 0 canl 0 printf CANPORTICONFIGUREERROR n Function 5 Sets a CAN port to normal mode for normal operation Command canNormalRun BYTE port Argum...

Page 18: ...AN port to send a message Command canSendMsg BYTEport MSG_STRUCTsendmsg Argument BYTE port MSG_STRUCT send_msg port port number O or 1 send msg send buffer pointer Response l successful 0 fail Example include can84 1 h main MSG_STRUCT smsg 1 Uli smsg 1 id 0x015 smsg l rtr 0 smsg l dlen 8 for i 0 i smsg l dlen i smsg l data i i if canSendMsg 0 smsg 1 l printf TRANSMISSION SUCCESSFUL n ...

Page 19: ...tr Argument BYTEport MSG_STRUCT msg ptr port port number O or 1 msg_ptr input buffer pointer Response l message received 0 no message received Example include can841 h main MSG_STRUCTrmsg2 if canReceiveMSG rmsg2 1 printf Port2 receive ID 3X RTR ld Length ld rmsg2 id rmsg2 rtr rmsg2 dlen for i 0 i rmsg2 dlen i cprintf 2X rmsg2 data i ...

Page 20: ...eans polling define PORT1 0 define PORT2 1 define FAIL 0 define SUCCESS 1 void main void Declare the CAN card segment address UI gSegment OxDA00 CAN_STRUCT canl can2 MSG_STRUCT smsql smsg2 MSG_STRUCT rmsql rmsg2 UI i if canInitHW gSegment CANl_IRQ CAN2 IRQ FAIL clrscr cprintf n n Hardware Initialization Error return Reset CAN controller canReset PORT1 canReset PORT2 canl acc_code 0 canl acc mask O...

Page 21: ...AN2 into normal mode clrscr smsgl id 0x015 Set ID 8 smsql rtr l Data lengths 8 smsgl dlen 8 for i 0 i smsql dlen i smsgl data i i while l canSendMsg PORTl smsgl Send to CAN1 if canReceiveMsg PORT2 rmsg2 1 cprintf PORT2 receive ID 3X RTR ld Length ld rmsg2 id rmsg2 rtr rmsg2 dlen for i 0 i rmsg2 dlen i cprintf 2X rmsg2 data il printf n if kbLit getch break Reset CAN controller canReset PORTl canRes...

Page 22: ...4 DataMonitor Utility C H A P T E R ...

Page 23: ...en will appear as shown below The main screen consists of A Menu bar Lists the available functions From the main menu you can select Configuration Monitoring and Terminal B Monitor screen Shows monitored data including message index CAN device ID data length and data C Status fields Display the status of the two ports and the stanus register of the CAN controllers D On line help message bar Shows ...

Page 24: ...arameters below need to be configured for each CAN controller Address segment The base address address segment of the PCL j 841 is normally adjusted during the installation process The selection of the address segment needs to be the same as that of the hardware configuration Port Select the port you want to configure Baudrate The baud rate must be coordinated with the CAN network Choose the appro...

Page 25: ...Q already selected for the PCL 841 which accepts values between IRQ3 to IRQ15 except 8 and 13 Running mode During the normal configuration and communica tion process select Normal Mode When the system fails you can hit Enter to reset the CAN controller Hit Enter again to return to Normal Mode to further execute your configura tion Monitor Select the port to be monitored from the Monitor pull down ...

Page 26: ... 1 1 0 0 Receive Buffer Status Data Overrun Status Transmit Buffer Access Transmission Complete Status Receive Status Transmit Status Error Status Bus Status The registers can only be read if the CAN controller is in Normal mode If the CAN controller operates correctly and the transmission has been completed successfully the status register will show as the normal value 00001100 If the Error Statu...

Page 27: ... the object ID and the data bytes as hexadecimal value Press Enter to begin data transmission If the CAN controller is configured correctly and the transmission has been successfully completed every CAN object will be shown in order of appearance at the left side of the screen Testing data transmission To test CAN transmission without actually sending connect Port I to Port 2 on the PCL 841 Select...

Page 28: ...5 Wiring C H A P T E R ...

Page 29: ...llow for impedence matching These resistors can be enabled by utilizing jumpers number 9 and 10 shown below Jumper 9 enables the terminal resistor for port one while jumper number 10 enables the terminal resistor for port two The value of the resistor should equal the characteristic impedance of the signal wires approximately 120 Q The following figure shows resistor placements CAN CAN CAN CAN CAN...

Page 30: ... CAN standard supports half duplex communication This means that just two wires are used to transmit and receive data Wiring connections are as follows PCL 841 DTE male DB 9 Terminal DTE Pin Signal Signal 7 CAN H CAN H 3 GND GND 2 CAN L CAN L ...

Page 31: ...30 PCL 841 Series User s Manual ...

Page 32: ...A Register structure A P P E N D I X ...

Page 33: ... detailed information please refer to the Stand alone C 4N eontmller Data Book from Philips Semiconductors Microcon troller Products You may also find the information on the enclosed disk under the Manual directory in the Word 6 0 file REGISTER DOC CAN controller address allocation Philips PCX82C200 CAN controller ...

Page 34: ...ptance Code Register 4 AC 7 AC 6 AC 5 AC 4 AC 3 AC 2 AC 1 AC 0 6 Acceptance Mask Register 5 AM 7 AM 6 AM 5 AM 4 AM 3 AM 2 AM 1 AM 0 7 Bus Timing Register 1 6 SJW 1 SJW 0 BRP 5 BRP 4 BRP 3 BRP 2 BRP 1 BRP 0 8 Bus Timing Register 0 7 SAM TSEG2 2 TSEG2 1 TSEG2 0 TSEG1 3 TSEG1 2 TSEG1 1 TSEG1 0 9 Output Control Register 8 OCTP1 OCTN1 OCPOL1 OCTP0 OCTN0 OCPOL0 OCMODE1 OCMODE0 10 Test Register note 1 9 ...

Page 35: ...y memory Interrupt Register IR The Interrupt Register allows identification of an interrupt source When one or more of this register s bits are set the INT pin is activat ed All bits are reset by the PCX82C200 after this register is read by the microcontroller This register appears to the microcontoller as a read only memory Acceptance Code Register ACR The Acceptance Code Register is part of the ...

Page 36: ...cation of the sample point and the number of samples to be taken at each sample point This register can be accessed read write if the Reset Request bit is set HIGH present Output Control Register OCR The Output Control Register allows under software control the setup of different driver configurations This register may be accessed read write if the Reset Request bit is set HIGH present Test Regist...

Page 37: ...36 PCL 841 Series User s Manual ...

Reviews: