BLE mesh Module MCU Development Overview
Last Updated on：2020-05-09 09:03:34
On July 19, 2017, the Bluetooth Special Interest Group (SIG) announced that Bluetooth technology began to fully support Mesh mesh networks. The new Mesh technology can support equipment many-to-many transmission, and especially improves the communication efficiency of building a wide range of network coverage. Mesh technology will be more suitable for building automation, wireless sensor networks, etc.
1.Bluetooth Alliance (SIG) international standard protocol to achieve true interconnection and interoperability;
2.Low power consumption technology at microampere level;
3.Support mobile phone Bluetooth direct control and gateway remote control at the same time;
4.Local scene linkage, applied in the field of high-end lighting;
5.Suitable for commercial lighting and large-scale group control;
6.The scheme is certified by the Bluetooth Alliance;
7.Super cost-effective lighting solution;
8.Simple and easy to operate, flexible networking, high robustness, and more robust system;
9.Frequency hopping technology, not easy to be interfered with by 2.4GHz frequency communication;
1.Poor ability to process concurrent messages may cause network congestion;
2.When there is no gateway, it cannot be controlled online;
3.Weak wall performance.
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. After BLE mesh device connecting to network, it will automatically form a mesh network with other BLE mesh devices.
This article will introduce you to the specific steps of MCU development.
Schematic of gatewayless BLE mesh communication
Schematic of BLE mesh 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 mesh(SIG)".
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 mesh Standard Serial Communication Protocol is shown below：
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 mesh 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 mesh 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.
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.