Yesterday, I had a chance to join in the “National junior solar sprint” organized by Singapore Polytechnic for secondary students in Singapore. The theme of the competition is “Sun seeker”, which is actually a small solar car race. The competition was held with purpose to create a playground for students to apply their knowledge and creation into a real thing.
In the previous post, an example of using STM32 DMA to perform a simple data copy between 2 arrays was introduced. Now, I will show another example with DMA and I2C to read raw data from MPU6050 acceleration and gyroscope sensor directly. Besides, a comparison to show timing difference between using and not using DMA is also mentioned.
In many microcontroller applications, you may need to read and write data from and to outside devices through I2C, SPI, USART or ADC… peripherals. When you do this using processor – you will waste a significant amount of processing time, especially for some applications that require transferring a huge data. In order to avoid occupying CPU, most advanced microcontrollers nowadays have Direct memory Access (DMA) unit. This unit does data transfers between memory locations without the need of CPU processing. In this post, I will take STM32 DMA as an example to show the advantages of using DMA over normal transferring method.