I try using Masking and reading output data using serial monitor in extended mode..
sorry ,, I edited the code,,but still no data output in serial monitor
Please correct me if there are any mistakes
CAN RX modul Enter setting mode success set rate success!! Enter Normal Mode Success!! Begin to set Mask!! set Mask success!! Begin to set Filter!! set Filter success!! Code: //RECEIVE CODE// #include "mcp_can.h" #include <SPI.h> //#include <stdio.h> #define INT8U unsigned char //boolean firstTime = false; INT8U Flag_Recv = 0; //INT8U len = 0; INT8U ID1 = 0x700; //INT8U ID2 = 0; INT8U buf[8]; //const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin //int buttonState = 0; //char str[20]; void setup() { Serial.begin(115200); Serial.println("CAN RX modul "); CAN.begin(CAN_500KBPS); CAN.init_Mask(0,1, 0); /* init Masks */ CAN.init_Filt(0, 1, 0); /* init filters */ attachInterrupt(0, MCP2515_ISR, FALLING); // digital pin 2 // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); } void MCP2515_ISR() { Flag_Recv = 1; } void loop() { if(Flag_Recv) { Flag_Recv = 0; //CAN.readMsgBuf(&len, buf); ID1=CAN.getCanId(); ID1=CAN.checkReceive(); Serial.print("Ready"); CAN.readMsgBuf(&ID1, buf); if (buf[0]==0){ // turn LED on: digitalWrite(ledPin, HIGH); Serial.print("LED ON "); } else { // turn LED off: digitalWrite(ledPin, LOW); Serial.print("LED OFF "); } } }Code: // SENDING CODE // #include "mcp_can.h" #include <SPI.h> INT8U ID1=0x700; INT8U buf[8]; const int buttonPin = 4; // variables will change: int buttonState = 0; //INT32U ID2=0x7e8; void setup() { Serial.begin(115200); if(CAN.begin(CAN_500KBPS) ==CAN_OK) Serial.print("can init ok!!\r\n"); else Serial.print("Can init fail!!\r\n"); pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); ID1=CAN.getCanId(); if (digitalRead (buttonPin) == LOW) { buf[0] = 0; CAN.sendMsgBuf(ID1,1,8,buf); Serial.println ("Sent 0"); } else { buf[0] = 1; CAN.sendMsgBuf(ID1,1,8,buf); Serial.println ("sent one"); } delay (10); }Statistics : Posted by nw_giri • on Mon Mar 11, 2013 1:03 pm • Replies 16 • Views 3058