Hi,guys!This is my first time here.This forum seems like a very active MSP430 community.Glad to find so many MSP430 lovers.
I would like to share a project I did a month ago,which is about evaluating TI's Senshub board with MSP430F5529.Well this board has lots of sensors on it,such as BMP180,MPU9150,TMP006,SHT21,ISL29023.On TI’s website there are a bunch of codes and documents about using Senshub with Tiva C board but I haven’t found any about using the board with MSP430.Also,seems like there isn’t too many people using Senshub with MSP430 on Internet.That’s why I started this project and try to make the board work with MSP430.This project is not a creative one but the code should be helpful if anyone wants to use some of the sensors with MSP430.
This post is actually my course report,so it might look a little bit formal..I hope I made my point clear.
Also,this article was actually posted on my blog first,so you can check out my blog for this article.And there are more projects on my blog but they’re not based on MSP430 so I’m not gonna post them here.I also made some improvement on this project.I tried to runs this project on freeRTOS and I’m half way there.If you want to see the current development you can check out this post here.I’ll post another thread about reading sensors through I2C on MSP430 using FreeRTOS once I’m done.
1.Introduction
In this project,a firmware was developed to acquire data from several sensors,including MPU9150,BMP180,SHT21,SIL29023,and TMP006.A simple I2C interface protocol was developed to communicate with sensors.Several filtering algorithms are applied to eliminate sensor noise,including moving average filter,median value filter,FIR lowpass filter.Device angle was calculated using atan(arc tangent)function and data fusion of gyroscope and accelerometer.An User interface consisted of switches,LEDs,and PC text output was built to evaluate different sensors and switch between low power mode and working mode.Finally all the raw sensor data and filtered data were sent to PC through UART and plotted in real-time.
2.Implementation
The block diagram of the whole system is shown in Fig.1.TI’s 16 bit microcontroller MSP430 was used here to read data from BoostXL sensor hub board and send data to PC.
Fig.1. System Diagram
Fig.2. is the flowchart of the system.The main program is a infinite loop and in each round the firmware decides which mode is chosen and then reads data from different sensors and uses different algorithm for them. Since there are too many sensors to be dealt with,they’re therefore put into three groups and user can choose which group to be working.After power on the system will go to the sensor mode 0,which evaluates the temperature sensors.If user press any button,an interrupt routine will catch the action and corresponding codes will be executed in next round.
Fig.2. System flowchart
2.1 I2C Protocol
Since MSP430 has a built-in I2C module so it’s a lot easier to communicate with sensors.However some basic I2C protocol are still needed because most sensors require some commands for initialization and a specific command sequence for reading the sensor data.Most of the sensors use the sequence described in Fig.3 as the communication protocol.
Fig.3. Sensors read and write sequence
Comparing to UART,SPI or other commonly used interface,I2C is more difficult to implement and debug.Because I2C is half duplex,which means both wires are used as receiver and transmitter and it needs an address in every transaction,so one can not perform self transmitting-receiving test in debugging.A logic analyzer with bus interpretation is then used for debugging I2C communication.
Fig.4. I2C debugging using logic analyzer
2.2 Filter Algorithm
Several filtering algorithm are used in this project,including average filter,median value filter,FIR low pass filter.An average filter is used for temperature sensors.So the result is the average value of all temperature sensors,which reduce the inaccuracy of one sensor.An median value filter is used for ambient light sensor because ISL29023 is very sensitive.The advantage of median value filter is that it can eliminate the spikes and preserve the edge information.An FIR low pass filter is used for reducing the high frequency noise in accelerometer data because accelerometer measure the acceleration force and therefore subject to vibration.
2.3 User Interface
Two buttons and LEDs are used for showing the program state.Button1 is for choosing different sensors and Button 2 is for switching between low power mode and normal working mode.Interrupt routines are used to catch the button press action.Also some codes are written so that the program change mode only after several time from last press to prevent noise or misoperation.
2.4 UART Protocol
After calculating the filtering data MSP430 sends the data to PC through UART.All the data are presented in ASCII format so sprintf function is used to convert float point data to string.Fig.5 shows MSP430 is sending the string “12345.79,”.
Fig.5. UART transmitting test
3.Result
3.1 Temperature Sensors
There are 4 temperature sensors on the PCB board.The red step curve is the data from MPU9150,which is very coarse comparing to other sensors so it’s discard before average filter calculating.Fig.6 shows all the temperature values.
Fig.6. Temperature sensor data
3.2 Humidity,Ambient Light,Air Pressure Sensors
The humidity,ambient light,and air pressure data are shown in Fig.7.The curve on the bottom is the ambient light data.We can see that there are lots of spikes as I waved my flash light to the sensors.But almost all the spikes are filtered out using median value filter.
Fig.7. Air pressure,humidity,and ambient light data
3.3 Gyroscope and Accelerometer Data Fusion
Fig.8 shows the gyroscope(red) data,accelerometer(orange) data,and device angle(black) data.As we can see the noise in angle data are largely filtered out.
Fig.8. Gyroscope,accelerometer,and device angle data
4.Conclusion
This project successfully finished all the goals.The most difficult and time consuming part in this project is the I2C communication and sensors bring-up.Besides the difficulties about I2C described in previous section,every sensor needs to be initialized,read,and wrote according to the user manuals,which took lots of time to verify and debug.
Here are the works to be done in the future.Although low power mode is used in this project but it’s only turn on by user.The power consumption can be further reduced by turning on the low power mode instead of running CPU for nothing waiting for I2C transaction to complete.The calculated device angle using gyroscope and accelerometer didn’t follow the motion quickly because a lot of time is spent on transmitting the data to PC.This can be solved by using UART transmitting complete interrupt and transmit buffer.
Check out the Git Hub code: Click me