Bafang communication protocol UART

Teh Stork

1 kW
Joined
May 25, 2011
Messages
463
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.
 
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/e-bike-conversion-software/#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
 
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.
 
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.
 
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
 
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.
 
user3bss said:
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
 
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 :eek:)

Display Commands and some Controller Replies:
Code:
# 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
 
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!
 
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.
 
rewsiffer said:
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
 
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)...
 
Tiju said:
rewsiffer said:
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.
 
Back
Top