Skip to content

Commit 4eb5fdd

Browse files
committed
Reformat and extend comments
1 parent 358aaac commit 4eb5fdd

File tree

4 files changed

+46
-48
lines changed

4 files changed

+46
-48
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
CAN BUS Shield
2-
---------------------------------------------------------
1+
# CAN BUS Shield
2+
---
33
[![CAN BUS Shield](https://statics3.seeedstudio.com/seeed/file/2017-08/bazaar528529_img_2653a.jpg)](https://www.seeedstudio.com/CAN-BUS-Shield-V2-p-2921.html)
44

5-
<br>
6-
75
CAN-BUS is a common industrial bus because of its long travel distance, medium communication speed and high reliability. It is commonly found on modern machine tools and as an automotive diagnostic bus. This CAN-BUS Shield adopts MCP2515 CAN Bus controller with SPI interface and MCP2551 CAN transceiver to give your Arduino/Seeeduino CAN-BUS capability. With an OBD-II converter cable added on and the OBD-II library imported, you are ready to build an onboard diagnostic device or data logger.
86

97
- Implements CAN V2.0B at up to 1 Mb/s

mcp_can.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ byte MCP_CAN::mcp2515_readRegister(const byte address)
192192

193193
/*********************************************************************************************************
194194
** Function name: mcp2515_readRegisterS
195-
** Descriptions: read registerS
195+
** Descriptions: read sucessive registers
196196
*********************************************************************************************************/
197197
void MCP_CAN::mcp2515_readRegisterS(const byte address, byte values[], const byte n)
198198
{
@@ -235,7 +235,7 @@ void MCP_CAN::mcp2515_setRegister(const byte address, const byte value)
235235

236236
/*********************************************************************************************************
237237
** Function name: mcp2515_setRegisterS
238-
** Descriptions: set registerS
238+
** Descriptions: set sucessive registers
239239
*********************************************************************************************************/
240240
void MCP_CAN::mcp2515_setRegisterS(const byte address, const byte values[], const byte n)
241241
{
@@ -259,7 +259,7 @@ void MCP_CAN::mcp2515_setRegisterS(const byte address, const byte values[], cons
259259

260260
/*********************************************************************************************************
261261
** Function name: mcp2515_modifyRegister
262-
** Descriptions: set bit of one register
262+
** Descriptions: Sets specific bits of a register
263263
*********************************************************************************************************/
264264
void MCP_CAN::mcp2515_modifyRegister(const byte address, const byte mask, const byte data)
265265
{
@@ -279,7 +279,7 @@ void MCP_CAN::mcp2515_modifyRegister(const byte address, const byte mask, const
279279

280280
/*********************************************************************************************************
281281
** Function name: mcp2515_readStatus
282-
** Descriptions: read mcp2515's Status
282+
** Descriptions: read mcp2515's status register
283283
*********************************************************************************************************/
284284
byte MCP_CAN::mcp2515_readStatus(void)
285285
{
@@ -551,7 +551,7 @@ byte MCP_CAN::mcp2515_configRate(const byte canSpeed, const byte clock)
551551

552552
/*********************************************************************************************************
553553
** Function name: mcp2515_initCANBuffers
554-
** Descriptions: init canbuffers
554+
** Descriptions: initialize CAN buffers
555555
*********************************************************************************************************/
556556
void MCP_CAN::mcp2515_initCANBuffers(void)
557557
{
@@ -575,7 +575,7 @@ void MCP_CAN::mcp2515_initCANBuffers(void)
575575

576576
/*********************************************************************************************************
577577
** Function name: mcp2515_init
578-
** Descriptions: init the device
578+
** Descriptions: initialize the controller
579579
*********************************************************************************************************/
580580
byte MCP_CAN::mcp2515_init(const byte canSpeed, const byte clock)
581581
{
@@ -694,7 +694,7 @@ void mcp2515_id_to_buf(const byte ext, const unsigned long id, byte *tbufdata)
694694

695695
/*********************************************************************************************************
696696
** Function name: mcp2515_write_id
697-
** Descriptions: write can id
697+
** Descriptions: write CAN ID
698698
*********************************************************************************************************/
699699
void MCP_CAN::mcp2515_write_id(const byte mcp_addr, const byte ext, const unsigned long id)
700700
{
@@ -706,7 +706,7 @@ void MCP_CAN::mcp2515_write_id(const byte mcp_addr, const byte ext, const unsign
706706

707707
/*********************************************************************************************************
708708
** Function name: mcp2515_read_id
709-
** Descriptions: read can id
709+
** Descriptions: read CAN ID
710710
*********************************************************************************************************/
711711
void MCP_CAN::mcp2515_read_id(const byte mcp_addr, byte* ext, unsigned long* id)
712712
{
@@ -731,7 +731,7 @@ void MCP_CAN::mcp2515_read_id(const byte mcp_addr, byte* ext, unsigned long* id)
731731

732732
/*********************************************************************************************************
733733
** Function name: mcp2515_write_canMsg
734-
** Descriptions: write msg
734+
** Descriptions: write message
735735
** Note! There is no check for right address!
736736
*********************************************************************************************************/
737737
void MCP_CAN::mcp2515_write_canMsg(const byte buffer_sidh_addr, unsigned long id, byte ext, byte rtrBit, byte len, volatile const byte *buf)
@@ -816,7 +816,7 @@ void MCP_CAN::mcp2515_start_transmit(const byte mcp_addr) // start
816816

817817
/*********************************************************************************************************
818818
** Function name: mcp2515_isTXBufFree
819-
** Descriptions: Test is tx buffer free for transmitting
819+
** Descriptions: Test if tx buffer is free for transmitting
820820
*********************************************************************************************************/
821821
byte MCP_CAN::mcp2515_isTXBufFree(byte *txbuf_n, byte iBuf) /* get Next free txbuf */
822822
{
@@ -1109,7 +1109,7 @@ byte MCP_CAN::sendMsg(unsigned long id, byte ext, byte rtrBit, byte len, const b
11091109

11101110
/*********************************************************************************************************
11111111
** Function name: sendMsgBuf
1112-
** Descriptions: send buf
1112+
** Descriptions: Send message to transmitt buffer
11131113
*********************************************************************************************************/
11141114
byte MCP_CAN::sendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, const byte *buf, bool wait_sent)
11151115
{
@@ -1118,7 +1118,7 @@ byte MCP_CAN::sendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, cons
11181118

11191119
/*********************************************************************************************************
11201120
** Function name: sendMsgBuf
1121-
** Descriptions: send buf
1121+
** Descriptions: Send message to transmitt buffer
11221122
*********************************************************************************************************/
11231123
byte MCP_CAN::sendMsgBuf(unsigned long id, byte ext, byte len, const byte *buf, bool wait_sent)
11241124
{
@@ -1128,7 +1128,7 @@ byte MCP_CAN::sendMsgBuf(unsigned long id, byte ext, byte len, const byte *buf,
11281128

11291129
/*********************************************************************************************************
11301130
** Function name: readMsgBuf
1131-
** Descriptions: read message buf
1131+
** Descriptions: read message from receive buffer
11321132
*********************************************************************************************************/
11331133
byte MCP_CAN::readMsgBuf(byte *len, byte buf[])
11341134
{
@@ -1137,7 +1137,7 @@ byte MCP_CAN::readMsgBuf(byte *len, byte buf[])
11371137

11381138
/*********************************************************************************************************
11391139
** Function name: readMsgBufID
1140-
** Descriptions: read message buf and can bus source ID
1140+
** Descriptions: read message buffer and CAN bus source ID
11411141
*********************************************************************************************************/
11421142
byte MCP_CAN::readMsgBufID(unsigned long *ID, byte *len, byte buf[])
11431143
{
@@ -1251,7 +1251,7 @@ void MCP_CAN::clearBufferTransmitIfFlags(byte flags)
12511251

12521252
/*********************************************************************************************************
12531253
** Function name: checkReceive
1254-
** Descriptions: check if got something
1254+
** Descriptions: check if a message was arrived
12551255
*********************************************************************************************************/
12561256
byte MCP_CAN::checkReceive(void)
12571257
{
@@ -1262,7 +1262,7 @@ byte MCP_CAN::checkReceive(void)
12621262

12631263
/*********************************************************************************************************
12641264
** Function name: checkError
1265-
** Descriptions: if something error
1265+
** Descriptions: check if an error occurred
12661266
*********************************************************************************************************/
12671267
byte MCP_CAN::checkError(void)
12681268
{
@@ -1272,7 +1272,7 @@ byte MCP_CAN::checkError(void)
12721272

12731273
/*********************************************************************************************************
12741274
** Function name: getCanId
1275-
** Descriptions: when receive something, you can get the can id!!
1275+
** Descriptions: return CAN ID of last message
12761276
*********************************************************************************************************/
12771277
unsigned long MCP_CAN::getCanId(void)
12781278
{
@@ -1281,7 +1281,7 @@ unsigned long MCP_CAN::getCanId(void)
12811281

12821282
/*********************************************************************************************************
12831283
** Function name: isRemoteRequest
1284-
** Descriptions: when receive something, you can check if it was a request
1284+
** Descriptions: check if last message was a remote request
12851285
*********************************************************************************************************/
12861286
byte MCP_CAN::isRemoteRequest(void)
12871287
{
@@ -1290,7 +1290,7 @@ byte MCP_CAN::isRemoteRequest(void)
12901290

12911291
/*********************************************************************************************************
12921292
** Function name: isExtendedFrame
1293-
** Descriptions: did we just receive standard 11bit frame or extended 29bit? 0 = std, 1 = ext
1293+
** Descriptions: check if last message used standard 11bit or extended 29bit address. 0 = std, 1 = ext
12941294
*********************************************************************************************************/
12951295
byte MCP_CAN::isExtendedFrame(void)
12961296
{
@@ -1299,4 +1299,4 @@ byte MCP_CAN::isExtendedFrame(void)
12991299

13001300
/*********************************************************************************************************
13011301
END FILE
1302-
*********************************************************************************************************/
1302+
*********************************************************************************************************/

mcp_can.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class MCP_CAN
5555
{
5656
private:
5757

58-
byte ext_flg; // identifier xxxID
59-
// either extended (the 29 LSB) or standard (the 11 LSB)
60-
unsigned long can_id; // can id
61-
byte rtr; // rtr
62-
byte SPICS;
58+
byte ext_flg; // Identifier Type
59+
// Extended (29 bit) or Standard (11 bit)
60+
unsigned long can_id; // CAN ID
61+
byte rtr; // Remote request flag
62+
byte SPICS; // Chip Select pin number
6363
SPIClass *pSPI;
64-
byte nReservedTx; // Count of tx buffers for reserved send
64+
byte nReservedTx; // Number of tx buffers reserved for send
6565

6666
/*
6767
* mcp2515 driver function
@@ -71,42 +71,42 @@ class MCP_CAN
7171

7272
void mcp2515_reset(void); // reset mcp2515
7373

74-
byte mcp2515_readRegister(const byte address); // read mcp2515's register
74+
byte mcp2515_readRegister(const byte address); // read mcp2515 register
7575

7676
void mcp2515_readRegisterS(const byte address,
7777
byte values[],
7878
const byte n);
79-
void mcp2515_setRegister(const byte address, // set mcp2515's register
79+
void mcp2515_setRegister(const byte address, // set mcp2515 register
8080
const byte value);
8181

82-
void mcp2515_setRegisterS(const byte address, // set mcp2515's registers
82+
void mcp2515_setRegisterS(const byte address, // set successive mcp2515 registers
8383
const byte values[],
8484
const byte n);
8585

8686
void mcp2515_initCANBuffers(void);
8787

88-
void mcp2515_modifyRegister(const byte address, // set bit of one register
88+
void mcp2515_modifyRegister(const byte address, // Set specific bit(s) of a register
8989
const byte mask,
9090
const byte data);
9191

92-
byte mcp2515_readStatus(void); // read mcp2515's Status
92+
byte mcp2515_readStatus(void); // read mcp2515 status
9393
byte mcp2515_setCANCTRL_Mode(const byte newmode); // set mode
9494
byte mcp2515_configRate(const byte canSpeed, const byte clock); // set baudrate
95-
byte mcp2515_init(const byte canSpeed, const byte clock); // mcp2515init
95+
byte mcp2515_init(const byte canSpeed, const byte clock); // Initialize Controller
9696

97-
void mcp2515_write_id( const byte mcp_addr, // write can id
97+
void mcp2515_write_id( const byte mcp_addr, // write CAN ID
9898
const byte ext,
9999
const unsigned long id );
100100

101-
void mcp2515_read_id( const byte mcp_addr, // read can id
101+
void mcp2515_read_id( const byte mcp_addr, // read CAN ID
102102
byte* ext,
103103
unsigned long* id );
104104

105-
void mcp2515_write_canMsg( const byte buffer_sidh_addr, unsigned long id, byte ext, byte rtr, byte len, volatile const byte *buf); // read can msg
106-
void mcp2515_read_canMsg( const byte buffer_load_addr, volatile unsigned long *id, volatile byte *ext, volatile byte *rtr, volatile byte *len, volatile byte *buf); // write can msg
107-
void mcp2515_start_transmit(const byte mcp_addr); // start transmit
108-
byte mcp2515_getNextFreeTXBuf(byte *txbuf_n); // get Next free txbuf
109-
byte mcp2515_isTXBufFree(byte *txbuf_n, byte iBuf); // is buffer by index free
105+
void mcp2515_write_canMsg( const byte buffer_sidh_addr, unsigned long id, byte ext, byte rtr, byte len, volatile const byte *buf); // write CAN msg
106+
void mcp2515_read_canMsg( const byte buffer_load_addr, volatile unsigned long *id, volatile byte *ext, volatile byte *rtr, volatile byte *len, volatile byte *buf); // read CAN msg
107+
void mcp2515_start_transmit(const byte mcp_addr); // start transmission
108+
byte mcp2515_getNextFreeTXBuf(byte *txbuf_n); // Find empty transmit buffer
109+
byte mcp2515_isTXBufFree(byte *txbuf_n, byte iBuf); // Check if specified buffer is free
110110

111111
/*
112112
* can operator function
@@ -129,10 +129,10 @@ class MCP_CAN
129129
byte sendMsgBuf(unsigned long id, byte ext, byte len, const byte *buf, bool wait_sent=true); // send buf
130130
byte readMsgBuf(byte *len, byte *buf); // read buf
131131
byte readMsgBufID(unsigned long *ID, byte *len, byte *buf); // read buf with object ID
132-
byte checkReceive(void); // if something received
133-
byte checkError(void); // if something error
134-
unsigned long getCanId(void); // get can id when receive
135-
byte isRemoteRequest(void); // get RR flag when receive
132+
byte checkReceive(void); // check if a message was received
133+
byte checkError(void); // check if an error occurred
134+
unsigned long getCanId(void); // return CAN ID of last message
135+
byte isRemoteRequest(void); // check if last message was a remote request
136136
byte isExtendedFrame(void); // did we recieve 29bit frame?
137137

138138
byte readMsgBufID(byte status, volatile unsigned long *id, volatile byte *ext, volatile byte *rtr, volatile byte *len, volatile byte *buf); // read buf with object ID

mcp_can_dfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,4 @@
448448
#endif
449449
/*********************************************************************************************************
450450
END FILE
451-
*********************************************************************************************************/
451+
*********************************************************************************************************/

0 commit comments

Comments
 (0)