Using STM32F103C8T6 as the main control, the price is relatively cheap, and there is a lot of relevant information online. I have used Punctual Atom's battleship development board before, and I am familiar with STM32f1 series programming.
Send control instructions through the Internet of Things module EM3080 to control the relay switch, and at the same time obtain the temperature and humidity sensor values and display them on the app.
The onboard OLED display simultaneously displays temperature and humidity data and relevant prompt information during operation.
Temperature and humidity sensor model: DHT11, one module can obtain temperature and humidity data, reducing component usage and CPU resource usage
Other parts are basically the same as Lichuang’s source solution.
Debugging process:
**1.** Welding part
First weld the minimum system of the microcontroller and the power supply part of the board to test whether the program can be downloaded normally.
Encounter problems :
(1) After welding this part, a short circuit was found between 3.3V_MCU and GND. The pins related to the power supply and ground of the microcontroller were checked and there was no short circuit. Finally, it was found that the problem was with the crystal oscillator used. The crystal oscillator is a 5*7mm SMD package 32.768 The Mhz active crystal oscillator is shown in the figure below. Using too much tin during soldering causes the 3.3V pin and the GND pin to be connected to the metal part of the top cover of the crystal oscillator at the same time. After removing the excess tin, measure again and there is no short circuit.
(2) After confirming that there is no short circuit, power on and test. The point source indicator light does not light up. There is no heat when touching the microcontroller, but the 32.768Mhz crystal oscillator is seriously hot. It has been confirmed that the VCC and GND of the crystal oscillator are not short-circuited. After repeated inspections, we found that the solder entered the inside of the crystal oscillator along the edge of the top cover, which may cause an internal short circuit of the crystal oscillator and cause the crystal oscillator to die. tear down. Since the STM32F1 clock source can be the internal RC oscillator circuit or an external crystal oscillator. Therefore, the board uses an 8Mhz crystal oscillator alone, and the 32.768Mhz is not soldered for the time being.
(3) Download the flashing LED test program. Since only one LED was welded at the beginning, and coincidentally, this LED was connected to the PB4 pin. After downloading the program, there was no response. I thought it was a board problem, so I struggled for a long time. I accidentally saw on Baidu that PB3, PB4, PA13, PA14, and PA15 are special IO ports used as debugging interfaces for the JTAG/SWD emulator. Among them, PA13 and PA14 are used as SWIO and SWCLK for SWD debugging respectively; PB3, PB4, PA13, PA14 and PA15 are jointly used for JTAG. These five IO pins are very special. Normally they are used as debugging pins of the SWJ emulator. If they are to be used as ordinary IO ports, special configuration is required. Different I/O usage requirements and configurations are also different, as follows:
l GPIO_Remap_SWJ_JTAGDisable : / !< JTAG-DP Disabled and SW-DP Enabled / That is, PB3, PB4, PA15 can be used for normal IO, and PA13&14 can be used for SWD debugging
l GPIO_Remap_SWJ_Disable : / !< Full SWJ Disabled (JTAG-DP + SW-DP) / All 5 pins are ordinary pins, but they can no longer be debugged with the JTAG&SWD emulator and can only be debugged with st-link.
l GPIO_Remap_SWJ_NoJTRST : / !< Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST /PB4 can be an ordinary IO port, JTAG&SWD is used normally, but JTAG is not reset
If you use all five pins as ordinary IO ports, then the remapping configuration in step 2 above should be written as GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE); if you use PB3, PB4, PA15 as ordinary IO, PA13&14 are used for SWD For debugging, the remapping configuration should be written as GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); In the same way, only PB4 can be configured as a normal IO port.
PA13&14 is used in the project for SWD debugging, and the others are used as ordinary I/O, so GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE) is used;
After the flashing LED program test is successful, all remaining components must be welded.
**2.**Software part
(1) When transplanting Song Gong's program to STM32, the modules should be tested separately when testing the program. Otherwise, it is impossible to determine which part of the program has a problem.
First test the DHT11 and display the temperature and humidity on the OLED. This part is displayed normally after following the above remapping operation.
When testing the sending and receiving of serial port 2, it was found that there was no response in the sending and receiving of serial port 2. At first, I thought it was a problem with the string sending function, so I made changes according to the methods on the Internet.
method 1:
const u8 TEXT_Buffer[]={"AT"};
for(i=0;i<sizeof(TEXT_Buffer);i++)
{
USART2->DR =TEXT_Buffer[i];
delay_ms(10);
}
Method 2:
void Send_Str1(char *s)
{
while(*s)
{
USART_SendData(USART1,*s++);//Serial port 1 sends data function, library function has been provided}
while(*s)
{
while(!USART_GetITStatus(USART1, USART_FLAG_TXE)); //Determine whether it can be sent
USART_SendData(USART1,*s);
while(USART_GetITStatus(USART1, USART_IT_TC)); //To determine whether the sending is completed, this sentence must be included, otherwise it will cause //only the last character to be sent (overwrite)
s++;
}
}
After the change, the test still had no response. After careful inspection of the program analysis, it was found that USART2 was mounted under the APB1 bus, and the clock enable part of the program was written incorrectly.
(2) 3080 module test, use USB to serial port module to directly connect the 3080 module, use Geshe FiberHome serial port assistant to test AT commands, the test results are as follows:
After successfully entering the router's network configuration mode, I used the Cloud Intelligence APP to scan the network configuration QR code, but the network configuration failed. Later, I changed the network configuration method of Alibaba Cloud equipment to one-click network configuration. The debugging was normal again and the network configuration was successful. (3) Problems with cloud command issuance and device data reporting. Note: Data reporting command format: AT+ILOPSENDJSON=property,{"temputure:",28}. When using serial port 2 to send commands to the 3080 module, use the method of operating the DR register Method, cache the data to be sent in the array in advance, and send the data bit by bit through a loop. Here, pay attention to whether all the cached data is sent. You can first use the serial port assistant to debug, confirm that the sent data is correct, and then modify the program to send it to the 3080 module.
The cloud command is issued to control the relay. Let's be lazy here and directly judge the received string to see if it contains the powerstate:0 substring. If so, open the relay. This place will be optimized later.
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