|MicroCAN Project||Parallel Port to MCP2510 Interface
Author: Embedded Micro Software
Last Update: 11/08/08
|Introduction||The MicroCAN Parallel Port Interface Project uses the parallel port on the
PC and the MicroChip MCP2510 Stand-Alone CAN Controller to implement a CAN (Controller
Area Network) interface.
|Hardware||The parallel port interfaces through the DB25 male connector (J1). The
74HC541 (U3) provides a buffer between the PC parallel port and the MCP2510 (U1). Ceramic
resonator Y1 provides the 8mhz clock for the MCP2510.
The PC acts as a master sending commands and/or data to the MCP2510, or receiving data from the MCP2510 using a Serial Peripherial Interface (SPI). The MCP2510 acts only as a slave.
The SPI requires the following 4 signals;
The Chip Select signal is an active low signal and enables the SPI port on the MCP2510 to clock in the data on the Serial In line or clock out data on the Serial Out line. The Serial Clock line clocks the data in or out.
The active low hardware Reset signal cause the MCP2510 to enter a 'known' initialized state. +5 volts for the module is provided by the 7805 voltage regulator. Diode D1 protects for reverse voltage and the surge suppressor D2 protects for over-voltage. Input voltage ranges from 5.6 to 15 volts and is connected to connector J3.
The 82C250 CAN physical layer provides the connection to the CAN+ and CAN- lines. Resistor R3 provides a 120 ohm termination resistance and can be jumpered in or out with jumper X1.
|Software||The software to control the MicroCAN is written using Borland's Delphi
programming language and runs under either Windows 95/98. Delphi is a powerful development
environment for Windows applications. The object Pascal is similiar enough to C allowing
applications to be built quickly and easily. The software is contained in the MicroCAN.dpr
The lowest level functions are required to control the parallel port lines. The 2 functions Outb and Inb are written in assembly langauge and write or read directly to/from the PC ports.
function Outb(Y: Integer; Port: Integer ): Byte;
Outb requires 2 parameters; Port contains the parallel port address and Y contains the value to write to it. Inb only requires the Port parameter (parallel port address) and returns the value read from it. Outb does not return anything.
The parallel port is address as 3 consecutive ports and typical addresses are $378, $3BC, or $278. Before accessing the parallel port, the 3 address variables dport (Data Port), sport (Status Port), and cport (Control Port) must be set. The following function sets these 3 global variables.
function qcSetPortAddress( port: Integer ): integer; stdcall;
The printer port assignment can be found be launching a DOS window and displaying the contents of memory location 0040:0008 using the debug program.
LPT1 is at 0378, LPT2 is at 0278 and LPT3 and LPT4 are not assigned.
After the port address has been assigned, the parallel port signals can be accessed. The following function shows an example of setting the RESET line high. Notice that the port is read first and the RESET value is or'd in to set it high. To set the RESET line low, the and operation with the complement of the RESET value is used.
procedure Tmcform.bResetHIClick(Sender: TObject);
procedure Tmcform.bResetLowClick(Sender: TObject);
The SerialRead function reads a register value from the MCP2510. The register number is passed to the function and the value in the register is returned. The ClockData function is used to send and receive the data.
The SerialWrite function write a register value to the MCP2510. The register number and the register value are passed to the function and the function does not return any values. The ClockData function is used to send and receive the data.
The qcReset function toggles the reset line low and then high as well as sends the reset command via the SPI interface. The clockout feature of the MCP2510 is disabled.
function qcReset: integer; stdcall;
The qcSearchPort function looks for the MicroCAN on one of the following ports; $378, $3bc, or $278. The qcSearchPort button under the Function tab in the MicroCAN Interface application executes this function and returns the results in the listbox. qcSearchPort returns the port address if found or -1 if not.
|This page has been hit times.|