If I initialise CAN according to the mbed example with it being defined as a CAN object outside of the main process, the mcu fails to boot and throws a runtime fault. This is because I need to initialise the can transceiver first with a digital can enable pin first before the can Tx and Rx lines are initialised to prevent the Rx line from being pulled down and thus causing a runtime error. This is how I would like to do things, but I am unsure how to do it:
#include "mbed.h"
//CAN can1(can1rx, can1tx, 500000); //cant initialise here without creating runtime error
CAN can2(can2rx, can2tx, 500000); //second can
DigitalOut led(LED1);
DigitalIn canFault(can1nfault);
DigitalOut canNSTB(can1nstb);
DigitalOut canEN(can1en);
#define repeatTime 100ms
void canInit(){
wait_us(100);
canEN = 1;
wait_us(100);
canNSTB = 1;
wait_us(100);
//Need to initialise CAN here instead
can_init_freq(&cb1, can1rx, can1tx, 500000); //Tried to use this function but unsure how to properly call it
}
int main(){
canInit();
while (true) {
led = !led;
ThisThread::sleep_for(repeatTime);
//printf("Hello World\n");
}
}
Hi, Sorry i forgot those details - I am using a STM32-F446RE.
Can 1 is connected to a TJA1043 transceiver that needs the enable and not standby pins set to certain logic levels before can interface is configured, thats causing problems.
Can2 is connected to a SN65 can transceiver which does not have these additional pins and works fine.
#include "mbed.h"
//first default state of pins
DigitalOut canNSTB(can1nstb,1);
DigitalOut canEN(can1en,1);
// then CAN
CAN can1(can1rx, can1tx, 500000); //cant initialise here without creating runtime error
CAN can2(can2rx, can2tx, 500000); //second can
DigitalOut led(LED1);
DigitalIn canFault(can1nfault);
Or using pointers is a way.
CAN *can1;
//later
can1 = new CAN(can1rx, can1tx, 500000);