Byggern
MCP2515 Class Reference

A singleton class which implements the communication between the AVR and the MCP2515. More...

#include <mcp2515.h>

Inheritance diagram for MCP2515:
CAN

Public Member Functions

 MCP2515 (const MCP2515 &)=delete
 
void SendMessage (CanMessage &message)
 
void SetLoopback ()
 
void SetNormal ()
 
void Initialize (SPI::SPI *spi, uint16_t identifier)
 
- Public Member Functions inherited from CAN
void SetUpperLevel (void(*handler)(CanMessage &data))
 

Static Public Member Functions

static MCP2515GetInstance ()
 

Private Member Functions

void RequestToSend ()
 
void WriteToRegister (uint8_t register_address, uint8_t byte)
 
void ReadFromRegister (uint8_t register_address, uint8_t &byte)
 
void Reset ()
 
void BitModify (uint8_t register_address, uint8_t mask, uint8_t data)
 
void ReadStatus (uint8_t &byte)
 
void LoadTxFrame (CanMessage &message)
 
void RxStatus (uint8_t &byte)
 
void ReadRxFrame (CanMessage &message)
 
 MCP2515 ()
 

Private Attributes

SPI::SPIspi_driver
 
volatile bool clear_to_send = true
 

Friends

void MCP2515_INT ()
 

Additional Inherited Members

- Protected Attributes inherited from CAN
void(* upper_level )(CanMessage &data)
 

Detailed Description

A singleton class which implements the communication between the AVR and the MCP2515.

Throughout the documentation of this class, we will refer to the datasheet of the chip. This can be found at Microchips site

The SPI driver you are using must have meet the following criteria Size of output buffer > 14 bytes Size of input buffer > 11 bytes

Please note: This implementation only uses one recieve and transmit buffer. TX0 and RX0

Constructor & Destructor Documentation

§ MCP2515() [1/2]

MCP2515::MCP2515 ( )
inlineprivate

Initializer not used due to singleton

§ MCP2515() [2/2]

MCP2515::MCP2515 ( const MCP2515 )
delete

Because of singleton - makes sure its not copied etc.

Member Function Documentation

§ BitModify()

void MCP2515::BitModify ( uint8_t  register_address,
uint8_t  mask,
uint8_t  data 
)
private

Modifies the given MCP2515 register with a bitmask. Please see MCP2515 datasheet page 66

Parameters
register_addressThe address to the MCP2515 register
maskDefines which bits to be modified
dataThe byte to be written

§ GetInstance()

static MCP2515& MCP2515::GetInstance ( )
inlinestatic

A Singleton implementation of this class

§ Initialize()

void MCP2515::Initialize ( SPI::SPI spi,
uint16_t  identifier 
)

Initializes the MCP2515 driver.

Parameters
spiThe singleton instance of the SPI driver
identifierThe CAN identifier for this node

§ LoadTxFrame()

void MCP2515::LoadTxFrame ( CanMessage message)
private

Loads the transmit frame, i.e. sends the CAN data to the MCP2515

Parameters
messageThe CAN_MESSAGE to be loaded into the TX frame

§ ReadFromRegister()

void MCP2515::ReadFromRegister ( uint8_t  register_address,
uint8_t &  byte 
)
private

Reads from the given MCP2515 register

Parameters
register_addressThe address to the MCP2515 register
byteThe byte to be written into

§ ReadRxFrame()

void MCP2515::ReadRxFrame ( CanMessage message)
private

Reads the RxFrame, i.e. retrieves the recieved data

Parameters
messageThe message to be written into

§ ReadStatus()

void MCP2515::ReadStatus ( uint8_t &  byte)
private

Gets the status byte from the MCP2515. Please see MCP2515 datasheet page 65, READ STATUS instruction

Parameters
byteThe byte to be written into

§ RequestToSend()

void MCP2515::RequestToSend ( )
private

Sends a RTS (Request to Send) signal to the MCP2515.

§ Reset()

void MCP2515::Reset ( )
private

Sends a reset command to the MCP2515 thorugh the SPI interace (hardware reset not connected). Will put the MCP2515 in config mode.

§ RxStatus()

void MCP2515::RxStatus ( uint8_t &  byte)
private

Gets the RxStatus byte from the MCP2515. Please see MCP2515 datasheet page 66, RX STATUS instruction

Parameters
byteThe byte to be written into

§ SendMessage()

void MCP2515::SendMessage ( CanMessage message)
virtual

Sends a CAN message

Parameters
messageThe CAN message to be sent

Implements CAN.

§ SetLoopback()

void MCP2515::SetLoopback ( )

Initiates the loopback mode of the MCP2515. Please consult the MCP2515 datasheet

§ SetNormal()

void MCP2515::SetNormal ( )

Initiates the normal mode of the MCP2515. Please consult the MCP2515 datasheet

§ WriteToRegister()

void MCP2515::WriteToRegister ( uint8_t  register_address,
uint8_t  byte 
)
private

Writes to the given MCP2515 register

Parameters
register_addressThe address to the MCP2515 register
byteThe byte to be written to the given register

Friends And Related Function Documentation

§ MCP2515_INT

void MCP2515_INT ( )
friend

The MCP2515 interrupt handler

Member Data Documentation

§ clear_to_send

volatile bool MCP2515::clear_to_send = true
private

Flag indicating if we can load the TX frame.

§ spi_driver

SPI::SPI* MCP2515::spi_driver
private

The SPI Driver the MCP2515 uses.


The documentation for this class was generated from the following files: