Skip to content

Commit 6fdcc1b

Browse files
authored
Merge pull request #57 from adlerweb/readme-pr
Reformat and extend comments
2 parents 43521de + e771551 commit 6fdcc1b

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
{
@@ -562,7 +562,7 @@ byte MCP_CAN::mcp2515_configRate(const byte canSpeed, const byte clock)
562562

563563
/*********************************************************************************************************
564564
** Function name: mcp2515_initCANBuffers
565-
** Descriptions: init canbuffers
565+
** Descriptions: initialize CAN buffers
566566
*********************************************************************************************************/
567567
void MCP_CAN::mcp2515_initCANBuffers(void)
568568
{
@@ -586,7 +586,7 @@ void MCP_CAN::mcp2515_initCANBuffers(void)
586586

587587
/*********************************************************************************************************
588588
** Function name: mcp2515_init
589-
** Descriptions: init the device
589+
** Descriptions: initialize the controller
590590
*********************************************************************************************************/
591591
byte MCP_CAN::mcp2515_init(const byte canSpeed, const byte clock)
592592
{
@@ -705,7 +705,7 @@ void mcp2515_id_to_buf(const byte ext, const unsigned long id, byte *tbufdata)
705705

706706
/*********************************************************************************************************
707707
** Function name: mcp2515_write_id
708-
** Descriptions: write can id
708+
** Descriptions: write CAN ID
709709
*********************************************************************************************************/
710710
void MCP_CAN::mcp2515_write_id(const byte mcp_addr, const byte ext, const unsigned long id)
711711
{
@@ -717,7 +717,7 @@ void MCP_CAN::mcp2515_write_id(const byte mcp_addr, const byte ext, const unsign
717717

718718
/*********************************************************************************************************
719719
** Function name: mcp2515_read_id
720-
** Descriptions: read can id
720+
** Descriptions: read CAN ID
721721
*********************************************************************************************************/
722722
void MCP_CAN::mcp2515_read_id(const byte mcp_addr, byte* ext, unsigned long* id)
723723
{
@@ -742,7 +742,7 @@ void MCP_CAN::mcp2515_read_id(const byte mcp_addr, byte* ext, unsigned long* id)
742742

743743
/*********************************************************************************************************
744744
** Function name: mcp2515_write_canMsg
745-
** Descriptions: write msg
745+
** Descriptions: write message
746746
** Note! There is no check for right address!
747747
*********************************************************************************************************/
748748
void MCP_CAN::mcp2515_write_canMsg(const byte buffer_sidh_addr, unsigned long id, byte ext, byte rtrBit, byte len, volatile const byte *buf)
@@ -827,7 +827,7 @@ void MCP_CAN::mcp2515_start_transmit(const byte mcp_addr) // start
827827

828828
/*********************************************************************************************************
829829
** Function name: mcp2515_isTXBufFree
830-
** Descriptions: Test is tx buffer free for transmitting
830+
** Descriptions: Test if tx buffer is free for transmitting
831831
*********************************************************************************************************/
832832
byte MCP_CAN::mcp2515_isTXBufFree(byte *txbuf_n, byte iBuf) /* get Next free txbuf */
833833
{
@@ -1120,7 +1120,7 @@ byte MCP_CAN::sendMsg(unsigned long id, byte ext, byte rtrBit, byte len, const b
11201120

11211121
/*********************************************************************************************************
11221122
** Function name: sendMsgBuf
1123-
** Descriptions: send buf
1123+
** Descriptions: Send message to transmitt buffer
11241124
*********************************************************************************************************/
11251125
byte MCP_CAN::sendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, const byte *buf, bool wait_sent)
11261126
{
@@ -1129,7 +1129,7 @@ byte MCP_CAN::sendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, cons
11291129

11301130
/*********************************************************************************************************
11311131
** Function name: sendMsgBuf
1132-
** Descriptions: send buf
1132+
** Descriptions: Send message to transmitt buffer
11331133
*********************************************************************************************************/
11341134
byte MCP_CAN::sendMsgBuf(unsigned long id, byte ext, byte len, const byte *buf, bool wait_sent)
11351135
{
@@ -1139,7 +1139,7 @@ byte MCP_CAN::sendMsgBuf(unsigned long id, byte ext, byte len, const byte *buf,
11391139

11401140
/*********************************************************************************************************
11411141
** Function name: readMsgBuf
1142-
** Descriptions: read message buf
1142+
** Descriptions: read message from receive buffer
11431143
*********************************************************************************************************/
11441144
byte MCP_CAN::readMsgBuf(byte *len, byte buf[])
11451145
{
@@ -1148,7 +1148,7 @@ byte MCP_CAN::readMsgBuf(byte *len, byte buf[])
11481148

11491149
/*********************************************************************************************************
11501150
** Function name: readMsgBufID
1151-
** Descriptions: read message buf and can bus source ID
1151+
** Descriptions: read message buffer and CAN bus source ID
11521152
*********************************************************************************************************/
11531153
byte MCP_CAN::readMsgBufID(unsigned long *ID, byte *len, byte buf[])
11541154
{
@@ -1262,7 +1262,7 @@ void MCP_CAN::clearBufferTransmitIfFlags(byte flags)
12621262

12631263
/*********************************************************************************************************
12641264
** Function name: checkReceive
1265-
** Descriptions: check if got something
1265+
** Descriptions: check if a message was arrived
12661266
*********************************************************************************************************/
12671267
byte MCP_CAN::checkReceive(void)
12681268
{
@@ -1273,7 +1273,7 @@ byte MCP_CAN::checkReceive(void)
12731273

12741274
/*********************************************************************************************************
12751275
** Function name: checkError
1276-
** Descriptions: if something error
1276+
** Descriptions: check if an error occurred
12771277
*********************************************************************************************************/
12781278
byte MCP_CAN::checkError(void)
12791279
{
@@ -1283,7 +1283,7 @@ byte MCP_CAN::checkError(void)
12831283

12841284
/*********************************************************************************************************
12851285
** Function name: getCanId
1286-
** Descriptions: when receive something, you can get the can id!!
1286+
** Descriptions: return CAN ID of last message
12871287
*********************************************************************************************************/
12881288
unsigned long MCP_CAN::getCanId(void)
12891289
{
@@ -1292,7 +1292,7 @@ unsigned long MCP_CAN::getCanId(void)
12921292

12931293
/*********************************************************************************************************
12941294
** Function name: isRemoteRequest
1295-
** Descriptions: when receive something, you can check if it was a request
1295+
** Descriptions: check if last message was a remote request
12961296
*********************************************************************************************************/
12971297
byte MCP_CAN::isRemoteRequest(void)
12981298
{
@@ -1301,7 +1301,7 @@ byte MCP_CAN::isRemoteRequest(void)
13011301

13021302
/*********************************************************************************************************
13031303
** Function name: isExtendedFrame
1304-
** Descriptions: did we just receive standard 11bit frame or extended 29bit? 0 = std, 1 = ext
1304+
** Descriptions: check if last message used standard 11bit or extended 29bit address. 0 = std, 1 = ext
13051305
*********************************************************************************************************/
13061306
byte MCP_CAN::isExtendedFrame(void)
13071307
{
@@ -1577,4 +1577,4 @@ byte MCP_CAN::digitalRead(const byte pin) {
15771577

15781578
/*********************************************************************************************************
15791579
END FILE
1580-
*********************************************************************************************************/
1580+
*********************************************************************************************************/

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
byte mcpMode; // Current controller mode
6666

6767
/*
@@ -72,43 +72,43 @@ class MCP_CAN
7272

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

75-
byte mcp2515_readRegister(const byte address); // read mcp2515's register
75+
byte mcp2515_readRegister(const byte address); // read mcp2515 register
7676

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

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

8787
void mcp2515_initCANBuffers(void);
8888

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

93-
byte mcp2515_readStatus(void); // read mcp2515's Status
93+
byte mcp2515_readStatus(void); // read mcp2515 status
9494
byte mcp2515_setMode(const byte newmode); // Sets and stores controller mode
9595
byte mcp2515_setCANCTRL_Mode(const byte newmode); // set mode
9696
byte mcp2515_configRate(const byte canSpeed, const byte clock); // set baudrate
97-
byte mcp2515_init(const byte canSpeed, const byte clock); // mcp2515init
97+
byte mcp2515_init(const byte canSpeed, const byte clock); // Initialize Controller
9898

99-
void mcp2515_write_id( const byte mcp_addr, // write can id
99+
void mcp2515_write_id( const byte mcp_addr, // write CAN ID
100100
const byte ext,
101101
const unsigned long id );
102102

103-
void mcp2515_read_id( const byte mcp_addr, // read can id
103+
void mcp2515_read_id( const byte mcp_addr, // read CAN ID
104104
byte* ext,
105105
unsigned long* id );
106106

107-
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
108-
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
109-
void mcp2515_start_transmit(const byte mcp_addr); // start transmit
110-
byte mcp2515_getNextFreeTXBuf(byte *txbuf_n); // get Next free txbuf
111-
byte mcp2515_isTXBufFree(byte *txbuf_n, byte iBuf); // is buffer by index free
107+
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
108+
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
109+
void mcp2515_start_transmit(const byte mcp_addr); // start transmission
110+
byte mcp2515_getNextFreeTXBuf(byte *txbuf_n); // Find empty transmit buffer
111+
byte mcp2515_isTXBufFree(byte *txbuf_n, byte iBuf); // Check if specified buffer is free
112112

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

140140
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
@@ -478,4 +478,4 @@
478478
#endif
479479
/*********************************************************************************************************
480480
END FILE
481-
*********************************************************************************************************/
481+
*********************************************************************************************************/

0 commit comments

Comments
 (0)