Skip to main content

CANBUS

Summary

These documents, dumps and projects explain everything we currently know about the Bafang CANBUS protocol

DIY CANBUS configuration

To configure the Bafang M500 / M600 motor without using the BESST programmer, you can use this interface.

Link interface USB to CAN on Amazon: https://www.amazon.co.uk/USB-Converter- ... 709&sr=8-2

Link cables Bafang HMI M500/M600 on e-bike-technologies: https://www.e-bike-technologies.de/inde ... 5-f-detail https://www.e-bike-technologies.de/inde ... 5-f-detail

Below are the software and the instructions for configuration and use. You might need to set InnoMaker to "loopback mode" for the settings to stick.

TODO: Insert images

(https://endless-sphere.com/forums/viewtopic.php?f=28&t=100777&start=400#p1595302)

Pinout

HIGO-B5-Female:
────────┐
/ 1 5 │
│ 2 │
\ 3 4 │
────────┘
1 Orange: VCC/Ctrl
2 White : CL
3 Brown : P+
4 Green : CH
5 Black : GND

Bit Rate 250 kBit/s
Level matching:
L9L5L3Byte
WalkWalkWalk06
00000
101
210B
310C
420D
5202
6315
716
8417
95303
The following Canbus frameid's have been identified:
FunctionGET/SETsecond-last-digitlast-digit
announceUpgrade2000
startUpgradeTransfer2001
pulseGET3000
unknown?3005
sensorSignalGET3100
controllerInformationGET3200
controllerInformation_1GET3201
controllerInformation_2GET3202
controllerInformation_3GET/SET3203
controllerInformation_4GET3204
controllerInformation_5GET3205
batteryInformationGET3400
batteryInformation_1GET3401
batteryInformation_2GET3402
besstGET3500
transmissionInformationGET3600
transmissionInformation_1GET3601
transmissionInformation_2GET3602
transmissionInformation_3GET3603
eletronicLockInformationGET3700
hardwareVersionNumberGET/SET6000
softwareVersionNumberGET6001
modelNumberGET/SET6002
serialNumberGET/SET6003
customerNumberGET/SET6004
manufacturerGET/SET6005
paramsGET/SET6006
errorCodeGET/SET6007
bootLoadGET/SET6008
conParams_1GET/SET6011
conParams_2GET/SET6012
conParams_3GET/SET6013
conParams_4GET/SET6014
conParams_5GET/SET6015
conParams_6GET/SET6016
conParams_7GET/SET6017
conParams_8GET/SET6018
sensorCalibrationGET6100
positionSensorCalibrationSET6200
clear_Hmi_Total_MileageSET6201
set_Hmi_TimeSET6202
clear_Hmi_Single_MileageSET6203
controllerFeaturesGET6215
dataOfHmiGET6300
dataOfHmi_1GET6301
dataOfHmi_2GET/SET6302
dataOfHmi_3GET6303
dataOfHmi_4GET6304
designInformationGET64?
chargingInformationGET6401
batteryCellsInformationGET6402
batteryCellsInformation_1GET6403
batteryCellsInformation_2GET6404
batteryCellsInformation_3GET6405
batteryCellsInformation_4GET6406
batteryCellsInformation_5GET6407
batteryCellsInformation_6GET6408
batteryCellsInformation_7GET6409
batteryCharacteristicsGET6415
set_Hmi_CardSET6500

Global Enums in BESST code

Source and target devices on the canbus.
Torque sensor   : 0x01
Controller : 0x02
HMI : 0x03
Battery : 0x04
BESST interface : 0x05
Advanced : 0x1f
References for the BESST USB tool used to send certain CANBUS commands
WRITE_CMD           : 0x00
READ_CMD : 0x01
NORMAL_ACK : 0x02
ERROR_ACK : 0x03
LONG_START_CMD : 0x04
LONG_TRANG_CMD : 0x05
LONG_END_CMD : 0x06
LONG_WARNING_CMD : 0x07
OPT_HARDWARE_VERSION    : 0x00
OPT_SOFTWARE_VERSION : 0x01
OPT_MODEL_VERSION : 0x02
OPT_SN : 0x03
OPT_CLIENT_NO : 0x04

These can be used using our CANBUS frameid calculator here: https://ornias1993.github.io/Bafang_M500_M600/index.html

Known working CANBUS commands

BESST Speed/Wheel/Circumference Setup
Decoding example: 05103203 6 70 17 B5 01 C0 08
ID: 05103203
Speed Limit Byte 1/0 : 70 17 -> 0x1770 = 6000 => 60.00km/h
Wheel Size Byte 3/2 : B5 01 -> 0x01B5 -> 0x01B . 5 = 27 . 5 => 27.5"
Circumference Byte 5/4 : C0 08 -> 0x08C0 = 2240 => 2240mm

Decoding example: 05103203 6 C4 09 D0 01 C0 08
ID: 05103203
Speed Limit Byte 1/0 : C4 09 -> 0x09C4 = 2500 => 25.00km/h
Wheel Size Byte 3/2 : D0 01 -> 0x01D0 -> 0x01D . 0 = 29 . 0 => 29.0"
Circumference Byte 5/4 : E8 08 -> 0x08E8 = 2280 => 2280mm

Little-Endian byte order!
BESST Torque Sensor Calibration
ID: 05106101
Numbers Byte: 0
BESST Position Sensor Calibration
ID: 05116201
Numbers Bytes: 0
Controller % Battery/Level Informations
ID: 02F83200
Numbers Byte: 8
% Battery Byte 0 : 50%(0x32) = 32
Byte 1/2/3 : 00 00 00
Byte 4 : EE
Byte 5 : 02
Level Byte 6/7 : FF FF
Controller Speed/Current/Voltage/Temperature Informations
Decoding example: 02F83201 8 C4 09 E8 03 E2 14 32 3C
ID: 02F83201
Numbers Byte: 8
Speed Byte 1/0 : C4 09 -> 0x09C4 = 2500 => 25.00km/h
Current Byte 3/2 : E8 03 -> 0x03E8 = 1000 => 10.00A
Voltage Byte 5/4 : E2 14 -> 0x14E2 = 5346 => 53.46V
Temp. Control. Byte 6 : 32 -> 0x32 = 50 -> 50 - 40 = 10 => 10°C
Temp. Motor Byte 7 : 3C -> 0x3C = 60 -> 60 - 40 = 20 => 20°C

Little-Endian byte order!
Controller Speed/Wheel/Circumference Informations
Decoding example: 02F83203 6 70 17 B5 01 C0 08
ID: 02F83203
Speed Limit Byte 1/0 : 70 17 -> 0x1770 = 6000 => 60.00km/h
Wheel Size Byte 3/2 : B5 01 -> 0x01B5 -> 0x01B . 5 = 27 . 5 => 27.5"
Circumference Byte 5/4 : C0 08 -> 0x08C0 = 2240 => 2240mm

Decoding example: 02F83203 6 C4 09 D0 01 C0 08
ID: 02F83203
Speed Limit Byte 1/0 : C4 09 -> 0x09C4 = 2500 => 25.00km/h
Wheel Size Byte 3/2 : D0 01 -> 0x01D0 -> 0x01D . 0 = 29 . 0 => 29.0"
Circumference Byte 5/4 : E8 08 -> 0x08E8 = 2280 => 2280mm

Little-Endian byte order!

Controller State Informations
ID: 02FF1200
Numbers Byte: 1
Bit0 Brake state : 1=Brake
Bit1 Motor stopped : 1=Stopped
Bit2 Battery undervoltage : 1=Undervoltage
HMI Level/Light Setup
ID: 03106300
Numbers Byte: 4
Levels number Byte 0 : 03 / 05 / 09
Set Level Byte 1 : Walk = 06 / 0 = 00 / 1 = 01 / 2 = 0B / 3 = 0C / 4 = 0D / 5 = 02 / 6 = 15 / 7 = 16 / 8 = 17 / 9 = 03
Button "+" Byte 2 : Off = 00 / On = 02 / Off with light = 01 / On with light = 03
Boost mode Byte 3 : Off = 01 / On = 00 (after two seconds of pressing the power button)
Torque Sensor
ID: 01F83100
Numbers Byte: 4
Torque Byte 0/1 : EE 02
Cadence Byte 2 : 00
Progressive Byte 3 : 01

CAN messages during operations

HMI
03106300 every 100ms
BESST
05F83501 every 1016ms
Controller (Only with the presence of the HMI or BESST)
02F83200 every 1500ms
02F83201 every 280ms
02F83202 every 100ms
02F83203 every 450ms
02F83205 every 300ms
02FF1200 every 490ms
Torque Sensor
01F83100 every 10ms
Battery
04F83400
04F83401
04F83402

CAN messages ondemand

Torque Sensor

03096000 Hardware Version Number
03096001 Software Version Number
03096002 Model Number
03096003 Serial Number
03096004 Customer Number

Controller

03116000 Hardware Version Number
03116001 Software Version Number
03116002 Model Number
03116003 Serial Number

Battery

03216000 Hardware Version Number
03216001 Software Version Number
03216002 Model Number
03216003 Serial Number
03216004 Customer Number

CANBUS controller update procedure

1. Start continuesly announcing that the host (pc) is ready to transfer a firmware update:

M500 05FF3005 - 00 ( BESST "waiting in firmware update mode" or "Trying to transfer") 05112000 - 88 45 02 00 (Polling: "Is Controller ready for firmware?")

M600 05FF3005 - 00 ( BESST "waiting in firmware update mode" or "Trying to transfer") 05112000 - 89 45 02 00 (Polling: "Is Controller ready for firmware?")

2. Wait for Controller response: Once you recieve this confirmation, you can stop announcing as stated in step 1.

M500

022A2000 - 88 45 82 (Response: "Controller ready to recieve firmware")

M600

022A2000 - 89 45 82 (Response: "Controller ready to recieve firmware")

3. send first package:

This package contains the length of the file, minus the first 16 hex bytes, transformed into hex. We will use ## ## ## to represent this value.

`` 05142001 - ## ## ## (Transfer started from BESST, contains length in hex)

4. wait for response first package:

We now need to wait for the response from the controller before actually starting to send the firmware

022A2001 - 00 (Transfer start ack from Controller)

5. send data:

We now send the firmware in 8 byte chunks, minus the first 16 hex bytes. Each chunk will be numbered in hexadecimal, starting from 0000. After each chunk we will recieve a response verifying the transfer has been completed successfully. We will use #### to represent the ever incrementing chunk numbers. While we list only one response, ofcoarse this means multiple chunks get send with incrementing frame numbers. We will use XX XX XX XX XX XX XX XX to represent the file content that is getting transfered.

Do not send the last data package this way though...

Data send:

0515#### - XX XX XX XX XX XX XX XX (Data transfer packages)

Response from controller:

022A#### - (Data transfer packages ack from controller)

6. send last data and end transfer:

This package needs to go towards a different frameID, to signal the controller that the transfer has been completed. The content of the package can vary in length up to 8 bytes, which we will simulate by using XX. The #### is still the autoincrement number from step 5.

Data send:

0516#### - XX (Transfer completed from BESST)

Response from controller:

022A#### - (Data transfer packages ack from controller)