eeprom adding

Fork of SEEED_CAN by Sophie Dexter

Embed: (wiki syntax)

« Back to documentation index

SEEED_CAN Class Reference

SEEED_CAN Class Reference

A can bus client, used for communicating with Seeed Studios' CAN-BUS Arduino Shield. More...

#include <seeed_can.h>

Public Member Functions

 SEEED_CAN (PinName ncs=SEEED_CAN_CS, PinName irq=SEEED_CAN_IRQ, PinName mosi=SEEED_CAN_MOSI, PinName miso=SEEED_CAN_MISO, PinName clk=SEEED_CAN_CLK, int spiBitrate=1000000)
 Seeed Studios CAN-BUS Shield Constructor - Create a SEEED_CAN interface connected to the specified pins.
int open (int canBitrate=100000, Mode mode=Normal)
 Open initialises the Seeed Studios CAN-BUS Shield.
void monitor (bool silent)
 Puts or removes the Seeed Studios CAN-BUS shield into or from silent monitoring mode.
int mode (Mode mode)
 Change the Seeed Studios CAN-BUS shield CAN operation mode.
int frequency (int canBitRate)
 Set the CAN bus frequency (Bit Rate)
int read (SEEED_CANMessage &msg)
 Read a CAN bus message from the MCP2515 (if one has been received)
int write (SEEED_CANMessage msg)
 Write a CAN bus message to the MCP2515 (if there is a free message buffer)
int mask (int maskNum, int canId, CANFormat format=CANStandard)
 Configure one of the Accpetance Masks (0 or 1)
int filter (int filterNum, int canId, CANFormat format=CANStandard)
 Configure one of the Acceptance Filters (0 through 5)
unsigned char rderror (void)
 Returns number of message reception (read) errors to detect read overflow errors.
unsigned char tderror (void)
 Returns number of message transmission (write) errors to detect write overflow errors.
int errors (ErrorType type=AnyError)
 Check if any type of error has been detected on the CAN bus.
unsigned char errorFlags (void)
 Returns the contents of the MCP2515's Error Flag register.
void attach (void(*fptr)(void), IrqType event=RxAny)
 Attach a function to call whenever a CAN frame received interrupt is generated.
template<typename T >
void attach (T *tptr, void(T::*mptr)(void), IrqType event=RxAny)
 Attach a member function to call whenever a CAN frame received interrupt is generated.
int interrupts (IrqType type)
 Check if the specified interrupt event has occurred.
unsigned char interruptFlags (void)
 Returns the contents of the MCP2515's Interrupt Flag register.

Detailed Description

A can bus client, used for communicating with Seeed Studios' CAN-BUS Arduino Shield.

Definition at line 64 of file seeed_can.h.


Constructor & Destructor Documentation

SEEED_CAN ( PinName  ncs = SEEED_CAN_CS,
PinName  irq = SEEED_CAN_IRQ,
PinName  mosi = SEEED_CAN_MOSI,
PinName  miso = SEEED_CAN_MISO,
PinName  clk = SEEED_CAN_CLK,
int  spiBitrate = 1000000 
)

Seeed Studios CAN-BUS Shield Constructor - Create a SEEED_CAN interface connected to the specified pins.

The Seeed Studio CAN-BUS shield is an Arduino compatible shield and connects to the FRDM-KL25Z SPI0 interface using pins PTD2 (mosi) PTD3 (miso) PTD1 (clk). The Active low chip select normally connects to the FRDM-KL25Z's PTD0 pin, but there is an option on the Seeed Studio CAN-BUS shield to connect to the PTD5 pin. The CAN-BUS shield uses the FRDM-KL25Z's PTD4 pin for its (active low) interrupt capability. The defaults allow you to plug the Seeed Studios' CAN-BUS Shield into a FRDM-KL25Z mbed and it to work without specifying any parameters.

