Bafang communication protocol UART

Get all your technical information about electric bikes here.
Post Reply
Teh Stork   1 kW

1 kW
Posts: 461
Joined: May 25 2011 8:02am

Bafang communication protocol UART

Post by Teh Stork » Dec 06 2015 6:25am

Hello,

I'm interested to know if anyone has done any reverse engineering on the bafang controller - display communication protocol?

It seems to be a relatively simple UART connection. The best would be to get the standard directly from Bafang, as there is sure to be some commands that are not utilized by the display.
2013 VW E-UP!
Kona mtb: Cromotor, Kelly KEB, ~6kW peak, 1,4kWh 90V battery 29E cells, 38 kg

philipps   1 µW

1 µW
Posts: 3
Joined: Nov 22 2015 3:01pm

Re: Bafang communication protocol UART

Post by philipps » Mar 06 2016 2:08pm

Hi,

the configuration tool for the Bafang Motors also contains the sourcecode written in Delphi from which you can get an idea of the protocol. The original source code is however very poorly written. Penooff did a rewrite of the tool with much more readable source code:
https://penoff.wordpress.com/2016/01/13 ... #more-1538

I also made an attempt to start an alternative Python-based client. Although it is in a very early stage, you should be able to extract the protocoal bits and pieces from the source code:
https://github.com/philippsandhaus/bafang-python

swseo   1 µW

1 µW
Posts: 2
Joined: Apr 07 2016 11:10pm

[Bafang Mid-driven Motor] Command Packet data structure?

Post by swseo » Apr 07 2016 11:24pm

Hello.

Now, I would like to develop my own LCD and external controller. In order to do this, I need to know the information of very detail data structure to send commands to motor controller and receive data and display them.
I know that bafang uses simple UART protorol for LCD display. Also, there is a programming device to program motor controller.
I think that Bafang open a document for the data structure. Just I guess.

Please share the information.

Thank you.

swseo   1 µW

1 µW
Posts: 2
Joined: Apr 07 2016 11:10pm

Re: Bafang communication protocol UART

Post by swseo » Apr 09 2016 9:17am

Hello.

Thank you for your post.

This is very helpful for me.

Now, I would like to develop my own LCD display and controller. Thus, I need the detail spec of uary protocol for run-time(read current ridding speed, send pas assist level, and etc), not just for programming the controller.

user3bss   1 µW

1 µW
Posts: 1
Joined: Jul 27 2016 12:36am

Re: Bafang communication protocol UART

Post by user3bss » Jul 27 2016 12:43am

I spent the last 2 weeks making tools for figuring out the protocol. it uses arduino due a custom shield and nodejs.
I also have a due sketch for capturing display/controller comms. it uses nodejs and has session support, so you can save your captures.
the captures i've done are already there, so u might not even need the due


I also started an app for android ios, using cordova, and theres an arduino nano ah meter

the repo is here: https://gitlab.com/groups/bafang

asotrox   1 µW

1 µW
Posts: 2
Joined: Mar 21 2017 9:23pm

Re: Bafang communication protocol UART

Post by asotrox » Mar 26 2017 1:08pm

Any progress on this? My controller is still in transit, but I've coded the "dashboard" and prepared my workbench to capture UART when it arrives. The goal is to use affordable micro controllers to read and display controller sensors in real-time. I'm not sure what to expect but it should be fun to reverse engineer the bafang protocol.

Tiju   100 µW

100 µW
Posts: 7
Joined: Jan 25 2017 5:44am

Re: Bafang communication protocol UART

Post by Tiju » Apr 26 2017 12:15pm

user3bss wrote:I spent the last 2 weeks making tools for figuring out the protocol. it uses arduino due a custom shield and nodejs.
I also have a due sketch for capturing display/controller comms. it uses nodejs and has session support, so you can save your captures.
the captures i've done are already there, so u might not even need the due


I also started an app for android ios, using cordova, and theres an arduino nano ah meter

the repo is here: https://gitlab.com/groups/bafang
nice work!

I saw in the gitlab repos you made a bluetooth module which relays commands from the android/iPhone app?!
Would be awesome to see a writeup, I'd could join dev. too! (only android though :-] )
Was more thinking about having a way to programm the controller with the phone but ride without the phone out and having a small RFID tag to "lock/unlock" (better said: short or cut the two pins so the motor has power or not) the Bike).

From what I've seen in sources online (python uart protocol @ github and delphi programming software) only reprogramming commands have been REd, what about "display-set" commands? any1 know?

Would be great to hear from you!

Best regards,
- Tiju

Tiju   100 µW

100 µW
Posts: 7
Joined: Jan 25 2017 5:44am

Re: Bafang communication protocol UART

Post by Tiju » May 04 2017 5:27pm

Sniffed some Display <-> Motor Controller Communication and this is what I have found out so far for commands sent by the display.

