mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-07-27 19:55:59 +00:00
Merge pull request #65 from ntb001/master
Allow for extended CAN IDs in the example programs
This commit is contained in:
+131
@@ -0,0 +1,131 @@
|
||||
## WINDOWS
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
## MAC OS
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
## DROPBOX
|
||||
# Dropbox settings and caches
|
||||
.dropbox
|
||||
.dropbox.attr
|
||||
.dropbox.cache
|
||||
|
||||
## VS CODE
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
## VIM
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-v][a-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
*~
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
|
||||
## EMACS
|
||||
# -*- mode: gitignore; -*-
|
||||
*~
|
||||
\#*\#
|
||||
/.emacs.desktop
|
||||
/.emacs.desktop.lock
|
||||
*.elc
|
||||
auto-save-list
|
||||
tramp
|
||||
.\#*
|
||||
|
||||
# Org-mode
|
||||
.org-id-locations
|
||||
*_archive
|
||||
|
||||
# flymake-mode
|
||||
*_flymake.*
|
||||
|
||||
# eshell files
|
||||
/eshell/history
|
||||
/eshell/lastdir
|
||||
|
||||
# elpa packages
|
||||
/elpa/
|
||||
|
||||
# reftex files
|
||||
*.rel
|
||||
|
||||
# AUCTeX auto folder
|
||||
/auto/
|
||||
|
||||
# cask packages
|
||||
.cask/
|
||||
dist/
|
||||
|
||||
# Flycheck
|
||||
flycheck_*.el
|
||||
|
||||
# server auth directory
|
||||
/server/
|
||||
|
||||
# projectiles files
|
||||
.projectile
|
||||
|
||||
# directory configuration
|
||||
.dir-locals.el
|
||||
+1
-1
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
THE SOFTWARE.
|
||||
|
||||
@@ -31,7 +31,7 @@ or download the zip.
|
||||
|
||||
Simply copy the CAN_BUS_Shield folder to your Arduino library collection. For example,
|
||||
arduino-1.6.12/libraries. Next time you run the Arduino IDE, you'll have a new option
|
||||
in Sketch -> Include Library -> CAN_BUS_Shield. Review the included examples in
|
||||
in Sketch -> Include Library -> CAN_BUS_Shield. Review the included examples in
|
||||
CAN_BUS_Shield/examples.
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ The available baudrates are listed as follows:
|
||||
#define CAN_5KBPS 1
|
||||
#define CAN_10KBPS 2
|
||||
#define CAN_20KBPS 3
|
||||
#define CAN_25KBPS 4
|
||||
#define CAN_25KBPS 4
|
||||
#define CAN_31K25BPS 5
|
||||
#define CAN_33KBPS 6
|
||||
#define CAN_40KBPS 7
|
||||
@@ -145,9 +145,9 @@ When frame is received you may check whether it was remote request and whether i
|
||||
|
||||
<br>
|
||||
|
||||
For more information, please refer to [wiki page](http://www.seeedstudio.com/wiki/CAN-BUS_Shield).
|
||||
For more information, please refer to [wiki page](http://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/).
|
||||
|
||||
|
||||
|
||||
----
|
||||
|
||||
This software is written by loovee ([luweicong@seeed.cc](luweicong@seeed.cc "luweicong@seeed.cc")) for seeed studio<br>
|
||||
@@ -165,4 +165,3 @@ global distributors and partners to push open hardware movement.<br>
|
||||
|
||||
|
||||
[](https://github.com/igrigorik/ga-beacon)
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ void taskCanRecv()
|
||||
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
|
||||
|
||||
Serial.println("\r\n------------------------------------------------------------------");
|
||||
Serial.print("Get Data From id: ");
|
||||
Serial.print("Get Data From id: 0x");
|
||||
Serial.println(CAN.getCanId(), HEX);
|
||||
for(int i = 0; i<len; i++) // print the data
|
||||
{
|
||||
|
||||
@@ -37,11 +37,11 @@ void loop()
|
||||
{
|
||||
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
|
||||
|
||||
unsigned char canId = CAN.getCanId();
|
||||
unsigned long canId = CAN.getCanId();
|
||||
|
||||
Serial.println("-----------------------------");
|
||||
Serial.println("get data from ID: ");
|
||||
Serial.println(canId);
|
||||
Serial.println("get data from ID: 0x");
|
||||
Serial.println(canId, HEX);
|
||||
|
||||
for(int i = 0; i<len; i++) // print the data
|
||||
{
|
||||
|
||||
@@ -36,10 +36,10 @@ void loop()
|
||||
{
|
||||
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
|
||||
|
||||
unsigned int canId = CAN.getCanId();
|
||||
unsigned long canId = CAN.getCanId();
|
||||
|
||||
Serial.println("-----------------------------");
|
||||
Serial.print("Get data from ID: ");
|
||||
Serial.print("Get data from ID: 0x");
|
||||
Serial.println(canId, HEX);
|
||||
|
||||
for(int i = 0; i<len; i++) // print the data
|
||||
|
||||
@@ -27,8 +27,8 @@ unsigned char stmp[8] = {ledHIGH, 1, 2, 3, ledLOW, 5, 6, 7};
|
||||
|
||||
void loop()
|
||||
{ Serial.println("In loop");
|
||||
// send data: id = 0x00, standard frame, data len = 8, stmp: data buf
|
||||
CAN.sendMsgBuf(0x70,0, 8, stmp);
|
||||
// send data: id = 0x70, standard frame, data len = 8, stmp: data buf
|
||||
CAN.sendMsgBuf(0x70, 0, 8, stmp);
|
||||
delay(1000); // send data once per second
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -52,4 +52,4 @@ CAN_CTRLERROR LITERAL1
|
||||
CAN_GETTXBFTIMEOUT LITERAL1
|
||||
CAN_SENDMSGTIMEOUT LITERAL1
|
||||
CAN_FAIL LITERAL1
|
||||
SPI_CS_PIN LITERAL1
|
||||
SPI_CS_PIN LITERAL1
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ sentence=Arduino library to control CAN-BUS Shield.
|
||||
paragraph=Arduino library to control CAN-BUS Shield.
|
||||
category=Device Control
|
||||
url=https://github.com/Seeed-Studio/CAN_BUS_Shield
|
||||
architectures=*
|
||||
architectures=*
|
||||
|
||||
+41
-41
@@ -78,7 +78,7 @@ byte statusToTxBuffer(byte status)
|
||||
case MCP_TX1IF : return 1;
|
||||
case MCP_TX2IF : return 2;
|
||||
}
|
||||
|
||||
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ byte statusToTxSidh(byte status)
|
||||
case MCP_TX1IF : return MCP_TXB1SIDH;
|
||||
case MCP_TX2IF : return MCP_TXB2SIDH;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -737,7 +737,7 @@ void MCP_CAN::mcp2515_read_id(const byte mcp_addr, byte* ext, unsigned long* id)
|
||||
void MCP_CAN::mcp2515_write_canMsg(const byte buffer_sidh_addr, unsigned long id, byte ext, byte rtrBit, byte len, volatile const byte *buf)
|
||||
{
|
||||
byte load_addr=txSidhToTxLoad(buffer_sidh_addr);
|
||||
|
||||
|
||||
byte tbufdata[4];
|
||||
byte dlc = len | ( rtrBit ? MCP_RTR_MASK : 0 ) ;
|
||||
byte i;
|
||||
@@ -752,14 +752,14 @@ void MCP_CAN::mcp2515_write_canMsg(const byte buffer_sidh_addr, unsigned long id
|
||||
for (i = 0; i < 4; i++) spi_write(tbufdata[i]);
|
||||
spi_write(dlc);
|
||||
for (i = 0; i < len && i<CAN_MAX_CHAR_IN_MESSAGE; i++) spi_write(buf[i]);
|
||||
|
||||
|
||||
MCP2515_UNSELECT();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_END();
|
||||
#endif
|
||||
|
||||
|
||||
mcp2515_start_transmit( buffer_sidh_addr );
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
@@ -770,16 +770,14 @@ void MCP_CAN::mcp2515_read_canMsg( const byte buffer_load_addr, volatile unsigne
|
||||
{
|
||||
byte tbufdata[4];
|
||||
byte i;
|
||||
|
||||
|
||||
MCP2515_SELECT();
|
||||
spi_readwrite(buffer_load_addr);
|
||||
// mcp2515 has auto-increment of address-pointer
|
||||
for (i = 0; i < 4; i++) tbufdata[i] = spi_read();
|
||||
|
||||
*rtrBit=(tbufdata[3]&0x08 ? 1 : 0 );
|
||||
|
||||
*id = (tbufdata[MCP_SIDH] << 3) + (tbufdata[MCP_SIDL] >> 5);
|
||||
|
||||
*id = (tbufdata[MCP_SIDH] << 3) + (tbufdata[MCP_SIDL] >> 5);
|
||||
*ext = 0;
|
||||
if ( (tbufdata[MCP_SIDL] & MCP_TXB_EXIDE_M) == MCP_TXB_EXIDE_M )
|
||||
{
|
||||
/* extended id */
|
||||
@@ -788,12 +786,14 @@ void MCP_CAN::mcp2515_read_canMsg( const byte buffer_load_addr, volatile unsigne
|
||||
*id = (*id << 8) + tbufdata[MCP_EID0];
|
||||
*ext = 1;
|
||||
}
|
||||
|
||||
*len=spi_read() & MCP_DLC_MASK;
|
||||
|
||||
byte pMsgSize = spi_read();
|
||||
*len = pMsgSize & MCP_DLC_MASK;
|
||||
*rtrBit = (pMsgSize & MCP_RTR_MASK) ? 1 : 0;
|
||||
for (i = 0; i < *len && i<CAN_MAX_CHAR_IN_MESSAGE; i++) {
|
||||
buf[i] = spi_read();
|
||||
}
|
||||
|
||||
|
||||
MCP2515_UNSELECT();
|
||||
}
|
||||
|
||||
@@ -822,9 +822,9 @@ byte MCP_CAN::mcp2515_isTXBufFree(byte *txbuf_n, byte iBuf) /* get Nex
|
||||
{
|
||||
*txbuf_n = 0x00;
|
||||
|
||||
if ( iBuf>=MCP_N_TXBUFFERS ||
|
||||
if ( iBuf>=MCP_N_TXBUFFERS ||
|
||||
(mcp2515_readStatus() & txStatusPendingFlag(iBuf))!=0 ) return MCP_ALLTXBUSY;
|
||||
|
||||
|
||||
*txbuf_n = txCtrlReg(iBuf) + 1; /* return SIDH-address of Buffer */
|
||||
mcp2515_modifyRegister(MCP_CANINTF, txIfFlag(iBuf), 0);
|
||||
|
||||
@@ -841,7 +841,7 @@ byte MCP_CAN::mcp2515_getNextFreeTXBuf(byte *txbuf_n) // get Nex
|
||||
byte i;
|
||||
|
||||
*txbuf_n = 0x00;
|
||||
|
||||
|
||||
if ( status==MCP_STAT_TX_PENDING_MASK ) return MCP_ALLTXBUSY; // All buffers are pending
|
||||
|
||||
// check all 3 TX-Buffers except reserved
|
||||
@@ -853,7 +853,7 @@ byte MCP_CAN::mcp2515_getNextFreeTXBuf(byte *txbuf_n) // get Nex
|
||||
return MCP2515_OK; // ! function exit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return MCP_ALLTXBUSY;
|
||||
}
|
||||
|
||||
@@ -902,7 +902,7 @@ void MCP_CAN::enableTxInterrupt(bool enable)
|
||||
} else {
|
||||
interruptStatus &= ~MCP_TX_INT;
|
||||
}
|
||||
|
||||
|
||||
mcp2515_setRegister(MCP_CANINTE, interruptStatus);
|
||||
}
|
||||
|
||||
@@ -1034,9 +1034,9 @@ byte MCP_CAN::init_Filt(byte num, byte ext, unsigned long ulData)
|
||||
byte MCP_CAN::sendMsgBuf(byte status, unsigned long id, byte ext, byte rtrBit, byte len, volatile const byte *buf)
|
||||
{
|
||||
byte txbuf_n=statusToTxSidh(status);
|
||||
|
||||
|
||||
if ( txbuf_n==0 ) return CAN_FAILTX; // Invalid status
|
||||
|
||||
|
||||
mcp2515_modifyRegister(MCP_CANINTF, status, 0); // Clear interrupt flag
|
||||
mcp2515_write_canMsg(txbuf_n, id, ext, rtrBit, len, buf);
|
||||
|
||||
@@ -1058,7 +1058,7 @@ byte MCP_CAN::trySendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, c
|
||||
}
|
||||
|
||||
mcp2515_write_canMsg(txbuf_n, id, ext, rtrBit, len, buf);
|
||||
|
||||
|
||||
return CAN_OK;
|
||||
}
|
||||
|
||||
@@ -1074,7 +1074,7 @@ byte MCP_CAN::sendMsg(unsigned long id, byte ext, byte rtrBit, byte len, const b
|
||||
can_id=id;
|
||||
ext_flg=ext;
|
||||
rtr=rtrBit;
|
||||
|
||||
|
||||
do {
|
||||
if (uiTimeOut > 0) delayMicroseconds(10);
|
||||
res = mcp2515_getNextFreeTXBuf(&txbuf_n); // info = addr.
|
||||
@@ -1149,10 +1149,10 @@ byte MCP_CAN::readMsgBufID(unsigned long *ID, byte *len, byte buf[])
|
||||
** Descriptions: Read message buf and can bus source ID according to status.
|
||||
** Status has to be read with readRxTxStatus.
|
||||
*********************************************************************************************************/
|
||||
byte MCP_CAN::readMsgBufID(byte status, volatile unsigned long *id, volatile byte *ext, volatile byte *rtrBit, volatile byte *len, volatile byte *buf)
|
||||
byte MCP_CAN::readMsgBufID(byte status, volatile unsigned long *id, volatile byte *ext, volatile byte *rtrBit, volatile byte *len, volatile byte *buf)
|
||||
{
|
||||
byte rc=CAN_NOMSG;
|
||||
|
||||
|
||||
if ( status & MCP_RX0IF ) // Msg in Buffer 0
|
||||
{
|
||||
mcp2515_read_canMsg( MCP_READ_RX0, id, ext, rtrBit, len, buf);
|
||||
@@ -1172,7 +1172,7 @@ byte MCP_CAN::readMsgBufID(byte status, volatile unsigned long *id, volatile byt
|
||||
} else {
|
||||
*len=0;
|
||||
}
|
||||
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1181,51 +1181,51 @@ byte MCP_CAN::readMsgBufID(byte status, volatile unsigned long *id, volatile byt
|
||||
** Descriptions: Read RX and TX interrupt bits. Function uses status reading, but translates.
|
||||
** result to MCP_CANINTF. With this you can check status e.g. on interrupt sr
|
||||
** with one single call to save SPI calls. Then use checkClearRxStatus and
|
||||
** checkClearTxStatus for testing.
|
||||
** checkClearTxStatus for testing.
|
||||
*********************************************************************************************************/
|
||||
byte MCP_CAN::readRxTxStatus(void)
|
||||
{
|
||||
byte ret=( mcp2515_readStatus() & ( MCP_STAT_TXIF_MASK | MCP_STAT_RXIF_MASK ) );
|
||||
ret=(ret & MCP_STAT_TX0IF ? MCP_TX0IF : 0) |
|
||||
(ret & MCP_STAT_TX1IF ? MCP_TX1IF : 0) |
|
||||
(ret & MCP_STAT_TX2IF ? MCP_TX2IF : 0) |
|
||||
ret=(ret & MCP_STAT_TX0IF ? MCP_TX0IF : 0) |
|
||||
(ret & MCP_STAT_TX1IF ? MCP_TX1IF : 0) |
|
||||
(ret & MCP_STAT_TX2IF ? MCP_TX2IF : 0) |
|
||||
(ret & MCP_STAT_RXIF_MASK); // Rx bits happend to be same on status and MCP_CANINTF
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name: checkClearRxStatus
|
||||
** Descriptions: Return first found rx CANINTF status and clears it from parameter.
|
||||
** Note that this does not affect to chip CANINTF at all. You can use this
|
||||
** Note that this does not affect to chip CANINTF at all. You can use this
|
||||
** with one single readRxTxStatus call.
|
||||
*********************************************************************************************************/
|
||||
byte MCP_CAN::checkClearRxStatus(byte *status)
|
||||
{
|
||||
byte ret;
|
||||
|
||||
|
||||
ret = *status & MCP_RX0IF; *status &= ~MCP_RX0IF;
|
||||
|
||||
|
||||
if ( ret==0 ) { ret = *status & MCP_RX1IF; *status &= ~MCP_RX1IF; }
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name: checkClearTxStatus
|
||||
** Descriptions: Return specified buffer of first found tx CANINTF status and clears it from parameter.
|
||||
** Note that this does not affect to chip CANINTF at all. You can use this
|
||||
** Note that this does not affect to chip CANINTF at all. You can use this
|
||||
** with one single readRxTxStatus call.
|
||||
*********************************************************************************************************/
|
||||
byte MCP_CAN::checkClearTxStatus(byte *status, byte iTxBuf)
|
||||
{
|
||||
byte ret;
|
||||
|
||||
|
||||
if ( iTxBuf<MCP_N_TXBUFFERS ) { // Clear specific buffer flag
|
||||
ret = *status & txIfFlag(iTxBuf); *status &= ~txIfFlag(iTxBuf);
|
||||
} else {
|
||||
ret=0;
|
||||
for (byte i = 0; i < MCP_N_TXBUFFERS-nReservedTx; i++) {
|
||||
ret = *status & txIfFlag(i);
|
||||
ret = *status & txIfFlag(i);
|
||||
if ( ret!=0 ) {
|
||||
*status &= ~txIfFlag(i);
|
||||
return ret;
|
||||
@@ -1233,7 +1233,7 @@ byte MCP_CAN::checkClearTxStatus(byte *status, byte iTxBuf)
|
||||
};
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
@@ -1243,7 +1243,7 @@ byte MCP_CAN::checkClearTxStatus(byte *status, byte iTxBuf)
|
||||
** more data to be sent. Otherwise IRQ will newer change state.
|
||||
*********************************************************************************************************/
|
||||
void MCP_CAN::clearBufferTransmitIfFlags(byte flags)
|
||||
{
|
||||
{
|
||||
flags &= MCP_TX_INT;
|
||||
if ( flags==0 ) return;
|
||||
mcp2515_modifyRegister(MCP_CANINTF, flags, 0);
|
||||
@@ -1299,4 +1299,4 @@ byte MCP_CAN::isExtendedFrame(void)
|
||||
|
||||
/*********************************************************************************************************
|
||||
END FILE
|
||||
*********************************************************************************************************/
|
||||
*********************************************************************************************************/
|
||||
|
||||
+1
-1
@@ -448,4 +448,4 @@
|
||||
#endif
|
||||
/*********************************************************************************************************
|
||||
END FILE
|
||||
*********************************************************************************************************/
|
||||
*********************************************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user