void loop() {
CAN_message_t msg;
if ( Can0.read(msg) ) canSniff(msg);
}
void canSniff(const CAN_message_t &msg) {
Serial.print("MB "); Serial.print(msg.mb);
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" EXT: "); Serial.print(msg.flags.extended);
Serial.print(" REMOTE: "); Serial.print(msg.rtr);
Serial.print(" TS: "); Serial.print(msg.timestamp);
Serial.print(" ID: "); Serial.print(msg.id, HEX);
Serial.print(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print(msg.buf[i], HEX); Serial.print(" ");
} Serial.println();
}
X = Can0.read(0x234) // read a specific CAN ID and address is to a variable. is this possible? I know my nomenclature is going to be wrong but I hope you get what I'm trying to achieve.
if(msg.id = 0x234)
{
for ( sint8_t i = 0; i < msg.len; i++ )
{
b =x*10
a=msg.buf[i]
x = b+a // makes it a single string of bits
}
}
void relayFrame(const CAN_message_t &frame) {
// Take incoming frame and send to other bus
frame.seq = 1;
if(frame.bus == 0 && can1Enabled) {
Can1.write(frame);
} else if(frame.bus == 1 && can0Enabled) {
Can0.write(frame);
}
/home/david/Arduino/ObjectOrientedCAN/CANalyzer.ino/CANalyzer.ino.ino: In function 'void relayFrame(const CAN_message_t&)':
CANalyzer.ino:72:13: error: assignment of member 'CAN_message_t::seq' in read-only object
frame.seq = 1;
^
exit status 1
assignment of member 'CAN_message_t::seq' in read-only object
/home/david/Arduino/ObjectOrientedCAN/CANalyzer.ino/CANalyzer.ino.ino: In function 'void setup()':
CANalyzer.ino:21:28: error: invalid conversion from 'void (*)(CAN_message_t&)' to '_MB_ptr {aka void (*)(const CAN_message_t&)}' [-fpermissive]
Can0.onReceive(relayFrame);
^
In file included from /home/david/Arduino/ObjectOrientedCAN/CANalyzer.ino/CANalyzer.ino.ino:1:0:
/home/david/Arduino/libraries/IFCT-master/IFCT.h:197:10: note: initializing argument 1 of 'void IFCT::onReceive(_MB_ptr)'
void onReceive(_MB_ptr handler); /* global callback function */
^
CANalyzer.ino:27:28: error: invalid conversion from 'void (*)(CAN_message_t&)' to '_MB_ptr {aka void (*)(const CAN_message_t&)}' [-fpermissive]
Can1.onReceive(relayFrame);
^
In file included from /home/david/Arduino/ObjectOrientedCAN/CANalyzer.ino/CANalyzer.ino.ino:1:0:
/home/david/Arduino/libraries/IFCT-master/IFCT.h:197:10: note: initializing argument 1 of 'void IFCT::onReceive(_MB_ptr)'
void onReceive(_MB_ptr handler); /* global callback function */
^
exit status 1
invalid conversion from 'void (*)(CAN_message_t&)' to '_MB_ptr {aka void (*)(const CAN_message_t&)}' [-fpermissive]
yes thats read only
you could copy it to modify it
CAN_message_t copyFrame = frame;
copyFrame.seq = 1;
modify everything in copyFrame.
Does it restore when you properly fix the cables/resistor?
The write function ends at writeTxMailbox() in the source, perhaps you can try to comment out the whole function, and uncomment one line at a time to see where it gets stuck, and report back?
FLEXCANb_MBn_CS(_baseAddress, mb_num) = (FLEXCAN_MB_CS_CODE(FLEXCAN_MB_CODE_TX_ONCE) |
FLEXCAN_MB_CS_LENGTH(msg.len) |
((msg.flags.remote) ? FLEXCAN_MB_CS_RTR : 0UL) |
((msg.flags.extended) ? FLEXCAN_MB_CS_IDE : 0UL) |
((msg.flags.extended) ? FLEXCAN_MB_CS_SRR : 0UL));
tic = micros();
FLEXCANb_MBn_CS(_baseAddress, mb_num) = (FLEXCAN_MB_CS_CODE(FLEXCAN_MB_CODE_TX_ONCE) |
FLEXCAN_MB_CS_LENGTH(msg.len) |
((msg.flags.remote) ? FLEXCAN_MB_CS_RTR : 0UL) |
((msg.flags.extended) ? FLEXCAN_MB_CS_IDE : 0UL) |
((msg.flags.extended) ? FLEXCAN_MB_CS_SRR : 0UL));
Serial2.print(F("time in [us]: "));
Serial2.println(micros()-tic);
time in [us]: 7
timý
Start