Parameters:
ncsActive low chip select, default: SEEED_CAN_CS is FRDM-KL25Z PTD0 pin (p9 on LPC1768).
If you change the link on the Seeed Studios CAN-BUS shield you should use a value of SEEED_CAN_IO9 or PTD5 instead.
irqActive low interrupt pin, default: SEEED_CAN_IRQ is FRDM-KL25Z PTD4 pin (p10 on LPC1768).
mosiSPI Master Out, Slave In pin, default: SEEED_CAN_MOSI is FRDM-KL25Z PTD2 pin (p11 on LPC1768).
misoSPI Master In, Slave Out pin, default: :p SEEED_CAN_MISO is FRDM-KL25Z PTD3 pin (p12 on LPC1768).
clkSPI Clock pin, default: SEEED_CAN_MISO is FRDM-KL25Z PTD1 pin (p13 on LPC1768).
spiBitrateSPI Clock frequency, default: 1000000 (1 MHz).

Definition at line 21 of file seeed_can.cpp.


Member Function Documentation

void attach ( void(*)(void)  fptr,
IrqType  event = RxAny 
)

Attach a function to call whenever a CAN frame received interrupt is generated.

Parameters:
fptrA pointer to a void function, or 0 to set as none.
eventWhich CAN interrupt to attach the member function to, default: RxAny
SEEED_CAN::None - Disable all interrupt sources,
SEEED_CAN::AnyIrq - Enable all interrupt sources,
SEEED_CAN::RxAny - Any full RX buffer can generate an interrupt,
SEEED_CAN::TxAny - Any empty TX buffer can generate an interrupt,
SEEED_CAN::Rx0Full - Receive buffer 1 full,
SEEED_CAN::Rx1Full - Receive buffer 1 full,
SEEED_CAN::Tx0Free - Transmit buffer 2 empty,
SEEED_CAN::Tx1Free - Transmit buffer 2 empty,
SEEED_CAN::Tx2Free - Transmit buffer 2 empty,
SEEED_CAN::Error - Error (multiple sources in EFLG register),
SEEED_CAN::Wake - Wakeup,
SEEED_CAN::MsgError - Message Error,

Definition at line 122 of file seeed_can.cpp.

void attach ( T *  tptr,
void(T::*)(void)  mptr,
IrqType  event = RxAny 
)

Attach a member function to call whenever a CAN frame received interrupt is generated.

Parameters:
tptrpointer to the object to call the member function on.
mptrpointer to the member function to be called.
eventWhich CAN interrupt to attach the member function to, default: RxAny
SEEED_CAN::None - Disable all interrupt sources,
SEEED_CAN::AnyIrq - Enable all interrupt sources,
SEEED_CAN::RxAny - Any full RX buffer can generate an interrupt,
SEEED_CAN::TxAny - Any empty TX buffer can generate an interrupt,
SEEED_CAN::Rx0Full - Receive buffer 1 full,
SEEED_CAN::Rx1Full - Receive buffer 1 full,
SEEED_CAN::Tx0Free - Transmit buffer 2 empty,
SEEED_CAN::Tx1Free - Transmit buffer 2 empty,
SEEED_CAN::Tx2Free - Transmit buffer 2 empty,
SEEED_CAN::Error - Error (multiple sources in EFLG register),
SEEED_CAN::Wake - Wakeup,
SEEED_CAN::MsgError - Message Error,

Definition at line 305 of file seeed_can.h.

unsigned char errorFlags ( void   )

Returns the contents of the MCP2515's Error Flag register.

Returns:
Bit_7 - RX1OVR: Receive Buffer 1 Overflow Flag bit - Set when a valid message is received for RXB1 and CANINTF.RX1IF = 1 - Must be reset by MCU,
Bit_6 - RX0OVR: Receive Buffer 1 Overflow Flag bit - Set when a valid message is received for RXB0 and CANINTF.RX0IF = 1 - Must be reset by MCU,
Bit_5 - TXBO: Bus-Off Error Flag bit - Bit set when TEC reaches 255 - Reset after a successful bus recovery sequence,
Bit_4 - TXEP: Transmit Error-Passive Flag bit - Set when TEC is >= 128 - Reset when TEC is less than 128,
Bit_3 - RXEP: Receive Error-Passive Flag bit - Set when REC is >= 128 - Reset when REC is less than 128,
Bit_2 - TXWAR: Transmit Error Warning Flag bit - Set when TEC is >= 96 - Reset when TEC is less than 96,
Bit_1 - RXWAR: Receive Error Warning Flag bit - Set when REC is >= 96 - Reset when REC is less than 96,
Bit_0 - EWARN: Error Warning Flag bit - Set when TEC or REC is >= 96 (TXWAR or RXWAR = 1) - Reset when both REC and TEC are < 96.

