NUCLEO-F413ZH STM32F413ZHT6 144 pins - CAN BUS

All about boards manufactured by ST
Post Reply
User avatar
konczakp
Posts: 18
Joined: Sat Jul 25, 2020 8:22 pm

NUCLEO-F413ZH STM32F413ZHT6 144 pins - CAN BUS

Post by konczakp »

Hi,

I have never used CAN BUS before so I need some help. Im trying to communicate 2 boards like STM32F1 Blue Pill with NUCLEO STM32F4. I know I need a transceivers for this to meet can bus standard but while I'm waiting for delivery of those transceivers I started to run some tests with code etc. At this point I just want to check on the oscilloscope if the code is working and maybe I will try to communicate both boards in this way :
renditionDownload.png
renditionDownload.png (46.72 KiB) Viewed 3509 times
I already searched the internet for the examples but none of them wanted to work as it should. One of them is just placing CAN pins in the right state but it is not transmitting anything. Another one after upload made my board (Blue Pill) unreachable (USB port enumeration problems). I've tried this one for example: https://raw.githubusercontent.com/nopno ... 32f103.ino.
I was hoping someone here was able to communicate via CAN BUS and is able to share some example. As I mentioned at the beginning I'm starting my journey with CAN-BUS so I need very simple example.

EDIT:

I also tried the meCAN from here: https://github.com/mackelec/meCAN but nucleo freezes on can1.begin. COde like this:

Code: Select all

#include <PString.h>
#include <Streaming.h>
#include <meCAN.h>

meCAN1 can1;
meCAN1 canData;

// PB0 - LED1
// PB7 - LED2
// PB14 - LED3
#define LED_PIN PB14

void setup() {

  pinMode(LED_PIN, OUTPUT);
  Serial.setRx(PD9); // for STM32F413 STLINK 
  Serial.setTx(PD8); // for STM32F413 STLINK 
  Serial.begin(115200);

  can1.begin(125,PB8,PB9,STD_ID_LEN); //for STM32F413 (Speed, CAN1_Rx, CAN1_Tx, ID_LEN)
  can1.attachInterrupt(can1ISR);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);   
  delay(1000);                       
  digitalWrite(LED_PIN, LOW);    
  delay(1000);                       
}

void can1ISR() 
{
  readCAN1();
}

uint8_t theNumber=33;

void readCAN1()
{
  can1.rxMsgLen = can1.receive(can1.id, can1.fltIdx, can1.rxData.bytes);
  Serial << "Can len = " << can1.rxMsgLen << endl;
  if (can1.rxMsgLen<1) return;
  if (can1.id != 100) reportCAN(&can1);
  sendCAN1();
}

void sendCAN1()
{
  unsigned char out[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  out[0] = theNumber;
  bool result = can1.transmit(102,out,8);
}


void reportCAN(meCAN1 *can)
{
  Serial << "CAN1 Rx <id> " << can->id << "  [" << _HEX(can->id) << "]  " << endl ;
  for (int i=0;i<can->rxMsgLen;i++)
  {
    Serial << _HEX(can->rxData.bytes[i]) << " " ;
  }
  Serial << endl;
}

What I'm missing here?
mack
Posts: 8
Joined: Sat Feb 08, 2020 2:33 am

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - CAN BUS

Post by mack »

I'm not sure I got all three CAN ports going on the F413. I had a mishap with a stray 12V wire and the F413 processor smoke managed to escape.

I use the library personally on F103/105/107 and L432/L452.

FYI, I've only used it with CAN transceivers.

The original ExeoCAN library can get stuck in an endless loop on INIT, to do with BUS condition, so I have made a change to meCAN that I may not have uploaded to Github.

Send me a private message if you need further help.
Post Reply

Return to “STM boards (Discovery, Eval, Nucleo, ...)”