cancel
Showing results for 
Search instead for 
Did you mean: 

CAN on stm32f303xC processor

ArturasV
Senior
Posted on November 21, 2014 at 14:58

The original post was too long to process during our migration. Please click on the attachment to read the original post.
10 REPLIES 10
Posted on November 21, 2014 at 15:41

You have to send the CAN data to something that will receive it, you can use a transceiver or a diode arrangement.

On an F4 you can externally loop through transceivers CAN1 and CAN2. I'd recommend doing initial experiments on hardware known to work.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ArturasV
Senior
Posted on November 21, 2014 at 16:11

So could you place answer me to this: If i don't use CAN tranceiver and i wont have something to accept data or diode arrangement for test, i won't be able to see any data with oscilloscope and initialization will fail? Yes or no?  If yes, then what is purpose of silent loopback mode? Shouldnt it work without a CAN tranceiver? Because i have wired up a CAN tranceiver, i thought i would look first is it possible to send data first, but i only have a tranceiver, no receiver.

Posted on November 21, 2014 at 19:27

I'm not using CAN on the F3, so have little time invested, or too invest, in what the silicon may or may not do.

What I can tell you is that in the F1/F2/F4, that ''loopback'' internally is a pretty useless test if you want to see real bus traffic, and I don't know what feedback the CAN peripheral is looking for on the pins in ''normal'' mode. I wired up two nodes with transceivers, and can see traffic. This would seem like a minimal threshold to effectively test anything.

The ''silent loop back'' on the F3, no signalling gets to the pins (per Ref Manual), but you can presumably sit in a loop sending and receiving to yourself.

The non-silent loop back should at least get a signal to CAN_TX pin

STM32F30x_DSP_StdPeriph_Lib_V1.0.0\Project\STM32F30x_StdPeriph_Examples\CAN\CAN_LoopBack\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock
Associate III
Posted on November 21, 2014 at 23:02

The loopback mode is useful for software unit testing the CAN stack, since it allows you to send a message and debug how it is processed when it is received after loopback.

To see signals on the CAN bus you need two nodes.  Inherent in CAN is a requirement for a minimum of two nodes.  A single node will recognize the bus is not configured right and will throw lots of errors.

The silent mode is useful after detecting a bus error (i.e. only one node).  To stop the flood of errors disable the CAN node but periodically enable in silent mode to see if the errors have cleared.  This gives you a sort of hot plug recovery on the bus.  The silent mode will be the receiver for the other node so if you only have two nodes it will come up.  The trick is to listen a multiple period longer than attempting to transmit so you don't get into a race condition.  The gap between silent listening should be smaller that the time you try to send before erroring out.

The logic for the CAN peripheral seems odd but after implementing a stack it's actually well thought out, especially for CANopen.

  Jack Peacock
ArturasV
Senior
Posted on November 22, 2014 at 12:27

Clive and Jack Peacock, thank you for your answers and explaining things clearly. But i didn't understand one thing from explanations: So that silent loopback mode stilll wont work if i don't have two CAN nodes? If it internally connects as ref manual states, why would i need CAN tranceiver for that?  CAN should at least go through initialization?

ArturasV
Senior
Posted on November 24, 2014 at 11:11

I still don't get it. When CAN is being initialized, it waits for the acknowledge. What should give the ack here? because i am always jumping to InitStatus = CAN_InitStatus_Failed. So as i see The INAK bit in MSR is never set to 0. Why?

 /* Request leave initialisation */

    CANx->MCR &= ~(uint32_t)CAN_MCR_INRQ;

   /* Wait the acknowledge */

   wait_ack = 0;

   while (((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))

   {

     wait_ack++;

   }

    /* ...and check acknowledged */

    if ((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)

    {

      InitStatus = CAN_InitStatus_Failed;

    }

    else

    {

      InitStatus = CAN_InitStatus_Success ;

    }

bcarpenter
Associate
Posted on November 28, 2014 at 02:02

Did you have any luck solving the initialisation issue? I'm have the same problem.

schwegelm
Associate
Posted on November 29, 2014 at 17:44

Hi, I have to command an industrial motor using the CAN bus. I've never used it, and so I'm wondering what exactly I need to use it. If I got an STM 32F303 or 32F4 or 32F2, do I need a seperate Transceiver? And are there libraries for using the CAN bus/Transceivers? And or any kind of Tutorials, Examples or the like?

Posted on November 29, 2014 at 23:51

do I need a seperate Transceiver? And are there libraries for using the CAN bus/Transceivers? And or any kind of Tutorials, Examples or the like?

Yes, generally you'd want a transceiver.

Suggest you look at STM32 board schematics using CAN, and the examples in the firmware library. I've posted a bunch of examples here too.

CAN's been around for decades, so I'm sure there's plenty of documentation and implementation stuff out of the internets.

There are also plenty of low cost STM32 based boards available with CAN .

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..