Definition at line 115 of file seeed_can.cpp.

int errors ( ErrorType  type = AnyError )

Check if any type of error has been detected on the CAN bus.

Parameters:
errorSpecify which type of error to report on, default: AnyError.
SEEED_CAN::AnyError - Any one or more of the following errors and warnings:
SEEED_CAN::Errors - Any one or more of the 5 errors:
SEEED_CAN::Rx1Ovr - Receive Buffer 1 Overflow Flag bit,
SEEED_CAN::Rx0Ovr - Receive Buffer 0 Overflow Flag bit,
SEEED_CAN::TxBOff - Bus-Off Error Flag bit,
SEEED_CAN::TxPasv - Transmit Error-Passive Flag bit,
SEEED_CAN::RxPasv - Receive Error-Passive Flag bit,
SEEED_CAN::Warnings - Any one or more of the 3 warnings:
SEEED_CAN::TxWarn - Transmit Error Warning Flag bit,
SEEED_CAN::RxWarn - Receive Error Warning Flag bit,
SEEED_CAN::EWarn - Error Warning Flag bit.
Returns:
1 if specified type of error has been detected
0 if no errors

Definition at line 108 of file seeed_can.cpp.

int filter ( int  filterNum,
int  canId,
CANFormat  format = CANStandard 
)

Configure one of the Acceptance Filters (0 through 5)

