Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normal CAN frames receive via interrupts not working #69

Open
MohamedRizwan03 opened this issue Nov 30, 2023 · 2 comments
Open

Normal CAN frames receive via interrupts not working #69

MohamedRizwan03 opened this issue Nov 30, 2023 · 2 comments

Comments

@MohamedRizwan03
Copy link

Hi,

I was just Teensy 4.1 to send and receive CAN messages in same channel (CAN1) (same as example code (CAN2.0_example_FIFO_with_interrupts.ino)).
Transmit is working fine but reception via interrupt is not happening. Even tried to read CAN frames via read function but still not works.

Below is the code (code is same as example code (CAN2.0_example_FIFO_with_interrupts.ino)). Additonally added mailbox status at the end of loop,
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can0;

void setup(void) {
Serial.begin(115200); delay(400);
//pinMode(6, OUTPUT); digitalWrite(6, LOW); /* optional tranceiver enable pin */
Can0.begin();
Can0.setBaudRate(1000000);
Can0.setMaxMB(16);
Can0.enableFIFO();
Can0.enableFIFOInterrupt();
Can0.onReceive(canSniff);
Can0.mailboxStatus();
}

void canSniff(const CAN_message_t &msg) {
Serial.print("MB "); Serial.print(msg.mb);
Serial.print(" OVERRUN: "); Serial.print(msg.flags.overrun);
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" EXT: "); Serial.print(msg.flags.extended);
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();
}

void loop() {
Can0.events();

static uint32_t timeout = millis();
if ( millis() - timeout > 200 ) {
CAN_message_t msg;
msg.id = random(0x1,0x7FE);
for ( uint8_t i = 0; i < 8; i++ ) msg.buf[i] = i + 1;
Can0.write(msg);

timeout = millis();

}

Can0.mailboxStatus();

}

Mailbox status is below,

16:09:08.144 -> FIFO Enabled --> Interrupt Enabled
16:09:08.144 -> FIFO Filters in use: 8
16:09:08.144 -> Remaining Mailboxes: 8
16:09:08.144 -> MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 1 2 3 4 5 6 7 8)
16:09:08.144 -> MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 1 2 3 4 5 6 7 8)
16:09:08.144 -> MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 1 2 3 4 5 6 7 8)
16:09:08.144 -> MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 1 2 3 4 5 6 7 8)
16:09:08.144 -> MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 1 2 3 4 5 6 7 8)
16:09:08.144 -> MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x5F2)(Payload: 1 2 3 4 5 6 7 8)
16:09:08.144 -> MB14 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x641)(Payload: 1 2 3 4 5 6 7 8)
16:09:08.144 -> MB15 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0xC6)(Payload: 1 2 3 4 5 6 7 8)

Hardware connection looks fine.

I don't know what's wrong here.

@msadie
Copy link

msadie commented Dec 1, 2023

Try moving the Can0.mailboxStatus(); from loop() to inside the "if" block. Since that function prints a bunch to serial, you definitely don't want to call it every single loop().

If mailbox status still shows all those mailboxes as transmitting, something outside the teensy is likely the culprit. Do you have another device on the bus that is ACK'ing the messages the teensy is transmitting?

@tonton81
Copy link
Owner

tonton81 commented Dec 1, 2023

msadie is correct. stuck transmissions means bad transceiver connection, no devices ACKing, or wrong bitrate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants