mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-09-15 11:03:48 +00:00
Added sleep support for MCP2515 + MCP2551. This way, you can reduce the power consumption of a complete node down to around 240uA! Changes: - Reintroduced gpio support from commits 43521de/bac66d1 (adlerweb, 15/01/2018) and corrected the errors - Introduced advanced sleep support based on https://github.com/coryjfowler/MCP_CAN_lib/pull/10/files - added example code (receive_sleep and send_sleep) - tested everything
56 lines
1.3 KiB
Arduino
56 lines
1.3 KiB
Arduino
// demo: Use RX0BF and RX1BF as digital outputs
|
|
// adlerweb, 2017-06-24
|
|
#include <SPI.h>
|
|
#include "mcp_can.h"
|
|
|
|
#define SPI_CS_PIN 10
|
|
|
|
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
|
|
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
|
|
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
|
|
{
|
|
Serial.println("CAN init failed, retry");
|
|
delay(100);
|
|
}
|
|
Serial.println("CAN init ok");
|
|
|
|
if(CAN.mcpPinMode(MCP_RX0BF, MCP_PIN_OUT))
|
|
{
|
|
Serial.println("RX0BF is now an output");
|
|
}
|
|
else
|
|
{
|
|
Serial.println("Could not switch RX0BF");
|
|
}
|
|
|
|
if(CAN.mcpPinMode(MCP_RX1BF, MCP_PIN_OUT))
|
|
{
|
|
Serial.println("RX1BF is now an output");
|
|
}
|
|
else
|
|
{
|
|
Serial.println("Could not switch RX1BF");
|
|
}
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
Serial.println("10");
|
|
CAN.mcpDigitalWrite(MCP_RX0BF, HIGH);
|
|
CAN.mcpDigitalWrite(MCP_RX1BF, LOW);
|
|
delay(500);
|
|
Serial.println("01");
|
|
CAN.mcpDigitalWrite(MCP_RX0BF, LOW);
|
|
CAN.mcpDigitalWrite(MCP_RX1BF, HIGH);
|
|
delay(500);
|
|
}
|
|
|
|
/*********************************************************************************************************
|
|
END FILE
|
|
*********************************************************************************************************/
|