Last Updated on : 2024-08-06 08:51:28download
This topic describes how to interface an MCU with Tuya’s Zigbee module by using the MCU SDK.
Tuya provides complete solutions with network modules, mobile app, and cloud services covered. You can connect your product to the cloud simply by interfacing the MCU with Tuya’s Zigbee module through the serial protocol.
The Zigbee module features ad hoc network and low power and requires a gateway to connect to the internet.
Two types of firmware are available to Tuya’s Zigbee modules: mains-powered and battery-powered.
TYZS3 and TYZS5 are the most popular Zigbee modules.
Before starting coding, you can use Tuya’s Module Debugging Assistant in MCU simulation mode to get familiar with the communication between the MCU and the Zigbee module.
In the MCU simulation mode, the Module Debugging Assistant simulates the MCU and responds to commands from the module. After you pair the module with the mobile app, you can test whether the module can receive and send data point (DP) data correctly. The following steps describe how to pair the module and use the Module Debugging Assistant.
Set up the peripheral circuit according to the schematic for a minimum system.
Open the Module Debugging Assistant and import the debugging file. Choose Zigbee Protocol and MCU Simulation.
Connect the module to your computer by using a USB to TTL converter. Set the Serial Port and Baud Rate. Click Open and then Start Debugging to start the data communication.
If the module does not send data upon powering on, check whether the peripheral circuit of the module works as expected.
Reset the module to enter pairing mode. Pair the module with the mobile app as instructed by the guide.
To set up a Zigbee sub-device, you should have a Zigbee gateway paired with the Smart Life app. For more information, see Zigbee Pairing.
Refer to the protocol documentation in the development document to understand how data is exchanged between the MCU and the module on the Module Debugging Assistant. The protocol consists of the basic protocol and the function protocol.
Tuya provides two options to implement the communication between your MCU and Tuya’s module.
Method 1: Integrate with protocol yourself
If your MCU does not have sufficient resources or porting SDK is not feasible, you can interface with the serial protocol yourself. For more information, see Zigbee Serial Protocol.
Method 2: Port the MCU SDK
If your MCU has sufficient resources, we recommend you port the MCU SDK for efficiency purposes. The MCU SDK is written in C language. You can directly import it to your project. The requirements for MCU resources:
4 KB flash memory.
About 100 bytes of RAM are required, depending on the data length of the data point (DP). If you enable OTA updates, it must be greater than 260 bytes.
9-level nested function.
For more information, see MCU SDK Porting.
After you port the MCU SDK, you can use the module simulation mode in the Module Debugging Assistant to verify the code. In the module simulation mode, the Module Debugging Assistant automatically sends the initial data to the MCU to check whether the communication works properly. An error message will be returned if any issue occurs. After initialization, you can test different functions.
The module simulation mode only verifies the communication between the MCU and the module and does not provide real networking capability. After finishing the test, you can connect the MCU to the actual module and test pairing functionality and specific features.
After the code is verified, you can pair the module with the app and test DP data communication.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback