Demo video courtesy of Jack Weber. (Audio may be quiet)
For my honors project in ELEC-2220, Computer Systems, with Dr. Nelson, I collaborated with Jack Weber to design a program that would play a specific musical tone based on the direction the project board (STM32F411E-DISCO) was tilted. Jack designed the audio output, and I handled detecting the tilt of the board. I completed this project my sophomore year and wrote this not long after, but only just published it on my website.
I used the accelerometer on the built-in MEMS LSM303AGR. I used I2C communication to configure the board and read the output of the acceleration. I used the built-in I2C1 interface on the STM board to communicate with the accelerometer. Although the interface handled some things automatically, such as generating ACK signals, receiving data to the data register (DR), and sending data from the DR, I had to write several subroutines to manage communication with the accelerometer. I used information from the class textbook (Embedded Systems with ARM Cortex-M Microcontrollers in Assembly Language and C, 4th Edition by Dr. Yifeng Zhu), the STM32F411xC/E reference manual and datasheet, the LSM303AGR datasheet, the STMCubeF4 package (which contains demonstrations and drivers written in C), as well as other online resources and class slides to determine how I2C communication worked and how to communicate with the built-in accelerometer. After I had successfully implemented I2C communication with the accelerometer, I was able to write to the configuration registers to enable the accelerometer sensors and read the sensor data. Then I used the X and Y acceleration to determine the tilt of the board by comparing the values to a threshold for positive and negative tilt in the specific direction. I returned these values, which Jack processed to determine the tone to generate.
I faced some challenges when developing this project. I struggled to find and understand information about the I2C communication. I also was not sure how to implement it in assembly since every example was written in C and mainly used drivers. Although the STMCubeF4 contained drivers for I2C communication and the LSM303AGR, it took time for me to get used to navigating such a large project and reading C code. I also ran into an issue of the LSM303AGR holding SDA low. This most often occurred if the program was quit in the middle of I2C communication (which often happened as I was developing the communication subroutines). This made debugging slow as I was unable to find a workaround for this. However, I eventually discovered the cause and that unplugging the board for 60 seconds would reset the LSM303AGR.
Overall, this project was a great experience. I enjoyed collaborating with Jack and overcoming challenges. Implementing I2C on such a low level has taught me a lot about the communication standard. The end result is very cool and works well.