Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mcp_can.cpp #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions mcp_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,32 @@ MCP_CAN::MCP_CAN(INT8U _CS)
MCP2515_UNSELECT();
}

/*********************************************************************************************************
** Function name: set the CAN object
** Descriptions: init CAN object only
*********************************************************************************************************/
MCP_CAN::MCP_CAN()
{
}

/*********************************************************************************************************
** Function name: init
** Descriptions: init can cs and set speed
*********************************************************************************************************/
INT8U MCP_CAN::begin(INT8U speedset, INT8U _CS)
{
SPICS = _CS;
pinMode(SPICS, OUTPUT);
MCP2515_UNSELECT();

INT8U res;

SPI.begin();
res = mcp2515_init(speedset);
if (res == MCP2515_OK) return CAN_OK;
else return CAN_FAILINIT;
}

/*********************************************************************************************************
** Function name: init
** Descriptions: init can and set speed
Expand Down Expand Up @@ -721,7 +747,7 @@ INT8U MCP_CAN::sendMsg()
INT8U MCP_CAN::sendMsgBuf(INT32U id, INT8U ext, INT8U len, INT8U *buf)
{
setMsg(id, ext, len, buf);
sendMsg();
return sendMsg();
}

/*********************************************************************************************************
Expand Down Expand Up @@ -813,4 +839,4 @@ INT32U MCP_CAN::getCanId(void)
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
*********************************************************************************************************/
4 changes: 3 additions & 1 deletion mcp_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ class MCP_CAN

public:
MCP_CAN(INT8U _CS);
INT8U begin(INT8U speedset); /* init can */
MCP_CAN();
INT8U begin(INT8U speedset); /* init can */
INT8U begin(INT8U speedset, INT8U _CS); /* init can with speedset and CS*/
INT8U init_Mask(INT8U num, INT8U ext, INT32U ulData); /* init Masks */
INT8U init_Filt(INT8U num, INT8U ext, INT32U ulData); /* init filters */
INT8U sendMsgBuf(INT32U id, INT8U ext, INT8U len, INT8U *buf); /* send buf */
Expand Down