Bonjour à tous,
J'utilise un arduino uno, un shield CAN-BUS Seeedstudio v1.0 et un LCD Keypad shield v1.1 Dfrobot.
J'aimerai pouvoir envoyer et reçevoir des messages avec un identifiant en 29 bit (extended mode).
Je pense qu'il faut ajouter cette ligne mais je ne comprends pas la configuration:
CAN.init_Mask(???,1,???);
Avez-vous une idée?
Merci d'avance.
Voici le code:
// include the library code:
#include <LiquidCrystal.h>
#include <mcp_can.h>
#include <SPI.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,4,5,6,7);
unsigned char Flag_Recv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
unsigned long canId = 0x000;
void setup() {
lcd.begin(16, 2);
lcd.print("Mise ss tension");
lcd.setCursor(0, 0); // x, y
delay(900);
Serial.begin(115200);
// init can bus, baudrate: 500k
if(CAN.begin(CAN_500KBPS) ==CAN_OK) {
Serial.print("can init ok\n");
lcd.print("can init ok ");
}
else {
Serial.print("Can init fail\n");
lcd.print("can init fail ");
}
delay(900);
attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
}
void MCP2515_ISR() {
Flag_Recv = 1;
}
void loop() {
lcd.setCursor(0, 0); // x, y (note: line 1 is the second row, since counting begins with 0):
CAN.sendMsgBuf(0x1FFFF, 0, 8, stmp); // send data: id = 0x00, standrad flame, data len = 8, stmp: data buf
delay(100); // send data per 100ms
if(Flag_Recv) // check if get data
{
Flag_Recv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
canId = CAN.getCanId();
Serial.println("CAN_BUS GET DATA!");
Serial.print("data len = ");
Serial.println(len);
Serial.print("CAN ID: ");
Serial.println(canId);
lcd.print("CAN ID: ");
lcd.println(canId);
lcd.setCursor(0, 1); // x, y
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]);
Serial.print("\t");
lcd.print(buf[i]);
}
Serial.println();
}
}