Parameters:
filterNumThe number of the Acceptance Filter to configure (Acceptance Filters 0 and 1 are associated with Mask 0, Acceptance Filters 2 through 5 are associated with Mask 1).
canIdCAN Id Filter bits (Acceptance Filters are only compared against bits that are set to '1' in an Acceptance Mask (e.g. mask 0x07F0 and filter 0x03F0 would allow through messages with CAN Id's 0x03F0 through 0x03FF because the 4 LSBs of the CAN Id are not filtered).
formatDescribes if the Acceptance Filter is for a standard (CANStandard) or extended (CANExtended) CAN message frame format, default: CANStandard.
Returns:
1 if Acceptance Filter was set
0 if the Acceptance Filter could not be set

Definition at line 87 of file seeed_can.cpp.

int frequency ( int  canBitRate )

Set the CAN bus frequency (Bit Rate)

Parameters:
hzThe bus frequency in Hertz
Returns:
1 if successful,
0 otherwise

Definition at line 58 of file seeed_can.cpp.

unsigned char interruptFlags ( void   )

Returns the contents of the MCP2515's Interrupt Flag register.

Returns:
Bit_7 - MERRF: Message Error Interrupt Flag,
Bit_6 - WAKIF: Wake-up Interrupt Flag,
Bit_5 - ERRIF: Error Interrupt Flag (multiple sources in EFLG register, see errorFlags)
Bit_4 - TX2IF: Transmit Buffer 2 Empty Interrupt Flag
Bit_3 - TX1IF: Transmit Buffer 1 Empty Interrupt Flag
Bit_2 - TX0IF: Transmit Buffer 0 Empty Interrupt Flag
Bit_1 - RX1IF: Receive Buffer 1 Full Interrupt Flag
Bit_0 - RX0IF: Receive Buffer 0 Full Interrupt Flag
Bits are set (1) when interrupt pending, clear (0) when no interrupt pending.
Bits must be cleared by MCU to reset interrupt condition.

Definition at line 150 of file seeed_can.cpp.

int interrupts ( IrqType  type )

Check if the specified interrupt event has occurred.

Parameters:
eventWhich CAN interrupt to attach the member function to
SEEED_CAN::RxAny - At least 1 RX buffer is full,
SEEED_CAN::TxAny - At least 1 TX buffer is empty,
SEEED_CAN::Rx0Full - Receive buffer 1 full,
SEEED_CAN::Rx1Full - Receive buffer 1 full,
SEEED_CAN::Tx0Free - Transmit buffer 2 empty,
SEEED_CAN::Tx1Free - Transmit buffer 2 empty,
SEEED_CAN::Tx2Free - Transmit buffer 2 empty,
SEEED_CAN::Error - Error (multiple sources in EFLG register),
SEEED_CAN::Wake - Wakeup,
SEEED_CAN::MsgError - Message Error,
Returns:
1 if specified interrupt event has occurred
0 if no errors

Definition at line 143 of file seeed_can.cpp.

int mask ( int  maskNum,
int  canId,
CANFormat  format = CANStandard 
)

Configure one of the Accpetance Masks (0 or 1)

Parameters:
maskNumThe number of the Acceptance Mask to configure (Acceptance Mask 0 is associated with Filters 0 and 1, Acceptance Mask 1 is associated with Filters 2 through 5).
canIdCAN Id Mask bits (Acceptance Filters are only compared against bits that are set to '1' in an Acceptance Mask (e.g. mask 0x07F0 and filter 0x03F0 would allow through messages with CAN Id's 0x03F0 through 0x03FF because the 4 LSBs of the CAN Id are not filtered).
formatDescribes if the Acceptance Mask is for a standard (CANStandard) or extended (CANExtended) CAN message frame format, default: CANStandard.
Returns:
1 if Acceptance Mask was set
0 if the Acceptance Mask could not be set

Definition at line 80 of file seeed_can.cpp.

int mode ( Mode  mode )

Change the Seeed Studios CAN-BUS shield CAN operation mode.

Parameters:
modeThe new operation mode
SEEED_CAN::Normal - Normal mode is the standard operating mode,
SEEED_CAN::Monitor - This mode can be used for bus monitor applications.
SEEED_CAN::Sleep - This mode can be used to minimize the current consumption,
SEEED_CAN::Loopback - This mode can be used in system development and testing.
SEEED_CAN::Reset - Reset the MCP2515 device and stay in Configuration mode.
Returns:
1 if mode change was successful
0 if mode change failed or unsupported,

Definition at line 51 of file seeed_can.cpp.

void monitor ( bool  silent )

Puts or removes the Seeed Studios CAN-BUS shield into or from silent monitoring mode.

Parameters:
silentboolean indicating whether to go into silent mode or not.

Definition at line 44 of file seeed_can.cpp.

int open ( int  canBitrate = 100000,
Mode  mode = Normal 
)

Open initialises the Seeed Studios CAN-BUS Shield.

Parameters:
canBitrateCAN Bus Clock frequency, default: 100000 (100 kHz).
modeThe initial operation mode, default: Normal.
SEEED_CAN::Normal - Normal mode is the standard operating mode,
SEEED_CAN::Monitor - This mode can be used for bus monitor applications.
SEEED_CAN::Sleep - This mode can be used to minimize the current consumption,
SEEED_CAN::Loopback - This mode can be used in system development and testing.
SEEED_CAN::Config - Open with this mode to prevent unwanted messages being received while you configure Filters.
Returns:
1 if successful,
0 otherwise

Definition at line 37 of file seeed_can.cpp.

unsigned char rderror ( void   )

Returns number of message reception (read) errors to detect read overflow errors.

Returns:
Number of reception errors

Definition at line 94 of file seeed_can.cpp.

int read ( SEEED_CANMessage msg )

Read a CAN bus message from the MCP2515 (if one has been received)

Parameters:
msgA CANMessage to read to.
Returns:
1 if any messages have arrived
0 if no message arrived,

Definition at line 66 of file seeed_can.cpp.

unsigned char tderror ( void   )

Returns number of message transmission (write) errors to detect write overflow errors.

Returns:
Number of transmission errors

Definition at line 101 of file seeed_can.cpp.

int write ( SEEED_CANMessage  msg )

Write a CAN bus message to the MCP2515 (if there is a free message buffer)

Parameters:
msgThe CANMessage to write.
Returns:
1 if write was successful
0 if write failed,

Definition at line 73 of file seeed_can.cpp.