MPU6050 (DMP) with STM32F103 mini board

Recently I’m trying to make the MPU6050 sensor work with the STM32F103 board. Since there’s work already done by someone else to make the MPU6050(DMP) available on boards with STM32F103. First, the document for DMP in MPU6050 is not available anywhere on the internet unless you register with a company/organization email address on the invsense “developer corner” through their website (even though, the document you get is not thorough enough to implement your own HAL driver for the DMP, let alone generating the firmware for the DMP. However according to some posts I found on the internet claiming that some opensource projects have signed certain agreement with invsense to gain support for use of DMP Anyway, the example project (including eMPL driver for MPU sensors) provided through the developer corner is enough to just extract YAW, PITCH & ROLL value from the sensor (I have no idea how the values are internally calculated using Gyro and Accel measures, and how they should be used in the flight control).

By far, the YAW, PITCH and ROLL values can be correctly extracted. I use python3 matplotlib for a simple host app to plot the three values.



I tried to rotate and tap the sensor board, the readings seemed okay for me. However, I’d like to try do a visualization as in the “FreeIMU Processing Example Project”(If I remember correctly), a 3D cube to show the orientation of the board).

TODO List:

1. 3D visualization. MPU6050 read out validation

2. PWMs on STM32F103

3. SPI on STM32F103 for wireless module

4. GPS

5. TFT2.8 Display

6. …


Chinese Characters Display Problem with Google-Chrome on Opensuse (KDE)

Just found out that the problem is related to font settings. One way to work around this is to modify the font configuration file under /etc/fonts/config.d/ change the sans-serif font (49-sansserif.conf) to some other font that supports Chinese language display (simsun).

OR use YAST to add Chinese Language support directly which will install the fonts and language packs for various applications for Help Documents etc.

BabyStep 4. STM32F103ZET6 I2C Interface

BabyStep 4. USART with DMA [Delayed]

BabyStep 4. I2C Interface [Check]

Today I tried the I2C interface with the STM32 board (with the Gyro GY-521 sensor).

Well, the I2C from the STM32F103ZE end is working now, but still not able to communicate with the GY-521 sensor (I need to read the sensor’s document AGAIN!!)

Unfortunately, just when I was trying to use I2C, I found that the material provided by the seller doesn’t contain example project for I2C. And the I2C1 port resides in PORTB (Pin6 & 7 as SCL and SDA), which conflicts with the port used by the TFT touch screen I bought. I checked the schematic of the board, found no I2C2 interface connected. For now, no screen is not a big problem, but I’m a little bit disappointed.

[—————————————Added 19/12/2013——————————————————]

After contacting the seller and referring to the datasheet of the chip, there IS an I2C2 interface available, which means that the schematic view is wrong. I2C2 goes with PB.10 & PB.11, also I’ve add another USART interface @PA.2&PA.3 to interface with the GPS sensor I have.


At first, there’s no output from the two I2C pins, after debugging I found that the I2C peripheral is always busy. Google Search results suggested that:

1. No pull up resistor connected causing the SCL/SDA pulled down by some other devices, seen as the I2C peripheral.

2. I2C peripheral is not correctly reset.   (

I tried to change the GPIO mode, but with no luck.

Finally, I switched the I2C configuration and enable order. IT WORKS.

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);      // Set clock for I2C1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);   // Set clock for GPIOB
I2C_Cmd(I2C1, ENABLE); // Enable the I2C1
// RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);          // Assert Reset for the I2C1
// RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);        // Dessert Reset for the I2C1, not necessary as it seems now
I2C_Config(I2C1); // GY521 is connected to the I2C1 PB.6&7

void I2C_Config(I2C_TypeDef* I2Cx){
    GPIO_InitTypeDef GPIO_InitStructure;
    I2C_InitTypeDef I2C_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; // PB.6 & 7
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    I2C_InitStructure.I2C_ClockSpeed = 400000; // 400kHz I2C fast mode
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; //
    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; // Tlow/Thigh = 2
    I2C_InitStructure.I2C_OwnAddress1 = 0x0000; // Use as I2C Master, Doesn't Matter
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; // Enable ACK Message
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // 0x4000

    I2C_Init(I2Cx, &I2C_InitStructure);
    return ;

Then, I found this tutorial with example code for basic I2C read/write

After some helper function to read/write register value from/to GY521, I had the I2C communication working @400KHz.


This is the Waveform for a cycle of Register Read from STM32 Device.

This is the waveform of a Burst Read cycle from Arduino device with example project from I2CDev library. (This is my target for STM32)

PS. There’s a CPAL I2C Library from STM32 focusing on providing User Application level I2C API, but for now, it’s too complex for me, I reserve it as future investigation.
BS 5. PWM / Timer ? [____]


BabyStep3: PRINTF with UART [Check]

The PRINTF with UART is working now with Interrupt Handler.
Even the Interrupt Handler in this case is not so complex, however, together with the procedure for registering Interrupt Handler requires some document reading.
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
Another approach is to redirect the printf/scanf to use USART* by means of implementing fputc and fgetc as following:
int fputc(int ch, FILE *f){
	/* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(USART1, (uint8_t) ch);
  /* Loop until the end of transmission */
  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) ;
  return ch;

int fgetc(FILE *f){
	int c = 0;
	while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET) ;
	c = (int) USART_ReceiveData(USART1);
	fputc(c, f);
	return c;
1. Checking Status Flag (TC, RXNE) is still required
2. Neither TXE nor RXNE interrupt should be enabled in this way
3. scanf, printf functions are not as full-feature as standard C library function in other platforms
    e.g. with test code
int a = 0;
int b = 0;
int c = 0;
scanf("%d", &a);
scanf("%d", &b);
c = a + b;
printf("a+b = %d\r\n", c);
the output from picocom application looks like:

Step4. PWM Outputs, Timer etc [____]

Step4. USART with DMA [____]

BS2. Learning ARM STM32 Development

STEP2. Test/Modify the example project from the firmware. [Check]
Get I2C/SPI/UART working.
Well, I tried an example project for blinking the two LED lights on the board, it’s working, debug mode OKAY.
However, it’s more complicated to work with I2C/SPI/U(S)ART as pins may be shared, and the names on the PCB is not directly readable, mannual reference is needed.
I need to finish the document of the architecture of the MCU first (130 Pages :(). Meanwhile I will check if I can modify the “printf” example project to work with the USB2Serial component I have now. If yes, then next step is to make I2C work with some sensors with I2C interface I have now.
STEP3. PRINTF with UART [____]

Learning ARM STM32 development

I have had this MINISTM32 board for a long time, but never started to try some application on it.

I did try to start with ARM Cortex-M3 datasheet, but it’s very difficult to start with if the target is to get the some dummy applications running ASAP.
I also had some example projects provided by the saler, but the structures of these example projects are not easy to capture for a total beginner.
So I’m making a baby-step plan (as indicated by an online tutorial).
STEP1. Get user mannual of the MCU (which is STM32F103ZE), and the firmware from ST.   [Check]
The documents can be got from:
The firmare:
This is a firmware from ST itself, providing library (example projects) for using standard phipherals (as I’m trying to get the board interacting with some sensors I have, gyro with I2C, camera with SPI etc).
All the firmwares for STM32 MCUs are listed here:
Just in case I need firmware for SDCard, Flash, USB later etc. 
STEP2. Test/Modify the example project from the firmware. [____]
Get I2C/SPI/UART working.