BLE Module MCU Development Overview
Last Updated on : 2020-08-05 03:44:28download
Tuya is providing developers with MCU SDK that can be quickly programmed .This is a development kit generated automatically from the product’s function datapoint according to Tuya Serial Port Communication Protocol. MCU engineer can develop this procedure conveniently on this basis. This article will introduce you to the specific steps of MCU development.
Schematic of gatewayless BLE single-point communication
Schematic of BLE single-point with gateway communication
The development process mainly includes: Creating products - Hardware Debugging- Software Debugging - Function Debugging.
Login Tuya Smart Developer Platform to create products. Please note that the communication type is "BLE".
Tuya BLE Standard Module includes both Non-low power and Low power mode. User can choose whether to enable the low-power function through protocol instructions.
- Non-low power mode is for products with long power supply and insensitive to power consumption.
- Low power mode is for battery-powered products with higher power consumption requirements.
After the product is created, users can select functions, panels, modules and firmware according to the actual needs of the product, and download the corresponding MCU development kit.
Creating a product is described in detail in the MCU Access Guide, so we won't go into details here.
When selecting module on the platform, the platform will recommend some common module models. After selecting the module and firmware, you can purchase module samples online.
The hardware engineer can enter the drawing board stage, and the related materials for hardware development can be viewed in the developer center:
Data manual link: BLE module datasheet;
Hardware design guidance: BLE module hardware design(not available now);
PCB data: Common module package library.
Note: When the battery is used as the power supply, when the power supply voltage is lower than the normal working voltage, the internal flash operation of the module will risk the error, causing the firmware or user data to be modified abnormally.
You can choose 2 way to rescue it: 1.When the MCU detects that the battery voltage is too low, cut off the module's power.
2.When the MCU detects that the battery voltage is too low, turn off the broadcast and system timing, put module in deep sleep mode. The minimum working voltage of Telink module is 1.8V, MCU can be set at 2.0V (slightly higher than 1.8V).
After getting the module, you don't need to write code first, first determine whether the module is working properly. Using the module debugging assistant (MCU simulation mode) provided by Tuya to cooperate with the module can perform network config operation, verify the module and be familiar with the protocol interaction process at the same time, and the development and debugging efficiency will be greatly improved later.
The framework of Tuya BLE Standard Serial Communication Protocol is shown below：
Low-power Mode Control Pin: At present, It's necessary required in Scheme of Standard Door Lock (TYBN1,BK3431Q), and it needs to be connected and used by MCU. For other standard scheme, to use the low-power mode, you must also connect the module's Low-power Control Part. If you don't need this mode, it's enough to just finish the basic connection part.
Status of Connection Notification Pin: In Low-power Mode, the GPIO will output high level when BLE connection with Mobile is successful. And when it's disconnected, the Pin will output low level.
Note: Some module does not supply this function. For details, please refer to the Low-power Mode section of the protocol document (optional, different models have different screen printing, see the datasheet for details.
Tuya MCU simulation debugging assistant, the assistant can simulate MCU data transmission and reception. Set up the minimum system of the module and connect the serial port to the computer.The assistant has the following functions: 1. Pair with a networked module and verify that the module is working properly. 2. Before the MCU completes development, debug the App panel display. 3. When the MCU developer does not know how to send and reply data to the module, the data of the simulation assistant can be used as a reference.
For more information, please refer to the Module Debugging Assistant Instruction
Module Debugging Assistant (MCU simulation mode)
step1. According to the minimum system schematic diagram, build the module peripheral circuit, simple test can fly wire directly.
step2. Open the Tuya module debugging assistant in the development kit and import the debugging file. Protocol selection BLE single point general protocol, MCU simulation mode.
step3. Connect the module serial port to the computer through the USB to TTL tool. The assistant selects the corresponding serial port and baud rate. Open the serial port and click Start. You will see that the module and the host computer automatically perform the initialization process protocol interaction.
Note： After the Bluetooth module is powered on, it will continuously send heartbeat packets. After receiving the correct response, it will perform subsequent initialization protocol interactions. If no data is sent after power on, please check if the peripheral circuit of the module is correct.
step4. Click Reset Module, the module will disconnect the BLE connection of the module, release the BLE binding relationship, clear the module's cache information, and restart the module.
During hardware debugging, you can see that the module and the MCU have a series of serial protocol interaction data. For the data analysis part, users can refer to the protocol document in the development kit. The agreement is mainly divided into two parts: the basic protocol and the functional protocol.
The basic protocol has nothing to do with the product. It is a common protocol of the module, including module initialization instructions and some extended function instructions.
The functional protocol part is mainly based on the reporting and issuing command words of the basic protocol, and details the format of the Datapoint content. The full content of the basic protocol, the document center is kept updated in real time, you can click the link to view: Tuya Cloud BLE Universal Serial Port Access Protocol(not available now).
There are two ways for the MCU to connect with the Tuya module protocol: transplant the MCU SDK or connect the protocol by yourself.
Connect protocol by yourself:
When the MCU resources are limited or the MCU SDK is not suitable for porting, customers can choose to connect the serial port protocol by themselves.
Transplant MCU SDK:
If the MCU resources are sufficient, it is generally recommended that users directly port the MCU SDK for efficient and convenient development. The MCU SDK in the development kit is a C-based protocol application code provided by Tuya, which can be directly added to the MCU project.
The MCU SDK requires MCU hardware resources: Flash 4K bytes; RAM is related to the length of the DataPoint, about 100 bytes (if OTA function is required, it must be bigger than 260 bytes); the number of function nesting levels is 9 levels. If users with insufficient resources can connect the protocol by themselves, the functions in the SDK package can still be used as a reference.
For details can see: Overview of migrating Tuya's MCU SDK.
After porting the MCU SDK code development, you can use the Tuya module debugging assistant - module simulation mode to verify the correctness of the MCU code. The usage method is similar to the MCU simulation mode. In the simulation module mode, the assistant will automatically send the initialization data stream to verify that the MCU response is correct and give corresponding prompts for the incorrect data. After the initial interaction is passed, you can manually click to test other extended functions.
Note： module simulation mode do not supply network functions, only used to verify the correctness of the MCU serial protocol transmission and reception. After the test is completed, the MCU can be connected to the actual module and test the network.
Module Debugging Assistant (Module simulation mode)
Other Debugging Common Tools Links：
Operations Center Guide：Tuya Smart Developer Platform - Operation. You can check device background log here according to your product id.
Tutorial for Tuya Support Center：Tuya provide online technical support, you can ask any questions like the question about documents here.
FAQ(not available now)：FAQ, you can read it before developing to avoid some problem.