FDCAN Teensy 4.1 and STM32

Drodru

Member
Hello everyone. I'm trying to communicate with an STM32 using FDCAN, but right now I didn't success. I'm sending the Teensy code here. Any clue, I don't know what information I can provide, so if any question I'm glad to awnser. The FDCAN specs are: 500kbits nominal and data, 20MHz clock, 150ns propagation delay, 20ppm clock tolerance in the STM32.
Thank you

Code:
#include <FlexCAN_T4.h>

FlexCAN_T4FD<CAN3, RX_SIZE_256, TX_SIZE_16> myFD;

uint32_t serial_clock = 0;
uint32_t serial_timer = 100;

const uint8_t payload_size = 10;
uint8_t payload[payload_size] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

CANFD_message_t msg_tosend;

void fdcan_begin()
{
  myFD.begin();

  CANFD_timings_t config;
  config.clock = CLK_20MHz;
  config.baudrate = 500000;
  config.baudrateFD = 500000;
  config.propdelay = 150;
  config.bus_length = 1;
  config.sample = 86.25;
  myFD.setBaudRate(config);

  myFD.setMB(MB0, RX, EXT);
  myFD.setMB(MB1, TX, EXT);
  myFD.onReceive(MB0, fdcan_receive); // allows mailbox 0 messages to be received in the supplied callback.
}

void fdcan_receive(const CAN_message_t &msg)
{
  for ( uint8_t i = 0; i < msg.len; i++ )
  {
    Serial.print(msg.buf[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

void set_message()
{
  msg_tosend.id = 0x11;
  msg_tosend.len = 8;
  msg_tosend.flags.extended = 0;
  msg_tosend.flags.overrun  = 0;
  msg_tosend.flags.reserved = 0;
  for (uint8_t i = 0; i < payload_size; ++i)
    msg_tosend.buf[i] = payload[i];

}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(430800);
  fdcan_begin();
  set_message();
}

void loop() {
  myFD.events();

  if (millis() > serial_clock + serial_timer)
  {
    serial_clock = millis();
    myFD.write(MB1, msg_tosend);
    Serial.println("a");
  }
}
 
Back
Top