Library functions
Library constructor
To start using Waspmote CAN Bus library, an object from class WaspCAN
must be created. This object, called CAN
, is created inside the CAN Bus library and it is public to all libraries. It is used through this guide to show how the CAN Bus library works. When creating this constructor, all the variables are defined with an initial value by default.
Switching the module on
This function powers the CAN Bus module and configures the SPI bus. The CAN Bus module can be used only in the socket 0. This function is necessary to configure the module, so the CAN Bus module must be plugged before. In this function must be configured the speed communication. There are four possibilities, 125 Kbs, 250 Kbps, 500 Kbps and 1 Mbs. The most frequently used is 500 Kbps. To operate with the CAN Bus module, we must work with all nodes at the same rate.
Example of use:
You can see how to use this function in this example:
Switching the module off
Switches off the Can Bus module and stops sending data frames. This function will disconnect the power supply of the module so all data stored on the stack will be lost.
Example of use:
Receiving data
We can receive CAN messages, filling the predefined message (messageCAN
) with the CAN controller message.
You can see how to use this function in this example:
Sending data
The CAN Bus module supports CAN to exchange data with other devices. This profile allows to create connections to another device using the same profile (CAN connection). Some functions have been developed to handle the communication between two or more devices. We can send CAN messages, sending the message that we have defined.
Example of use:
You can see how to use this function in this example:
Printing data
We can print through the serial port the received message to view the data. This functions is very useful for debugging and code testing.
Example of use:
CAN in Automation
The Can Bus library defines the most important and used PIDs. The CAN Bus module can be used to request information from a vehicle.
Typically, an automotive technician will use PIDs with a proffesional scan tool connected to the vehicle's OBD-II connector. The scan tool sends PIDs to the vehicle's controller area network (CAN). A device on the bus recognizes the PID as one it is responsible for, and reports the value for that PID to the bus. The scan tool reads the response, and displays it. The user could use Waspmote to emulate this kind of scan tools.
Example of use:
Please note that each car manufacturer implements a different CAN Bus configuration, and each car has a different PID list. This information is usually difficult to access for security reasons.
You can see how to use this function in this example:
The user can also request additional PIDs that he can define in the library. On the other hand, the user can request PIDs manually with the use of the function CiARequest().
Example of use:
You can see how to use this function in this example:
Last updated