Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <tiny_mcp_can.h>
- #include <tinySPI.h>
- MCP_CAN CAN0(PB3); // Set CS to pin PB3 Pin no 2 on chip
- byte data[8] = {0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8};
- void setup()
- {
- pinMode(PB4, OUTPUT);
- if (CAN0.begin(MCP_ANY, CAN_250KBPS, MCP_16MHZ) == CAN_OK)
- {
- //Sucsess();
- digitalWrite(PB4, HIGH);
- delay(2000);
- digitalWrite(PB4, LOW);
- }
- else{
- Failure();
- Failure();
- }
- CAN0.setMode(MCP_NORMAL);
- }
- void loop()
- {
- //byte sndStat = CAN0.sendMsgBuf(0xF2, 0, 8, data);
- if (CAN0.sendMsgBuf(5000, 1, 8, data) == CAN_OK) {
- //Read();
- digitalWrite(PB4, HIGH);
- delay(100);
- digitalWrite(PB4, LOW);
- } else {
- //Failure();
- delay(100);
- }
- //delay(100); // send data per 100ms
- }
- #include "tiny_mcp_can.h"
- #define spi_readwrite SPI.transfer
- #define spi_read() spi_readwrite(0x00)
- void MCP_CAN::mcp2515_reset(void)
- {
- SPI.begin();//SPISettings(10000000, MSBFIRST, SPI_MODE0));
- MCP2515_SELECT(); // digital Write CS low
- spi_readwrite(MCP_RESET); // SPI.transfer();
- MCP2515_UNSELECT(); // digitalWrite CS High
- SPI.end();//Transaction();
- delayMicroseconds(10); // just a delay
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement