A can bus client, used for communicating with can devices. More...
#include <CAN.h>
Public Member Functions | |
CAN (PinName rd, PinName td) | |
Creates a CAN interface connected to specific pins. More... | |
CAN (PinName rd, PinName td, int hz) | |
Initialize CAN interface and set the frequency. More... | |
int | frequency (int hz) |
Set the frequency of the CAN interface. More... | |
int | write (CANMessage msg) |
Write a CANMessage to the bus. More... | |
int | read (CANMessage &msg, int handle=0) |
Read a CANMessage from the bus. More... | |
void | reset () |
Reset CAN interface. More... | |
void | monitor (bool silent) |
Puts or removes the CAN interface into silent monitoring mode. More... | |
int | mode (Mode mode) |
Change CAN operation to the specified mode. More... | |
int | filter (unsigned int id, unsigned int mask, CANFormat format=CANAny, int handle=0) |
Filter out incoming messages. More... | |
unsigned char | rderror () |
Detects read errors - Used to detect read overflow errors. More... | |
unsigned char | tderror () |
Detects write errors - Used to detect write overflow errors. More... | |
void | attach (Callback< void()> func, IrqType type=RxIrq) |
Attach a function to call whenever a CAN frame received interrupt is generated. More... | |
template<typename T > | |
void | attach (T *obj, void(T::*method)(), IrqType type=RxIrq) |
Attach a member function to call whenever a CAN frame received interrupt is generated. More... | |
template<typename T > | |
void | attach (T *obj, void(*method)(T *), IrqType type=RxIrq) |
Attach a member function to call whenever a CAN frame received interrupt is generated. More... | |
CAN | ( | PinName | rd, |
PinName | td | ||
) |
Creates a CAN interface connected to specific pins.
rd | read from transmitter |
td | transmit to transmitter |
Example:
CAN | ( | PinName | rd, |
PinName | td, | ||
int | hz | ||
) |
Initialize CAN interface and set the frequency.
rd | the read pin |
td | the transmit pin |
hz | the bus frequency in hertz |
void attach | ( | Callback< void()> | func, |
IrqType | type = RxIrq |
||
) |
Attach a function to call whenever a CAN frame received interrupt is generated.
This function locks the deep sleep while a callback is attached
func | A pointer to a void function, or 0 to set as none |
type | Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, CAN::TxIrq for transmitted or aborted, CAN::EwIrq for error warning, CAN::DoIrq for data overrun, CAN::WuIrq for wake-up, CAN::EpIrq for error passive, CAN::AlIrq for arbitration lost, CAN::BeIrq for bus error) |
void attach | ( | T * | obj, |
void(T::*)() | method, | ||
IrqType | type = RxIrq |
||
) |
Attach a member function to call whenever a CAN frame received interrupt is generated.
obj | pointer to the object to call the member function on |
method | pointer to the member function to be called |
type | Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error) |
void attach | ( | T * | obj, |
void(*)(T *) | method, | ||
IrqType | type = RxIrq |
||
) |
Attach a member function to call whenever a CAN frame received interrupt is generated.
obj | pointer to the object to call the member function on |
method | pointer to the member function to be called |
type | Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error) |
int filter | ( | unsigned int | id, |
unsigned int | mask, | ||
CANFormat | format = CANAny , |
||
int | handle = 0 |
||
) |
Filter out incoming messages.
id | the id to filter on |
mask | the mask applied to the id |
format | format to filter on (Default CANAny) |
handle | message filter handle (Optional) |
int frequency | ( | int | hz | ) |
Set the frequency of the CAN interface.
hz | The bus frequency in hertz |
int mode | ( | Mode | mode | ) |
Change CAN operation to the specified mode.
mode | The new operation mode (CAN::Normal, CAN::Silent, CAN::LocalTest, CAN::GlobalTest, CAN::SilentTest) |
void monitor | ( | bool | silent | ) |
Puts or removes the CAN interface into silent monitoring mode.
silent | boolean indicating whether to go into silent mode or not |
unsigned char rderror | ( | ) |
Detects read errors - Used to detect read overflow errors.
int read | ( | CANMessage & | msg, |
int | handle = 0 |
||
) |
Read a CANMessage from the bus.
msg | A CANMessage to read to. |
handle | message filter handle (0 for any message) |
void reset | ( | ) |
Reset CAN interface.
To use after error overflow.
unsigned char tderror | ( | ) |
Detects write errors - Used to detect write overflow errors.
int write | ( | CANMessage | msg | ) |
Write a CANMessage to the bus.
msg | The CANMessage to write. |