Photon CAN Bus [Completed]

I had another hour on hardware today but I didn’t make anymore progress. Still not receiving messages (I suspect the pin configuration for the rx, but it looks correct).

TX messages look wrong. I double checked myour code and didn’t see anything.

Need a bigger block of consecutive time and also need to get JTAG running so I can verify the registers.

I have used eclipse with the stm32f2xx along time ago (openocd ), what is everyone using here?

Alright… So I had a good chunk of time to play with this again tonight and I still cannot get my intended message out, or receive a message.

I have removed all CAN interrupts, and buffers. I have also initialized the RCC, GPIO, CAN, CAN Filters using the STM Standard Peripheral Drivers.

So the drivers are getting very simple.

I can still send out a message, but the ID and data are incorrect. If I change baud rate then I get error frames until I change my receiver to the new baud rate then I see the exact same message again.

I have also played around with my CAN transceiver in case that has issues. I have another one on the way from amazon.

If there is anyone out there that want to try and test this for me please grab my code and try it. It should transmit a message once per second. It should also print the latest rx message on the USB serial.

source is located here:

go to:

firmware\main>

run this command while in DFU mode:

make clean all -s PLATFORM=photon COMPILE_LTO=n APP=can MODULAR=n PARTICLE_DEVELOP=1 program-dfu

uses D1 for CAN_RX
uese D2 for CAN_Tx

You need a CAN transceiver to get CAN_Hi and CAN_Low for the CAN Bus.

The CAN transmit message is currently hard coded. So if your seeing valid data you cannot change it via Can1.write;

This is the message I am getting:

ID=0x1FFFFEFF Extended RTR   Data=0x0F

I am trying to send:

ID=0x1234 Extended NoRTR Data= 1, 2, 3, 4, 5, 6, 7, 8
1 Like

My latest code is NOT on git hub. I forgot to push it after I committed. Doh!

I will get it there tomorrow morning

I’m glad you are working on this. I’m using the CANBUS on TI Tiva LaunchPads and I would like to try out your code as soon as you can post it. I made CANBUS to WiFi gateways with CC3100s and CC3200s but I’m not very satisfied with the performance.

@RLRJCN I have uploaded the code.

Which CAN transceivers are you using on the TI Tiva, or does that board already have them populated?

Mostly MCP2551

@RLRJCN FYI I think the example Application initializes the CAN baud rate to 125,000.

Have you had a chance to try it yet?

I just started working with a CANBUS implementation on a Teensy 3.2 which I am able to do a hex dump of the CAN messages from my TI Lauchpads at 1Mb OK. I downloaded your fork and installed it on a Photon and I am able to capture messages coming from the Photon to the Teensy but they don’t appear to have the correct content. On the Photon side it looks like it is receiving it’s own messages because there are no filters. I need to read up on the Photon’s CAN controller as I’m not familiar with the architecture. I dropped the bit rate down to 125Kb but it didn’t seem to make any difference. Do you have any sample code with filters?

So your getting the same result as me. So there is something wrong with the registers and I haven’t figured it out.

The receiver does not seem to be working for me. It should be setup to receive all messages standard or extended. But I have not received anything yet.

@BDub Can you confirm the clock frequencies for me?

Main (SYSCLK) clock frequency is 120 MHz?
APB1 clock frequency is 30 Mhz?

so my baud rate is:
tq (for 250kbit) = (1/30Mhz)8 = 1/3.75Mhz
Nominal Bit Time = 1 * tq + (11
tq) + (3*tq) = 1/250Khz
Baud = 1/Nominal Bit Time = 250Kbit

I have to assume these are correct because I do not see error frames when I change to different baud rates. But I am still stumped as to why I am not getting the correct data out…

Maybe you can do a similar thing to what the usart library does and use the actual value of the clock:

1 Like

Hey ,

can you show me your can bus library ?? Because at Github I can’t finded the code . :smile:

It is not working yet, and I haven’t had time to debug it. I have a hard coded message in the CAN driver transmit but it wasn’t being transmitted correctly either.

I can do the make in the main directory but in the modules directory i get errors as shown below. Is this to be expected or do you know what’s wrong?

…/…/…/build/target/hal-dynalib/platform-6-m//libhal-dynalib.a(hal_can.o): In function HAL_CAN_Init': hal_can.c:(.text.HAL_CAN_Init+0xc): undefined reference todynalib_location_hal_can’
…/…/…/build/target/hal-dynalib/platform-6-m//libhal-dynalib.a(hal_can.o): In function HAL_CAN_Begin': hal_can.c:(.text.HAL_CAN_Begin+0xc): undefined reference todynalib_location_hal_can’
…/…/…/build/target/hal-dynalib/platform-6-m//libhal-dynalib.a(hal_can.o): In function HAL_CAN_Write_Data': hal_can.c:(.text.HAL_CAN_Write_Data+0xc): undefined reference todynalib_location_hal_can’
…/…/…/build/target/hal-dynalib/platform-6-m//libhal-dynalib.a(hal_can.o): In function HAL_CAN_Available_Data': hal_can.c:(.text.HAL_CAN_Available_Data+0xc): undefined reference todynalib_location_hal_can’
…/…/…/build/target/hal-dynalib/platform-6-m//libhal-dynalib.a(hal_can.o): In function HAL_CAN_Read_Data': hal_can.c:(.text.HAL_CAN_Read_Data+0xc): undefined reference todynalib_location_hal_can’
…/…/…/build/target/hal-dynalib/platform-6-m//libhal-dynalib.a(hal_can.o):hal_can.c:(.text.HAL_CAN_Peek_Data+0xc): more undefined references to `dynalib_location_hal_can’ follow

running make in the main directory builds only the application firmware for the photon, not the system firmware (which is built from modules.)

The error looks like a missing library. did you add your library to the HAL makefile?

I’m using https://github.com/bspranger/firmware can you see if it works for you? I want it to rebuild the modules which it is not doing.

sorry it has taken me so long to respond. It could be that I am missing a file in the check in. But try this first and let me know.

from the directory:

C:\Particle\firmware\main

run the following command

make clean all -s PLATFORM=photon COMPILE_LTO=n APP=can MODULAR=n PARTICLE_DEVELOP=1

or if you want it to download via DFU/USB after the compile is complete

make clean all -s PLATFORM=photon COMPILE_LTO=n APP=can MODULAR=n PARTICLE_DEVELOP=1 program-dfu

It works from main but not from modules.

When you say it works, Does that mean it compiles?
I have not tried building the separate modules.

The build completes successfully, downloads to the Photon, runs and apparently sends incorrect data to another CAN devices. I have a working on a TI EK-TM4C1294XL Launchpad with CAN and an Ethernet to WiFi bridge as an alternative to the Photon but it is not as compact.