- Research Overview
- MPhil Information
- Wireless Comms
- Bat System
- Broadband Phone
- Sentient Vehicles
- Task Assignment
- Computing for the Future of the Planet
- Active Floor
- Open-Source CSK Energy
DTG Local Pages
- Cambridge Weather
- Contact Details
CAN Bus Controllers
The CAN network is specifically designed for use in electrically harsh environments such as vehicles. Key features of this network are:
- Messages are retransmitted if receipt is not acknowledged
- All nodes listen to all traffic, and ignore messages not intended for them, but still monitor for errors.
- Error checking is employed to ensure that a single node cannot block the network
- Nodes do not have an address, they have a pattern match. Therefore several nodes may recieve a message and take action based on the match.
- Collision detection on the network is transparent, with the 'winning' node unaware that a collison occurred (similar to the I2C network)
- At the electrical level, differential signalling using 2 wires and GND is used to minimise problems with electrical noise
- A side effect of the addressing and collision detection mechanism means that some nodes are assigned a higher priority than others in the event of contention on the bus.
In the Sentient Van project we use a microchip part MCP25050. This device interfaces 8 bits of IO with the CAN bus, ideal for remote sensing. The datasheet for the device is here http://ww1.microchip.com/downloads/en/DeviceDoc/21664c.pdf
Devices have two receive filters (RXF0SID, RXF1SID) and a receive mask (RXMSID). Each of these filters is represented as two bytes, with the top three bits of the LSB being the least significant three bits of the 11 bit filter or mask value. These filter IDs are often expressed as a 3 digit hexadecimal string. The first of these digits is in the range [0,7] and is formed from the top three bits of the filter. The second and third of these digits are in the range [0,F] and are formed from the remaining two groups of four bits. For example:
Receive filter RXF0 is used for Information Request Messages (IRMs) and RXF1 is used for Input Messages (IMs). IRMs are used to read values from registers and IMs are used to write values into registers. It is important to make the top 7 bits of RXF0 and RXF1 distinct because the bottom 4 bits of an incoming message are masked out, and it is important to be able to distinguish between incoming IRMs and IMs.
Devices have three transmit IDs (TXID0SID, TXID1SID, TXID2SID). TXID0 is used for scheduled transmissions from the device; TXID2 is used for edge detected and threshold exceeded messages. So, if you would like to be able to distinguish between these messages, keep them distinct.
For the available groups of registers, consult Table 4-2 of the MCP2502X/5X datasheet. The last three bits (labelled '2' .. '0' in the table) indicate which group of registers you wish to refer to. To read from a group with last three bits g on a device with RXF0 set to r, send an IRM to (r & 0xFF0 | 0x008 | g). You can expect to receive the Output Message reply to originate from (r & 0xFF0 | g).
For example, the Configuration Registers have last three bits 010, so g = 0x2. We therefore send our message to (r & 0xFF0 | 0x00A). For example, if r = 0x2AB, send to 0x2AA. And we expect to receive back the output message from the device from ID (r & 0xFF0 | 0x002). In the same example, this will be 0x2A2. Table 4-2 indicates that the response will have a body of length 5 containing the values of the registers listed.
To modify one of the registers, use an IM. There are seven addresses which can be used to write to seven groups of registers. Alternatively, an eighth address can be used to write to an arbitrary register in the device's RAM. To write to address a on a device with RXF1 set to r, send a message to (r & 0xFF8 | 0x000) with a body of length 3 containing the address of the register, a mask indicating which bits of the register you would like to set, and the value to write into those bits. Note that the addresses of the registers are offset by 0x1C from the values in Table 3-1 of the MCP2502X/5X datasheet. For example, if we wish to turn on the A/D converter (indicated by the ADON bit of the ADCON0 register, which is bit 7) in the device with RXF1 set to 0x2B2, send a message to address 0x2B0 with 3-byte body 0x2A 0xFF 0xD0. No response is transmitted.
As an end-to-end example, consider the device with RXF0 = 0x2AB, RXF1 = 0x2B2. We change the ADON bit of the ADCON0 register:
send 0x2A9 recv 0x2A1 7 50 48 F3 29 F1 33 00 send 0x2B0 3 2A 80 D0 recv 0x2A9 recv 0x2A1 7 D0 48 F3 29 F1 33 00
In this example, ADCON0.ADON was initially 0, so even if scheduled transmission of A/D values is enabled (STCON.STEN = 1 and STCON.STMS = 1), no values would be sent. Furthermore, no response to a (r & 0xFF0 | 0x008) request would be received. After ADCON0.ADON is set to 1, scheduled transmissions will start and (r & 0xFF0 | 0x008) requests will be replied to from (r & 0xFF0 | 0x000).
CANKing for Windows
Some brief notes on using CANKing in association with an MCP2510 development kit board:
- Use the Universal page dialogue box to send CAN commands. This dialogue box can be accessed via the menus: Messages->Universal->Universal.
Some brief notes on using the MCP250xx Programmer in association with an MCP2510 development kit board:
- Use a monochrome monitor.
- On the CAN Engine page, if you alter the filters or masks, you should double click the 'Std ID' buttons to refresh the values in the RAW ID column.
- Even if you express an interest in analogue sampling, you must manually turn on the A/D converter using the huge button on the A/D page.
- On the CAN Engine page, the boxed number in the Baud Rate Prescaler box is not updated when you load a device file, although the position of the slider is initialised correctly. Clicking once on the slider will initialise the boxed number.
Use a serial communications program, such as Minicom or HyperTerminal, to communicate with the CAN232 device. Use 57600 baud, 8N1, with no flow control. Echo typed characters locally and append line feeds to incoming line ends.
To test the connection, type V to find out the version of the device. You can expect a response like V1220. Enter N to find out the serial number of the device. You can expect a response like NB394.
Open the CAN channel using O. Then send commands using Tiiildd... where iii is the address and l is the number of dd bytes.
V S4 O t2A90 t2B032A80D0
Commands to give a Lawicel CANUSB on a CAN bus containing a device with RXF0 set to 110 and RXF1 set to 120:
|t1180||Request the contents of the I/O registers|
|t12032A8080||Sets ADON bit of ADCON0 register|
|t12032B0F00||Set the inputs to be A/D rather than GPIO, in ADCON1|
|t12031F7F7F||Set GPDDR to all inputs|
|t12032C8000||Clears STEN bit of STCON register|
|t12032C3000||Sets the scheduled transmission rate to max|