mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-09-15 02:52:53 +00:00
Update mcp_can.cpp
This commit is contained in:
+30
-10
@@ -57,11 +57,15 @@
|
||||
*********************************************************************************************************/
|
||||
void MCP_CAN::mcp2515_reset(void)
|
||||
{
|
||||
SPI_BEGIN();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_BEGIN();
|
||||
#endif
|
||||
MCP2515_SELECT();
|
||||
spi_readwrite(MCP_RESET);
|
||||
MCP2515_UNSELECT();
|
||||
SPI_END();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_END();
|
||||
#endif
|
||||
delay(10);
|
||||
}
|
||||
|
||||
@@ -73,13 +77,17 @@ INT8U MCP_CAN::mcp2515_readRegister(const INT8U address)
|
||||
{
|
||||
INT8U ret;
|
||||
|
||||
SPI_BEGIN();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_BEGIN();
|
||||
#endif
|
||||
MCP2515_SELECT();
|
||||
spi_readwrite(MCP_READ);
|
||||
spi_readwrite(address);
|
||||
ret = spi_read();
|
||||
MCP2515_UNSELECT();
|
||||
SPI_END();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_END();
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -91,7 +99,9 @@ INT8U MCP_CAN::mcp2515_readRegister(const INT8U address)
|
||||
void MCP_CAN::mcp2515_readRegisterS(const INT8U address, INT8U values[], const INT8U n)
|
||||
{
|
||||
INT8U i;
|
||||
SPI_BEGIN();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_BEGIN();
|
||||
#endif
|
||||
MCP2515_SELECT();
|
||||
spi_readwrite(MCP_READ);
|
||||
spi_readwrite(address);
|
||||
@@ -100,7 +110,9 @@ void MCP_CAN::mcp2515_readRegisterS(const INT8U address, INT8U values[], const I
|
||||
values[i] = spi_read();
|
||||
}
|
||||
MCP2515_UNSELECT();
|
||||
SPI_END();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_END();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
@@ -109,13 +121,17 @@ void MCP_CAN::mcp2515_readRegisterS(const INT8U address, INT8U values[], const I
|
||||
*********************************************************************************************************/
|
||||
void MCP_CAN::mcp2515_setRegister(const INT8U address, const INT8U value)
|
||||
{
|
||||
SPI_BEGIN();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_BEGIN();
|
||||
#endif
|
||||
MCP2515_SELECT();
|
||||
spi_readwrite(MCP_WRITE);
|
||||
spi_readwrite(address);
|
||||
spi_readwrite(value);
|
||||
MCP2515_UNSELECT();
|
||||
SPI_END();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_END();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
@@ -125,7 +141,9 @@ void MCP_CAN::mcp2515_setRegister(const INT8U address, const INT8U value)
|
||||
void MCP_CAN::mcp2515_setRegisterS(const INT8U address, const INT8U values[], const INT8U n)
|
||||
{
|
||||
INT8U i;
|
||||
SPI_BEGIN();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_BEGIN();
|
||||
#endif
|
||||
MCP2515_SELECT();
|
||||
spi_readwrite(MCP_WRITE);
|
||||
spi_readwrite(address);
|
||||
@@ -135,7 +153,9 @@ void MCP_CAN::mcp2515_setRegisterS(const INT8U address, const INT8U values[], co
|
||||
spi_readwrite(values[i]);
|
||||
}
|
||||
MCP2515_UNSELECT();
|
||||
SPI_END();
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI_END();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user