Whoever found the checksum calc (prolly by reversing the leaked programmer software), that helped a lot... :-)

Display always sends Commands like this (i think): <CMD_TYPE> <CMD_SUBTYPE> <DATA> <Checksum> ( checksum is sum of bytes %256)
Controller just replies in weird ways... no checksum as far as I can tell, but either just the same value twice or with 0x20 added :o)

Display Commands and some Controller Replies:

Code: Select all

# 0x16 => set something
	0xb => set assist level (1 byte)
  -> answer appears to just be "0x01"

# 0xa unknown, length likely 13

# 0x1a unknown, length likely 28

# 0x11 = read something maybe?
	0x08 -> likely brakes
		-> 0x03 = Brake Sensor activated (braking...)
		-> 0x01 = normal
	
	0x11 -> no idea...  maybe voltage
         Values:
	  2 Controller:     0xEA 0xEA
      2 Controller:     0xEB 0xEB
      2 Controller:     0xEC 0xEC
      2 Controller:     0xED 0xED
      2 Controller:     0xEE 0xEE
      2 Controller:     0xEF 0xEF
      2 Controller:     0xF0 0xF0
	  
	0x0A -> most likely amps, stays 0 when only spinning rear wheel
		Values:
		0x01 0x01
		0x02 0x02
		0x04 0x04
		0x05 0x05
	
	0x22 -> speed 
		unknown?wheel?  wheel+0x20?
		0x00    0x00    0x20	=> when speed was 0
		0x00    0x14    0x34  => when speed is higher...
		0x00    0xC3    0xE3  => 24.1 km/h
Hope this helps. If you find some more stuff, please share ;-)

Cheers,
- Tiju

AZeBikeGuy   100 W

100 W
Posts: 114
Joined: Sep 06 2016 2:58pm
Location: Arizona

Re: Bafang communication protocol UART

Post by AZeBikeGuy » Jun 06 2017 1:43pm

I'm super interested in this too!

rewsiffer   100 µW

100 µW
Posts: 7
Joined: Jun 13 2017 12:40pm

Re: Bafang communication protocol UART

Post by rewsiffer » Jun 28 2017 1:05pm

Hi, I search the forum but I couldn't find any solid information.

Do any of you know what voltage the UART communication protocol operates at? I would assume 3.3v or 5v, since they are the most common. I have plenty of UART adapters around from arduino projects so I have no need to buy the "official" bafang programming cable. I just want to make sure I get the voltages right. Thanks!

Lusi22   10 µW

10 µW
Posts: 6
Joined: May 21 2017 8:13am

Re: Bafang communication protocol UART

Post by Lusi22 » Jun 30 2017 2:16am

Hello,

is there a way/software/app to setup the MaxDrive Torque sensor with original programming cable? Penoff`s Software let me only setup PAS, but i need setup for Torque.

Tiju   100 µW

100 µW
Posts: 7
Joined: Jan 25 2017 5:44am

Re: Bafang communication protocol UART

Post by Tiju » Aug 27 2017 6:32am

rewsiffer wrote:Hi, I search the forum but I couldn't find any solid information.

Do any of you know what voltage the UART communication protocol operates at? I would assume 3.3v or 5v, since they are the most common. I have plenty of UART adapters around from arduino projects so I have no need to buy the "official" bafang programming cable. I just want to make sure I get the voltages right. Thanks!
it's 3.3V but might be 5v tolerant... I'm using 3.3V anyway

AZeBikeGuy   100 W

100 W
Posts: 114
Joined: Sep 06 2016 2:58pm
Location: Arizona

Re: Bafang communication protocol UART

Post by AZeBikeGuy » Aug 27 2017 9:25am

I hooked up an oscilloscope and measured 0 to 3.6V on the controller TX side and 0 to 3.74V on the host TX (PC cable I acquired from Luna)...

DaDo.Bzz   100 W

100 W
Posts: 142
Joined: Feb 12 2015 3:29pm

Re: Bafang communication protocol UART

Post by DaDo.Bzz » Aug 29 2018 6:01am

Tiju wrote:
Aug 27 2017 6:32am
rewsiffer wrote:Hi, I search the forum but I couldn't find any solid information.

Do any of you know what voltage the UART communication protocol operates at? I would assume 3.3v or 5v, since they are the most common. I have plenty of UART adapters around from arduino projects so I have no need to buy the "official" bafang programming cable. I just want to make sure I get the voltages right. Thanks!
it's 3.3V but might be 5v tolerant... I'm using 3.3V anyway
Must be 5V tolerant as I have 5V usb to serial. But no problem to make from 5V usb to serial 3.3V by two resistors.
LMX 81, 16S6P 60A
Dengfu E10, M600, 840Wh, 48V
CTM Scroll, BBSHD, 700Wh, 52V
Slovakia, Bratislava

Post Reply