camcamfresh / Xiaomi-M365-BLE-Controller-Replacement

Replacing the BLE Controller with a Cellular Controller
142 stars 34 forks source link

How to receive data from Motor controller and BMS? #15

Open kyuhyong opened 5 years ago

kyuhyong commented 5 years ago

Thank you for the detailed information as they are very clear and well documented. One thing I noticed is that the board can send message through TX port but how it can receive data from the motor controller and BMS? since there is no RX port for it. Isn't half duplex serial communication still needs both RX/TX ports for receiving and transmitting data?

camcamfresh commented 5 years ago

I was very confused about the communication when I first started and I'm still not sure I completely understand it. I think you're thinking of simplex, which is data communication one way only.

With the scooter, data is transferred via one data wire (plus the ground) that connects to the motor controller, BMS and microcontroller. All three devices talk to each other on the same data line (and share a ground).

When you enable half duplex mode on the Particle device it connects the Rx and Tx line together via an onboard resistor or transistor (maybe both I'm not too sure) and tells the Particle device to only send or receive data, but not both at the same time.

As a result, only one wire is used at a single moment. If we speed the communication up to say 115200 bauds, we can fit the Tx and Rx on the same line by switching between the two modes really fast. Particle handles this all in there library, so all we have to do is program the communication protocol.