Recently, a creator incentive activity was launched, so I drew a temperature and humidity meter based on HC32F120, and I spent a lot of time watching the manual. Then refer to the official reference design to complete the hardware design.Wan Sheng coreThe sample mall purchase sample welding, and share my small production on this platform. This article mainly introduces the main points of the HC32F120 design and the precautions used by the firmware library. I hope to provide some ideas for developers who want to perform domestic alternatives.Raiders.The most worth seeing is the precautions to avoid stepping on the pit.
1. Introduction to HC32F120
1.1 Features
Built -in memory: Flash Memory of 64kbyte, supporting safety protection, 4kbyte SRAM;
Low -power operation: peripheral function can be closed or turned on independently, low power consumption mode: Sleep, STOP mode;
Up to 12 -channel 12bit 1MSPS ADC, support a single/scanning transformation, support each Timer event trigger start to change;
Timer: 8 multi -function 16bit general -purpose Timer (Timerb), support input capture, output comparison, PWM output;
1 I2C, support 7 -bit/10 -bit address format;
4 USART, one of the UART supports LIN bus protocol.Support full -scale and semi -dual -workers asynchronous communication;
1 SPI, supports 16bit data width.
Second, board production
2.1 hardware design
MCU module: REGC pin connects a 0.47UF capacitor to stabilize the kernel source domain, VDD pins connect a 100NF decoupled capacitor, the reset pin is low -power, and the MD pins are connected to a 10K pull -up resistance.
Power module: Two 1.5V dry batteries are used to power the system by DC-DC boost chip HT7733.
Download and debug module: Download and debug in SWD.
Crystal module: A 20MHz non -source crystal vibration is connected to the high -speed external clock source.
Display module: Use the 0.96 -inch OLED of the IIC interface as the temperature and humidity display module.
Sensor module: Use SHT20 to collect the temperature and humidity of the environment.
2.2 proofing
2.3 Material purchase and welding real objects
Software design
3.1 IIC initialization
No need to initialize the GPIO of I2C peripherals like STM32, set the reuse function of IO through GPIO_SETFUNC, and use the CLK_FCGPERIPEROCLOCLOCLOCLOCKMD to enable the I2C clock to fill the I2C initialization structure of the I2C peripherals. Finally, I2C_CMD (EN EN Able) Make I2C peripherals.
3.2 SHT20 initialization
After sending 0xff to SHT20 after I2C, the initial 20 is completed.
3.3 debug serial port initialization
The baud rate of the initialized serial port is 115200.
3.4 Read the temperature and humidity function
Refer to the I2C routine of the DDL library of HC32F120, and write a function that reads the temperature and humidity of the SHT20.
Fourth, precautions
1. The problem encountered at first was that the I2C parameter settings were invalid. I found that the screen of OLED when I tune the Potter rate is still the same fast. The assertion in the figure below needs to be opened.You need to set the frequency division factors. After the assertion is opened, adjust the division of frequency factors according to the error of the assertion.
2. I have to use Jlink for download and prevent. I have tried Stlink and CMSIS-DAP. No, only download through Jlink.
3. The memory mapping of this chip has a segment space. The start signal generated by the i2C in the firmware library is to control the corresponding position of the corresponding register through the space. The code shown below:
4. The clock initialization function is not in the main function, but is completed by SystemInit in the startup file.