STM32_SDK Quick Start

STM32_SDK quick start

Sample Code Link

Please chceck the below to downlod.

https://github.com/WITMOTION/WitHighModbus_HWT9073485

Routine Introduction

This routine introduces how to use the serial port 2 of the STM32Core platform to connect the Witte Smart HWT9053-485 sensor, and then directly print data through the 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 Connect

First of all, prepare WitMotion HWT9053-485 sensor, a 485 to TTL transfer module, STM32Core development board and a serial port 3 in 1 adapter. Below is the wiring:

Download the program to the development board, open the serial port debugging assistant at the same time, then power on again, the following information will be displayed:

Please send corresponding instructions to configure the module through the prompt information.

Initialization

Modbus is a one-question-one-answer interactive form, so the module needs to be continuously inquired before the data can be returned

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

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

Usart2Init(9600); //Initialize the serial port connected to the module

RS485_IO_Init(); //Initialize the half-duplex 485T/R control pin

WitInit(WIT_PROTOCOL_905x_MODBUS, 0x50); //Initialize the high-precision modbus protocol and set the device address

WitSerialWriteRegister(SensorUartSend); //Registers a callback function that writes out data

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

WitDelayMsRegister(Delayms); //Register millisecond delay function

AutoScanSensor(); //Automatically search for sensors

Receiving the Sensor's Data

Acquire data

We will create an array to store the read data into the array, and read the corresponding data directly according to the index. Since the module used this time is a high-precision modbus protocol, you need to provide the data start address and the amount of data to be read when you need to ask. For example, the example calls WitReadReg(AX,16) every 300ms; the starting address is AX (acceleration X value) and continuously reads 16 data volumes, and the final effect is to read the 3D acceleration, 3D angular velocity, 3D angle, and 3D magnetic field of the module. The data into the specified index array and temperature. Finally print it out.

WitReadReg(AX, 16);//Interval reading module, the address starts from AX (acceleration X) to read 16 bytes of data. Refer to REG.H register list

Setting the 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.。

  • Open the serial port assistant, send the command B\r\n, and then observe the phenomenon

After sending B\r\n, the module will search for the device again, and prompt what baud rate is found. The window displays information prompting that the 115200 baud rate search is successful, and compares the sending instructions described in the HELP prompt information. The baud rate indicates that the setting is correct. Use other commands as needed.

Accelerometer Calibration

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

After sending a\r\n through the serial port assistant, after waiting for about 5 seconds, the X and Y axis angles will be calibrated to a state of about 0 degrees. Acceleration X, Y calibration is about 0g, Z is about 1g.

Magnetic field Calibration

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

Other

Please reference to the protocol.

Last updated