Cannot get Can API to output data to Nucleo-F446RE can-pins (using keil studio)

Ties_van_Essen
Thu, 16 Nov 2023 13:54:01 +0000
Keil Studio

Hi All,

This is my first post so excuse my formatting. I am trying to get the can bus interface to work on my Nucleo-F446RE. I have posted my code below and my current issue is that both the TD & RD pins are permanently high (at 3.3V) without actually transmitting data. I have tried to use the SPI interface in the past with the classic MCP2515 module but that also never worked. I have tried so many things and am at a complete loss, I also have a lot of trouble finding documentation for can bus + STM32 intergration so if you have any links that alone would be greatly appreciated. Thanks!

#include "mbed.h"
// #include "mcu1pindef.h"

#if !DEVICE_CAN
#error [NOT_SUPPORTED] CAN not supported for this target
#endif


/** The constructor takes in RX, and TX pin respectively.
  * These pins, for this example, are defined in mbed_app.json
  */
#define CanRD PB_8
#define CanTD PB_9
CAN can1(CanRD, CanTD, 500000);

static BufferedSerial pc(USBTX, USBRX,9600);

int messageid = 10;

int counter = 0;
char messagedata[8]{
    0x1F,
    0x2F,
    0x1F,
    0x2F,
    0x1F,
    0x2F,
    0x1F,
    0x2F
};

int main()
{
while(1){
   CANMessage msg;
   if (can1.write(CANMessage(messageid,messagedata,8,CANData, CANStandard))){
       printf("Message sent: %d\n", counter++);
}
   else{
       printf("Message failed: %d\n", counter++);
    }

    // if (can2.read(msg)) {
    //     printf("Message received: %d\n", msg.data[0]);
    // }

 }
}

15 posts - 2 participants