cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32F4] Unable to get CAN to work using HAL

3pak
Associate II

I have been trying to get CAN communication to work using the STM32F4 HAL. I am using the MCP2561 (http://ww1.microchip.com/downloads/en/DeviceDoc/20005167C.pdf) transceiver with the Nucleo board. I have tried using both Normal mode and Loopback mode. On the other side of the transceiver, we have a connection to CAN termination resistors, which is connected to a PCAN-USB converter that goes to a computer running PCAN explorer.

We do not see anything on PCAN explorer or on an oscilloscope that is connected directly to the STM32 CAN RX and CAN TX pins. We can see by debugging in TrueSTUDIO that the CAN messages do make it into the TX mailbox, but they never get sent.

1 REPLY 1
T J
Lead

this code will transmit data out the CanPort..

Our suggestion is that you work on the receiver first.

if you can transmit every second from WindowsPCan, then work on the receiver code

just check on the scope that PCan is transmitting.

if the scope shows a continuous mishmash of signals, then the receiver is not initialised correctly.

That will clarify the correct bit rates and segment timings.

then you could work on the transmitter.

if ((CAN1->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) 	// (1) 
  {
    CAN1->sTxMailBox[0].TDTR = canTxMsgLength[canTxMsgOUT];	        // (2) length
    CAN1->sTxMailBox[0].TDLR = canTxMsgBottomWord[canTxMsgOUT]; // (3) 4bytes
    CAN1->sTxMailBox[0].TDHR = canTxMsgTopWord[canTxMsgOUT];       // (3) 4bytes
   CAN1->sTxMailBox[0].TIR  = ((uint32_t)canTxMsgID [canTxMsgOUT] << 21 | CAN_TI0R_TXRQ); 	// (4)	// send it now if the line is idle
the frame is sent at this point.