This log will mostly talk about my STM32 programming and the control systembuilding. Our rocket electronic system is divided into two parts: the rocket controllerand the data collector. We use STM32F103RE as our rocket main rocket controllerand ATmega328 as the data collector. STM32 and ATmega328 are based on thedifferent construction and use different IDE---STM32 is based on the ARMconstruction and ATmega328 is based on the AVR construction. I use KEIL MDK U4as the programming IDE and complier of STM32 chip while I use Arduino IDE asthose of ATmega328 chip. STMf10x series chips need JLINK to burn the code onthe flash, where the chip could read and run the code when it is reset. JLINK is a necessary tool for the STM32 programming because it offers the simulationdebugger which could control and minister the running progress and the real-time memory state of the chip which we are debugging on. Technically, whatthe JLINK do is the following things: burning the HEX code into the flash through the JTAG port, leading the chip to reset and controlling the flashpointer of the chip. Such functions could also be completed by the IAP (In Application Programming). I will talk about how it works and how to realize it later. Thesensors we used are BMP8050, MPU6050 and HMC 5335, which could give us the three-axis acceleration, three-axis angular velocity, three-axis magneticdeclination and temperature. Each sensor will keep sending the real-time datathrough the IIC port to the MCU. We use ATmaga328 to be the sensor data collector while the ATmaga328 sends the data to the STM32F103 at the same time.The system is divided into two parts since I want to ensure that the reliability and the security of the main controller, which controls the parachute openingand the wireless data transmission, are not despaired by the “heavy bombardment”from various sensors. To be honest, the sensor and its collector are very easy to go “crazy”. (Maybe because one data from the sensor is mistakenly out of the setting range or the collector is missing one of the important signals, likethe ending signal, which could let it fail to packet the data.) In addition tothe data from the sensors, we also get the GPS signal as I mentioned in theprevious log. So, generously speaking, the whole system’s structure is like below.
Aswe have mentioned before, the sensors are transmitting data through the IICport. The most interesting part of the IIC port is that it can support the datatransmission of several masters and several slave devices with only one port. Eachsensor is connected to the ATmega328’s IIC port. Each slave device has oneunique address. Sensors will continue making data, but it will not send thedata to the IIC port until it got the data require that includes its ownaddress. For the master device, it will recorded a form of the address of theslave devices and it will send the data require to the slave devices one by oneso that the transmission of different slave devices will not be conflicted and influenced.After the ATmega328 collects the data and organizes them following the rule ofcertain communication agreement, it will send the data packet to STM32F103through the Serial port 2. For the STM32F103, it will use three of its serialports: the Serial port 1 for the GPS data receiving, the Serial port 2 forsensors-ATmega data receiving and the serial port 3 for wireless datatransmission to the ground station. It will also record the sensors data intothe SD card through its SPI port. Generously speaking, the STM32 chip needs todo the following things at the same time: receiving the sensor data, recordingthe sensor data, receiving the GPS data, sending the GPS data to the ground andkeeping monitoring whether the time is for the parachute opening. We shouldnotice that our chip could only do one thing at one moment, so how to make ithandle these simultaneous tasks becomes a serious problem. At first, I thoughtto so these tasks in a fixed order, which means that the chip finishes thetasks one by one. But this will cause the chip can’t run at its highest efficientsince the data “wave” of each data source is not at the same frequency or thesame rate. For instance, the inactive-and –active-time diagram of two events islike below. The active period means that during this period the data is keptsending to the MCU or the MCU is sending data to the other devices. We shouldnotice that the active periods of different data sources are overlapping.
Ifwe used the one-by-one way to collect the data, we inevitably would sometimeslose some data, may be some important data like clock timing signal that usedto control the opening of the parachute, while sometimes there is no work forthe MCU to do. At last, I got one solution. I used to treat each event with thesame weight. But soon I realize that some event is not as important as theother. For instance, sending the GPS signal back is less necessary than readingthe data transmitted from the sensor since our main purpose is to collectsensor data while GPS signal is only for the final locating of the rocket. Sowe could combine it with the interrupt mechanism in order to build a systemthat could make the important data loss become as less as possible. Morespecifically, I gave each interrupt two parts of level or priority. The firstpriority determines which to do the when two of the interrupt-active-time is overlapping. For instance, I gave the sensor reading thehigher first priority than the writing data. So when the MCU is recording theold data, if it got the sensor-reading-interrupt, it will suspend the datarecording and turn to do the data receiving. When it is done with the datareceiving, it will continue the job of data recording. The most interestingpart is that if during the time of receiving the sensor data the clock alarminginterrupt arrive, it will suspend the present interrupt and do the moreimportant work. In the other hand, if the MCU has not get any high levelinterrupts, it will not waste its time but it will do the low level interruptswhich are suspended before. And the second priority is also very important. Itworks when several same low first priority interrupts are waiting for the onehigh first priority interrupt to finish. The second priority will decide which suspendedinterrupt will begin at first. The general priority setting is like below.
This makes sure that theimportant thing is done while the calculating power of the MCU is not wasted. Anda point to notice is that the speed of recording data to the SD card or sendingdata to the ground station through the wireless device is much slower than thatof receiving data from the sensor or the GPS. So it is necessary to build someCaches which could temporally record some data that is important but has notbeen recorded or sent yet in the RAM of the STM32 chip. The code below is theexact code of the sensor data receiving interrupt.
I read something about the mechanism of the multi-task operation system and themain idea in it is also the priority. In the other word, I have realized asimple multi-task operation system. That is very exciting.