/*
*/
#include <mcp_can.h>
#include <SPI.h>
MCP_CAN CAN0(10); // Set CS to pin 10
#define interrupt_RPM_Pin 7
#define interrupt_AFC_Pin 6
uint16_t pulse_RPM;
uint16_t pulse_AFC;
bool busy_RPM;
bool busy_AFC;
void setup(){
Serial.begin(115200);
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
Serial.println("MCP2515 Initialized Successfully!");
}
else Serial.println("Error Initializing MCP2515...");
CAN0.setMode(MCP_NORMAL);
//pinMode(interrupt_RPM_Pin, INPUT_PULLUP);
//attachInterrupt(digitalPinToInterrupt(interrupt_RPM_Pin), Flow_RPM_Interrupt, CHANGE);
//pinMode(interrupt_AFC_Pin, INPUT_PULLUP);
//attachInterrupt(digitalPinToInterrupt(interrupt_AFC_Pin), FlowInterrupt, CHANGE);
}
byte data[8] = {0x00, 0x00, 0x6c, 0x19, 0x00, 0x00, 0x00, 0x00};
byte data2[8] = {0x00, 0x00, 0x00, 0xA, 0x00, 0x00, 0x00, 0x00};
void loop(){
//Frequency(); // Call frequency measurement function
byte sndStat = CAN0.sendMsgBuf(0x118, 0, 8, data);
if(sndStat == CAN_OK){
Serial.println("Message RPM sent OK");
} else {
Serial.println("Error sending RPM...");
}
sndStat = CAN0.sendMsgBuf(0x198, 0, 8, data2);
if(sndStat == CAN_OK){
Serial.println("Message AFC sent OK");
} else {
Serial.println("Error sending AFC...");
}
delay(10);
}
/*
void Frequency() {
static unsigned long startTime;
if (micros() - startTime < 1000000UL ) return; // Check if 1000 milliseconds interval has passed
startTime = micros();
while (busy) {}; // Wait for interrupt handling to complete
uint8_t sreg = SREG; // Save status register
cli(); // Disable interrupts
count = pulse; // Save pulse count for calculation
pulse = 0; // Reset pulse count
SREG = sreg; // Restore status register
frequency = count / 2.0f; // Calculate frequency
flowRate = frequency * factor; // Calculate flow rate
PlotInfo(); // Display information
}
void Flow_RPM_Interrupt() {
busy_RPM = true; // Set busy flag to indicate interrupt handling
pulse_RPM++; // Increment pulse count
busy_RPM = false; // Clear busy flag after interrupt handling
}
void Flow_AFC_Interrupt() {
busy_AFC = true; // Set busy flag to indicate interrupt handling
pulse_AFC++; // Increment pulse count
busy_AFC = false; // Clear busy flag after interrupt handling
}
*/