CAN bus : communication with EPOS2 controller device

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Posts: 1
Joined: Thu Mar 12, 2020 7:30 am

CAN bus : communication with EPOS2 controller device

Post by Ghost114 » Thu Mar 12, 2020 9:49 am

Hello everyone,

I'm back with useful information, so I edited this post.

For my work, I need to use a pyboard to communicate with a Maxon EPOS2 device through CAN bus. ... ung/367676
I'm using the same micropython functions as in : ... hlight=can

The first step to reach this goal was to establish a CAN communication between two pyboards, using a LT1796CN8 transceiver.
This was a success as one pyboard is randomly turning the internal leds on and off and the other one (the slave pyboard) is repeating the same actions.

Now, I connected the EPOS device to the can bus and I'm trying to send and read the data from it.

This is the basic code I'm using :

Code: Select all

from pyb import CAN, LED, delay

# according to
# with a clockrate of 42MHz
can1 = CAN(1, CAN.NORMAL)
can1.init(CAN.NORMAL, extframe=False, prescaler=3, sjw=1, bs1=11, bs2=2)
# to have a 1Mbits/s of bitrate, same as EPOS2

# list of objects from EPOS2
Modes_of_operation_id = 0x6060-00 # RW
Position_actual_value_id = 0x6064-00   # [qc], RO
Velocity_actual_value_id = 0x606C-00 # [rpm], RO
Current_actual_value_id = 0x6078-00 # [mA], RO
list_id = (Modes_of_operation_id,Position_actual_value_id,Velocity_actual_value_id,Current_actual_value_id)
# filter 0 
can1.setfilter(0, CAN.LIST16, 0, list_id)

# leds initialisation.
leds = [LED(1), LED(2), LED(3), LED(4)]
for i in leds: # turn all the leds off

# modify operation mode
    can1.send(1, Modes_of_operation_id, timeout=5000)
    print('Operation mode changed !')
    print("Can't change Operation mode ! ")

# data acquisition
for i in range(1,10):
      # data is received on filter 0
      _id, rtr, fmi, data = can1.recv(0, list=None, timeout=5000)
      print('Value : ', data)
      print('Type : ', type(data))

     print("Can't read data !")
Running the code has no effect on the EPOS. And I get an error when trying to read a message.

After some research, I found out that the SDO protocol must be used to communicate with the EPOS device. The idea is to send a data frame with a certain size (resquest). In response, the EPOS send back a data frame (response) with has the same size and the information we need.

Someone else has already done this with Arduino. Here is the link.
This is exactly what I want to do with my pyboard.

What I need now is to translate this C++ code into a micropython code so I can use it on the pyboard. I'm not good with C++ so I don't understand the synthax.

I know that the proposed code in C++ is long. A simple code where I can read and write from/to the controller device is enough for now.

Thank you in advance for you help and stay safe

Post Reply