CANbus reader 1Mbps.spin:
1. Start(rx_pin, tx_pin, sync_pin, bitrate)
Define the CAN-TX and CAN-RX pins, and set the bit rate.
The sync I/O pin lets the two cogs synchronize operations
via an I/O connection. Software can use the pin to
communicate between tasks. If both cogs start successfully,
this object returns the base address of the received data
array. If the cogs do not start, the start method returns the
false condition.
2. ID
Returns the Ident (ID) value, but does not wait for an ID
value to appear in the receiver buffer memory. It returns
the false condition if no ID was stored.
3. DataLength
Returns the number of data bytes in
a CAN frame.
4. ReadData
Returns the contents of the data
buffer, starting with the first byte.
Successive use of this method
returns the following bytes; second,
third, and so on. It does not return
“out-of-date” or old data. If the
current data buffer contains only
one byte, this method returns the
value in byte 0, and false for the
remaining bytes 1 through 7.
5. DataAddress
This method returns the address of
a length-prefaced string that contains the data in the
current receiver buffer.
6. NextID
Returns the Ident (ID) value in the next buffer, but it does
not wait for an ID to appear. It clears the previous ID to
zero. You use this method to advance to the next data
buffer.
7. SetFilters
Set your mask value (if any) and as many as five filter
values.
8. Stop
This method stops the CANbus reader 1Mbps object and
frees the reader and the cogs for other uses.
What’s Next?
A CAN controller has more capabilities than covered
here. It will acknowledge receipt of a frame, identify frame
errors, keep bit-timing clocks synchronized, and identify
any defective CAN controllers on a bus. I’ll discuss those
and other topics in Part 2. NV
Notes
1. Corrigan, Steve, "Controller Area
Network Physical Layer
Requirements," SLLA270. Texas
Instruments, 2008; www.ti.com/lit/
an/slla270/slla270.pdf.
2. Voss, Wilfried, "A Comprehensible
Guide to Controller Area Network,"
Copperhill Media, Greenfield, MA,
2008. ISBN: 978-0976511601;
http://copperhilltech.com/technical-literature.
The Propeller Object Exchange (OBEX) lists several CAN
files with methods that send and receive CAN frames; go
to http://obex.parallax.com/object/745.
For an even simpler CAN test, visit
http://obex.parallax.com/object/845.
For more information about the Propeller IC and the Spin
language, see the Propeller Manual, version. 1.2 available
on the Parallax website www.parallax.com.
December 2016 33