STM32_SDK Quick Start

STM32_SDK quick start

Routine Download

Please check the below link to download

Routine Introduction

This routine introduces how to use the STM32Core platform to simulate the use of the IIC protocol, taking JY901S as an example, and then directly print data through serial port 1, receive sensor data and communicate with the sensor;

Before viewing this routine, please read the relevant sensor manual to understand the protocol used by the sensor and the basic functions of the sensor

How to wiring

First prepare WitMotion standard sensor, here take JY901S as an example, STM32Core development board and a serial port three-in-one module. Please the below wiring:

Physical wiring diagram:

Download the program to the development board, open the serial port debugging assistant at the same time, and power on again, it will display as follows

You can send corresponding instructions to configure the module through the prompt information.


Modules with standard protocols only need to be connected to power and serial lines, and the data will be automatically returned.

For the introduction of API functions, please read the WIT_C_SDKAPI function documentation.

Usart1Init(115200);//Initialize the print data serial port

IIC_Init();;//Initialize the IIC interface for obtaining module data

WitInit(WIT_PROTOCOL_I2C, 0x50);//Initialize the IIC protocol and set the device address

WitI2cFuncRegister(IICwriteBytes, IICreadBytes);//Register IIC read and write callback functions

WitRegisterCallBack(CopeSensorData);//Register to get the sensor data callback function

AutoScanSensor();//Automatically search for sensors

Receive data

Get data

We will create an array to store the read data into the array, and read the corresponding data directly according to the index. If the module automatically lasts data, the status data update will read the data returned by the sensor, and the final effect is to read the data of the module's 3-axis acceleration, 3-axis angular velocity, 3-axis angle, and 3-axis magnetic field into the specified index array. Finally print it out. In addition, IIC needs to actively read sensor data, so it needs to access the module at intervals.

WitReadReg(AX, 12); //Interval read sensor data

Setting sensor

The parameters of the module can be set through the function CmdProcess(); Such as acceleration calibration, magnetic field calibration and modifying baud rate etc.

Accelerometer Calibration

Some common API function interfaces are defined in the file wit_c_sdk.c, which only needs to be called.

Magnetic Cliabration

The magnetic field calibration needs to be sent to start the calibration first, then rotate around the three axes of the sensor and then end the calibration. First call WitStartMagCali(); to start magnetic field calibration, then rotate the sensor on three axes, and then call WitStopMagCali(); to end the calibration.


Please reference to the sensor datasheet

Last updated