This project is a very simple application. It is mainly used for converting I2C to RS485. It is a sensor conversion module. This project is to digitize the I2C signal of the temperature, humidity and air pressure sensor and output the RS485 signal to facilitate the integrated development of other instruments.
name | Measuring range | Accuracy | Accuracy | unit |
---|---|---|---|---|
Temperature Sensor | -40~85 | 0.1 | ±0.5 | ℃ |
Humidity Sensor | 0-100 | 0.1 | ±5% | %RH |
barometric pressure sensor | 300-1100 | 1 | ±0.2 | hPa |
In this case, as a simple application, the chip must have one I2C, one UART, and at least 1 byte of EEPROM. The chip I chose here is the domestic Hangshun chip, HK32F030MF4P6. The chip has a built-in crystal oscillator, so many peripheral devices can be omitted.
In order to be compatible with more systems, the power supply is designed to be powered by 5-18V. Considering that the high voltage drop will cause the LDO step-down chip to overheat, a DC-DC chip + LDO step-down chip is used here, and the input is transferred through the switching power supply chip. The VCC is converted to 5V, and then converted to 3.3V by the LDO power chip as the main power supply of the chip. The voltage is reduced to DC3.3V in two steps. (Actually measured 4.0-18.5V is available). **Note:** I have omitted the capacitor of the VIN part of HK7533 here, because in the PCB layout, I introduced it directly from the 5V voltage capacitor of the front stage, which is very close. Therefore, a 10uF capacitor is omitted at VIN. Please be careful to add it if you transplant it later.
The reason I highlight here is that some RS485 chips do not support 3.3V power supply (some are 5V power supply). If you transplant, please pay attention to the voltage issue.
If you search for "louver temperature and humidity sensor housing" on Taobao, you can quickly find a housing similar to the author's. Plan the PCB according to the internal dimensions of the housing.
The temperature, humidity and air pressure sensors should be placed as close to the side as possible, and a tiny fan can be added if conditions permit. The sensor should be kept away from internal heating components (such as power chips, power modules, buck chips, etc.). The case is placed in the corner. Designed with 4 wires (pin and female positions), you can also break the board and connect it with wires to completely isolate the PCB from heat conduction.
1. There are various methods. Currently, the author uses the "teppanyaki" method. First, apply solder paste, stick it on, and then heat it with a "whirter".
2. After completing the power-on test, first use a multimeter to check whether VCC (5V3.3VUSB) and GND are short-circuited. Make sure before plugging in. Do not plug in if there is a short circuit.
Because RS485 involves hardware address issues and requires a power-saving function, eeprom reading and writing is added to the program to save the address after power failure.
#include "eeprom.h"
uint8_t EEPROM_WriteByte(uint32_t address, uint8_t data_in)//写EEPROM
{
if(HK32F030M_EE_SIZE <= address)
{
return 0;
}
FLASH_Unlock();
EEPROM_EraseByte(address+HK32F030M_EE_BEGIN);
EEPROM_ProgramByte(address+HK32F030M_EE_BEGIN, data_in);
FLASH_Lock();
if((*(uint8_t *)(address+HK32F030M_EE_BEGIN)) != data_in)
{
return 0;
}
return 1;
}
uint8_t EEPROM_ReadByte(uint32_t address,uint8_t *data_out)//读EEPROM
{
if(HK32F030M_EE_SIZE <= address)
{
return 0;
}
*data_out = (*((uint8_t *)(address + HK32F030M_EE_BEGIN)));
return 1;
}
The RS485 chip needs to control input and output, which is half-duplex. When coding, GPIO must be used as output high and low levels for control. The code snippet is as follows
void RS485_CTRL_TX(void)
{
GPIOC->BSRR = GPIO_Pin_3; //IO口置为3.3v
}
void RS485_CTRL_RX(void)
{
GPIOC->BRR = GPIO_Pin_3; //IO置为0v
}
I found an abandoned shutter box in the corner of the warehouse and assembled it. The two pads drawn on the PCB were just used to weld on the copper pillars, and the copper pillars were fixed on the shutters. As shown below:
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet