tonton81/FlexCAN_T4

Can.write(msg) repeats sending same frame forever

Knio opened this issue · 4 comments

Knio commented

Hi, when writing a CAN message, everything is working, but the message gets re-sent in a loop forever, eventually filling up all the queues and blocking the whole bus. Is there some automatic re-sending code if a message is not ACKed? how can I clear the transmitter?

I'm using 2x Teensy 4.0 with a SN65HVD230 transceiver (one sending and one receiving, no other nodes, on a bench) and have confirmed everything is working with a probe.
I modified the example code slightly to send a unique byte counter for every byte and repeat the mailbox status to be able to debug better.

Receiver log: (same code but with the write commented out)

FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_INACTIVE
                MB9 code: TX_INACTIVE
                MB10 code: TX_INACTIVE
                MB11 code: TX_INACTIVE
                MB12 code: TX_INACTIVE
                MB13 code: TX_INACTIVE
                MB14 code: TX_INACTIVE
                MB15 code: TX_INACTIVE
MB 99  OVERRUN: 0  LEN: 8 EXT: 0 TS: 5249 ID: 76D Buffer: 0 1 2 3 4 5 6 7
MB 99  OVERRUN: 0  LEN: 8 EXT: 0 TS: 5383 ID: 76D Buffer: 0 1 2 3 4 5 6 7
MB 99  OVERRUN: 0  LEN: 8 EXT: 0 TS: 5517 ID: 76D Buffer: 0 1 2 3 4 5 6 7
MB 99  OVERRUN: 0  LEN: 8 EXT: 0 TS: 5651 ID: 76D Buffer: 0 1 2 3 4 5 6 7
MB 99  OVERRUN: 0  LEN: 8 EXT: 0 TS: 5785 ID: 76D Buffer: 0 1 2 3 4 5 6 7
MB 99  OVERRUN: 0  LEN: 8 EXT: 0 TS: 5919 ID: 76D Buffer: 0 1 2 3 4 5 6 7
MB 99  OVERRUN: 0  LEN: 8 EXT: 0 TS: 6053 ID: 76D Buffer: 0 1 2 3 4 5 6 7
MB 99  OVERRUN: 0  LEN: 8 EXT: 0 TS: 6187 ID: 76D Buffer: 0 1 2 3 4 5 6 7
(continues forever)

Sender log:

FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_INACTIVE
                MB9 code: TX_INACTIVE
                MB10 code: TX_INACTIVE
                MB11 code: TX_INACTIVE
                MB12 code: TX_INACTIVE
                MB13 code: TX_INACTIVE
                MB14 code: TX_INACTIVE
                MB15 code: TX_INACTIVE
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_INACTIVE
                MB10 code: TX_INACTIVE
                MB11 code: TX_INACTIVE
                MB12 code: TX_INACTIVE
                MB13 code: TX_INACTIVE
                MB14 code: TX_INACTIVE
                MB15 code: TX_INACTIVE
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_INACTIVE
                MB11 code: TX_INACTIVE
                MB12 code: TX_INACTIVE
                MB13 code: TX_INACTIVE
                MB14 code: TX_INACTIVE
                MB15 code: TX_INACTIVE
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_INACTIVE
                MB12 code: TX_INACTIVE
                MB13 code: TX_INACTIVE
                MB14 code: TX_INACTIVE
                MB15 code: TX_INACTIVE
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 18 19 1A 1B 1C 1D 1E 1F)
                MB12 code: TX_INACTIVE
                MB13 code: TX_INACTIVE
                MB14 code: TX_INACTIVE
                MB15 code: TX_INACTIVE
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 18 19 1A 1B 1C 1D 1E 1F)
                MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 20 21 22 23 24 25 26 27)
                MB13 code: TX_INACTIVE
                MB14 code: TX_INACTIVE
                MB15 code: TX_INACTIVE
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 18 19 1A 1B 1C 1D 1E 1F)
                MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 20 21 22 23 24 25 26 27)
                MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x5F2)(Payload: 28 29 2A 2B 2C 2D 2E 2F)
                MB14 code: TX_INACTIVE
                MB15 code: TX_INACTIVE
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 18 19 1A 1B 1C 1D 1E 1F)
                MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 20 21 22 23 24 25 26 27)
                MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x5F2)(Payload: 28 29 2A 2B 2C 2D 2E 2F)
                MB14 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x641)(Payload: 30 31 32 33 34 35 36 37)
                MB15 code: TX_INACTIVE
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 18 19 1A 1B 1C 1D 1E 1F)
                MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 20 21 22 23 24 25 26 27)
                MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x5F2)(Payload: 28 29 2A 2B 2C 2D 2E 2F)
                MB14 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x641)(Payload: 30 31 32 33 34 35 36 37)
                MB15 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0xC6)(Payload: 38 39 3A 3B 3C 3D 3E 3F)
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 18 19 1A 1B 1C 1D 1E 1F)
                MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 20 21 22 23 24 25 26 27)
                MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x5F2)(Payload: 28 29 2A 2B 2C 2D 2E 2F)
                MB14 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x641)(Payload: 30 31 32 33 34 35 36 37)
                MB15 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0xC6)(Payload: 38 39 3A 3B 3C 3D 3E 3F)
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 18 19 1A 1B 1C 1D 1E 1F)
                MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 20 21 22 23 24 25 26 27)
                MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x5F2)(Payload: 28 29 2A 2B 2C 2D 2E 2F)
                MB14 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x641)(Payload: 30 31 32 33 34 35 36 37)
                MB15 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0xC6)(Payload: 38 39 3A 3B 3C 3D 3E 3F)
FIFO Enabled --> Interrupt Enabled
        FIFO Filters in use: 8
        Remaining Mailboxes: 8
                MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x76D)(Payload: 0 1 2 3 4 5 6 7)
                MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x4BC)(Payload: 8 9 A B C D E F)
                MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x489)(Payload: 10 11 12 13 14 15 16 17)
                MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x599)(Payload: 18 19 1A 1B 1C 1D 1E 1F)
                MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x151)(Payload: 20 21 22 23 24 25 26 27)
                MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x5F2)(Payload: 28 29 2A 2B 2C 2D 2E 2F)
                MB14 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x641)(Payload: 30 31 32 33 34 35 36 37)
                MB15 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0xC6)(Payload: 38 39 3A 3B 3C 3D 3E 3F)

Lightly modified example code:

#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(500'000);
  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 byte_count = 0;
  static uint32_t timeout = millis();
  if ( millis() - timeout > 2000 ) {
    CAN_message_t msg;
    msg.id = random(0x1,0x7FE);
    for ( uint8_t i = 0; i < 8; i++ ) msg.buf[i] = byte_count++;
    Can0.write(msg);
    timeout = millis();
    Can0.mailboxStatus();
  }

}

Maybe double check the connection from the receiving Teensy's Tx pin to the transceivers D pin.

Knio commented

Thanks! after testing again, it seems my transceiver is defective and can read, but not generate a voltage. I suspect there might be a lot of counterfeit VP230s around...

I would still like to know if there's a way to disable the auto-retransmission, or clear all the queues?

no, auto retransmission is done by hardware not software. if you send one frame it will try forever until someone gets it. clearing the queues won't help if your code still submits a single transfer