Skip to main content
Visitor II
December 20, 2017
Question

STM32F3 CAN Bus example using HAL Library

  • December 20, 2017
  • 5 replies
  • 6916 views
Posted on December 20, 2017 at 18:49

Hello,

I'm trying to bring up the CAN bus on the STM23F303RE nucleo board and am having some difficulty determining which way to go.  I've been unable to find a HAL library example for this platform.  Can anyone point me to one?  I have found a HAL example for the STM32F4 but that target has different peripherals.  

Also, I see three different possible design approaches for this project.  It's a fairly simple control loop that we're developing.  The 3 options seem to be:

   1. Code system using HAL library.

   2. Use STMCube for development (but why is there no CAN example for STMCube and the STM32F3xx?)

   3. I see the ARM-Mbed program but am not familiar with the benefits or roadblocks of using that RTOS.  (I don't think we need an RTOS)

Thanks for any suggestions here.

- Dave

#can-bus-stm32f303
    This topic has been closed for replies.

    5 replies

    Graduate II
    December 20, 2017
    Posted on December 20, 2017 at 19:13

    None of the NUCLEO boards ship with CAN transceivers, dig into the HAL examples for other boards (ie EVAL series), and port to your target and pin selections.

    STM32Cube\Repository\STM32Cube_FW_F3_V1.9.0\Projects\STM32303C_EVAL\Examples\CAN\CAN_Networking\readme.txt

    Visitor II
    December 20, 2017
    Posted on December 20, 2017 at 19:30

    I’m looking doing just that from the STM32F4 code. Do you know if the addresses and ports are the same between the F3 and F4? We will be building our own trancievers. Do you know if I’m going STM board to STM board if I need the trancievers?

    Thanks,

    - Dave

    ________________

    Attachments :

    image001.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyEX&d=%2Fa%2F0X0000000b4u%2FlNb1bbGShAZykI2eARa6Ww.QHbPckMesRspkqYcgeAI&asPdf=false
    Graduate II
    December 20, 2017
    Posted on December 20, 2017 at 19:52

    The CAN implementation between F2, F3 and F4 should be very similar, APB bus speed being the main thing impacting choice of settings.

    With board-to-board you'd need at minimum a diode arrangement as CAN RX needs to see TX data to confirm signal has been placed on bus, and you'd need a responding device to acknowledge receptions.

    Visitor II
    December 21, 2017
    Posted on December 22, 2017 at 00:40

    I've got the networking sample code running (sort of) on two stm32f303re Nucleo boards. I'm waiting on transceivers which should arrive tomorrow.  I was wondering about the sample code however.  Since both boards are loaded with the same code, won't they both be at the same CAN address?  I think they're both set to StdId of 0x321 in the CAN_config function.  Is that the CAN ID or is it set on the hardware somehow?

    Thanks,

    Graduate II
    December 22, 2017
    Posted on December 22, 2017 at 01:22

    It is not an address, it is a message ID

    Visitor II
    December 22, 2017
    Posted on December 22, 2017 at 02:16

    How do you set the CAN address on the Nucleo boards?

    Sent from my iPhone

    Visitor II
    December 22, 2017
    Posted on December 22, 2017 at 02:36

    To set the address, I set my address by dip switch.

    I used a slot of 16 ID's for each node.

    All over I have 48 nodes all using 16 addresses, I use the 'ID' range of 0x400-0x7ff.

    as you can see there is no server address.

    The primary sensors are the lower 32 slaves, and the IO boards occupy the top 16

    any node can transmit strings on channel 0, receive commands on channel 1 etc.

    I send 16 analog values on channel 2. A node can send commands to an IO board on channel 4.

    there are many ways to implement an addressing scheme, this one works well for me.

    Visitor II
    December 22, 2017
    Posted on December 22, 2017 at 02:50

    The Nucleo board has no dip switches. I’ve not found any docs about it. I’m sure they are there but I haven’t found them.

    Sent from my iPhone

    Graduate II
    December 22, 2017
    Posted on December 22, 2017 at 03:02

    His board has DIP switches, assume it's not a Nucleo.

    Run a different program on each. Typically when testing CAN you want a Transmitter App on one board, and a Receiver App on the other, to acknowledge traffic. ie one sends 0x123 messages, the other filters/listens for 0x123 messages.

    It isn't an Address, all boards see the same traffic, you can set a filters to select which ID messages you want to process. ie in a car the window motor doesn't need to receive the oil temperature, but  all windows might want to hear a home message.

    Visitor II
    December 22, 2017
    Posted on December 22, 2017 at 04:01

    You can mimic a dip switch on the nucleo board by setting some pins to input with pull ups turned on,

    putting these pin low to read 0s

    Edit:

    the easiest way through to success is to use a third party, known good data source.

    I purchased a CanDo unit, and started sending frames, then I got my receiver working first...

    then I worked to transmit to the CanDo.

    using port pins for the addressing.

    Visitor II
    December 23, 2017
    Posted on December 23, 2017 at 00:50

    Thanks for the info. It’s not a simple protocol/implementation. I thought that the networking example could be run on both boards. Pressing a button on either board would transmit a message on the bus and the other boards would catch it. (Would the transmitter see its own message?)

    I’m working at wiring the Nucleo boards to the L9616 CAN bus transceiver. It looks like it should be trivial but the first hurdle is to figure out orientation of the chip! The docs show a standard dot or indent on the corner of chip to indicate pin 1 but none of my chips have any pin 1 indication. I’ve got a 50% chance to get it right.

    So, I wired TX and RX from the Nucleo to the transceiver but it is not working as expected. When I transmit a CAN package, the TX, RX, C-HI and C-LO all show the same squarewave waveform. Should I see the TX signal on the RX pin? (Maybe so since it’s out on the bus) And I would expect the sign of the C-HI and C-LO to be opposite. Is this correct? I do not have 120 ohm terminating resistors but I wouldn’t think I need them for a small bench-top test. Also, what level should the Reference Voltage pin be held at on the L9616? I did not see that in the technical specs manual.

    I have the CL/CH output of the CAN transceiver going to a USB/CAN tool and it doesn’t detect a CAN device on the network…

    Any suggestions appreciated.

    Thanks,

    ________________

    Attachments :

    image001.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyES&d=%2Fa%2F0X0000000b4t%2FCLqMX5MZHnzsy2mxZ_lYX9A9cBZseGSRnLOD7tCiKVE&asPdf=false
    Visitor II
    December 23, 2017
    Posted on December 23, 2017 at 01:46

    Please check the

    beveled edge

    on the chip.. you must know the orientation.

    Sounds like you have lost your ground reference, maybe the chip is backwards...

    To check your transceiver,

    Start your USB/Can unit transmitting frames...

    can you check it on the scope ? 

    The 120R is not needed for bench work. if you check the scope, you wont see ringing due to the light weight of the short copper wires.

    on the transceiver chip, you should see traffic on the Rx pin, and not on the Tx pin or ground pin.

    I guess the Rx1 pin is for noisy circuits. It is an output, so a 0.1uF cap I guess.. There must be an application note.

    Graduate II
    March 24, 2024

    Hello, David. I have a STM32F303 connected to a L9616 and I can transmit to the CAN bus, but Despite all the effort I could not get the reception callbacks fired. The 9616 Vs pin is connected to 5V instead of 3.3V and I suspect this is why the STM32 CAN Rx pin is at 5V.

    Can you please share your connection diagram between STM32 and L9616 with me? Could you make your device work as expected?

    Best regards,

    Hering

    Technical Moderator
    March 24, 2024

    Hello @enhering ,

    Could you please open a new thread as this one is very old and the member who you are looking for to help could no more available in the community.

    Other members in this community can assist you ..

    Thank you.