This commit is contained in:
reeedstudio
2014-09-12 11:08:40 +08:00
2 changed files with 36 additions and 8 deletions
+35 -8
View File
@@ -65,8 +65,7 @@ void MCP_CAN::mcp2515_readRegisterS(const INT8U address, INT8U values[], const I
spi_readwrite(MCP_READ);
spi_readwrite(address);
// mcp2515 has auto-increment of address-pointer
for (i=0; i<n; i++)
{
for (i=0; i<n && i<CAN_MAX_CHAR_IN_MESSAGE; i++) {
values[i] = spi_read();
}
MCP2515_UNSELECT();
@@ -789,12 +788,40 @@ INT8U MCP_CAN::readMsg()
*********************************************************************************************************/
INT8U MCP_CAN::readMsgBuf(INT8U *len, INT8U buf[])
{
readMsg();
*len = m_nDlc;
for(int i = 0; i<m_nDlc; i++)
{
buf[i] = m_nDta[i];
INT8U rc;
rc = readMsg();
if (rc == CAN_OK) {
*len = m_nDlc;
for(int i = 0; i<m_nDlc; i++) {
buf[i] = m_nDta[i];
}
} else {
*len = 0;
}
return rc;
}
/*********************************************************************************************************
** Function name: readMsgBufID
** Descriptions: read message buf and can bus source ID
*********************************************************************************************************/
INT8U MCP_CAN::readMsgBufID(INT32U *ID, INT8U *len, INT8U buf[])
{
INT8U rc;
rc = readMsg();
if (rc == CAN_OK) {
*len = m_nDlc;
*ID = m_nID;
for(int i = 0; i<m_nDlc && i < MAX_CHAR_IN_MESSAGE; i++) {
buf[i] = m_nDta[i];
}
} else {
*len = 0;
}
return rc;
}
/*********************************************************************************************************
@@ -843,4 +870,4 @@ INT32U MCP_CAN::getCanId(void)
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
*********************************************************************************************************/
+1
View File
@@ -101,6 +101,7 @@ public:
INT8U init_Filt(INT8U num, INT8U ext, INT32U ulData); /* init filters */
INT8U sendMsgBuf(INT32U id, INT8U ext, INT8U len, INT8U *buf); /* send buf */
INT8U readMsgBuf(INT8U *len, INT8U *buf); /* read buf */
INT8U readMsgBufID(INT32U *ID, INT8U *len, INT8U *buf); /* read buf with object ID */
INT8U checkReceive(void); /* if something received */
INT8U checkError(void); /* if something error */
INT32U getCanId(void); /* get can id when receive */