FIGURE 7. Circuit diagram for a loopback test of a CAN
transmitter and receiver on a Propeller MCU IC. This type of test
does not require a physical CAN bus with drivers and receivers.
Propeller “CANbus Writer 1Mbps.spin” and “CANbus
reader 1Mbps.spin” object files include many CAN-control
methods. To use them, give the object file a name:
writer : “CANbus writer 1Mbps”
FIGURE 6. Three examples of how a mask bit affects the use
reader : “CANbus reader 1Mbps”
of filter bits with a received ID. This diagram includes only the
five least-significant bits (LSBs) of an 11-bit ID value. The bits
not shown here operate the same way.
Then, you identify the methods in the object file this way:
writer.Start (25, 24, 1_000_000)
CANbus software. I found this program too complicated
for novices, so you can use the simpler test, “CAN
Loopback demo JT.spin.” For an even simpler test, see
Now consider key methods that send and receive
“CAN Loopback demo JT2.spin.” You can find both in the
CAN frames. For more details, review the listings for the
OBEX at http://obex.parallax.com/object/845. (Other
reader and writer object files noted above.
MCU suppliers provide similar libraries of CAN software
and code examples, although some get quite complicated.)
CAN Writer Methods
The free Propeller IDE (integrated development
environment) — called the Propeller Tool — lets you open
Located in object file: “CANbus writer 1Mbps.spin:”
the CAN software, download it to a Propeller IC, run it,
and modify it if you wish. The IDE includes the Parallax
1. Start(rx_pin, tx_pin, bitrate)
Serial Terminal (PST) that connects to the QuickStart board
Define the CAN-TX and CAN-RX pins, and set the bit rate.
via a USB virtual port, which is also used to program the
Propeller IC. When you run the CAN Loopback demo
2. Send(ident, bytes, d0, d1, d2, d3, d4, d5, d6, d7)
JT.spin program, the terminal window displays the
Create and send a CAN frame with an ID value and as
information saved by the CAN receiver software (Figure 8).
many as eight bytes of data.
For more information about the Propeller IC and the Spin
language, see the Propeller
Manual, version. 1.2 (available
This method returns a true condition if the transmitter-busy
on the Parallax website at
and error-detect bits are clear.
How Does the Code
Stop CAN operations.
CAN Reader Methods
First, a few words about
the Spin language. When you
These methods provide a place to start when you
FIGURE 8. This image
need to use methods in an
create programs of your own. Keep in mind you must turn
displays three hex digits for
object file (one with a .spin
on and initialize the receiver and transmitter in any CAN
the 11-bit CAN ID,
suffix), you identify the object
based device you program. You cannot have “receive only”
followed by one to eight
data bytes as seen in the
and then use that name as a
or “transmit only” devices on a CAN bus.
Parallax Serial Terminal
prefix to the name of the
As I’ll explain in a future article, the receiver plays an
method you want to use. The
important role in a transmission. Located in object file
32 December 2016