0
\$\begingroup\$

I need help with this piece of code. I don't know what I did wrong, or what I'm missing. It is a simple program to interface the stm32f103c8t6 with a gy-521 (the MPU6050 on it), I was able to get it working when I used the ESP8266 and arduino, but now I'm using keil uvision with the STM and I don't know why it's not working.

Here is the full code: http://codepad.org/fMh3m2JC

These are the libraries I used

enter image description here

I set up a debugging process to monitor what the problem is and I discovered that it gets stuck in the while loop on line 123, everything works fine up to this point.

enter image description here

The while loop lets the MCU waits for the I2C_EVENT_MASTER_BYTE_RECEIVED event, this event is simply a mask for the BUSY, MSL and RXNE flags.

I monitored the i2c interface window as I stepped through the code then I realised that the MSL and RXNE were not set at this point which means the MCU is in slave mode and the data register is still empty, the ARLO bit is set which I think it shouldn't be at this point.

enter image description here

Anyway, all these are just my hypothesis based on my limited knowledge and experience. The problem may not be related to these things, I just want someone to take a look at the code and tell me what I'm doing wrong. Thanks.

PS: I also notice that the onboard LED refuses to flash, is it because of the i2c communication?

\$\endgroup\$
  • \$\begingroup\$ Why aren't you using your i2c_receive_nack() function? You're trying to do I2C_CheckEvent without actually initiating a receive operation first, and then after that your comment says "Nack and stop", but you're not doing a Nack, just a stop. \$\endgroup\$ – brhans Apr 25 at 0:57
  • \$\begingroup\$ Were you doing the software debugging or hardware debugging i.e using ST Link or JTAG? \$\endgroup\$ – MaNyYaCk Apr 25 at 13:21
  • \$\begingroup\$ brhans, the contents of the i2c_receive_nack() is what I have between line 116 and 121, I did that just to be able to monitor the content of that function (jumping to and from the function just felt like a pain in the ass). I put the "//Nack and stop" comment when I had it as a function initially. So, in line 113 the MCU listens to the slave to receive the data, in line 116 the master ack is didabled, in line 119 the MCU waits until the data is received (which never happened), I also noticed that the green LED on the MPU6050 goes dim at this point (is this supposed to mean something?) \$\endgroup\$ – Olawaiye Clifford Apr 25 at 14:07
  • \$\begingroup\$ MaNyYaCk, I was doing software debugging with keil debugger, I only have the "st-link v2 mini" which I think does not support SWO.. But the software debugging has been working well enough (for my previous projects) \$\endgroup\$ – Olawaiye Clifford Apr 25 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.