I2C (TWI) Atmega1284P MPU9150

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I’m trying to use the I2C(TWI) protocol to get some data from The GY-5150 (HCMODU0064) which is a breakout module for the MPU-9150 9DOF (Acc, Gyros, Compass) using an Atmega1284P

I’m using the Fleury’s Libray:

i2cmaster.h

twimaster.c

I omitted the file “i2cmaster.S” since when I try to compile the solution with this file included; I got an error message stating “functions redefinition”

I’m using as well a library (MPU9150.h) from the 9DOF supplier containing some routines that I tried to adapt from Arduino to Atmega

and an LCD library to display the results (TFTLCD3.h)

The problem is that I do not get any sensor reading on the screen and it seems that the processor gets stuck in some loop.

Did I miss something? Any help please?

Set ups Fcpu=16Mhz , Fscl=400Khz

Attachment(s): 

This topic has a solution.
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Life is much easier if you stick to conventions.  e.g. declarations in .H files.  code in .C files.

 

Fleury uses 8-bit addressing.   e.g. 0xD0/0xD1 for the W/R addresses of your chip.

 

So you would be writing things like:

  ret = i2c_start((I2CACCGYROADD<<1) + I2C_WRITE); 

I always avoid i2c_start_wait().     It just hangs if you have an error (like wrong I2C address or missing chip)

If you use the return values from Fleury (or any other respected library),   you can see immediately where your problems lie.

 

But as a general strategy:

1.   buy a UNO

2.   test any new hardware with Arduino sketches.

3.   you may need to run your Arduino at 3.3V for some hardware modules.

4.   a Seeeduino is switchable between 3.3V and 5V

 

Having tested / prototyped your project on the Arduino,   it is relatively easy to re-write in C or C++ or any other language.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you David....It worked....

 

Concerning the UNO....How much time It will take me to adapt to the Arduino syntax and Envirnment? Because this is what really disuades me each time I think in doing so

 

Thank you another time for your help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Arduino syntax and environment are really easy to pick up.

 

Most bits of hardware have got dedicated libraries and specific examples.

So it is easy to evaluate whether a particular chip is suitable or to build a prototype.

 

The libraries come with source code.     You don't need to understand it before using the methods().

However,   if you want to write your own 'equivalent' functions in another language,     it is useful to see how the 'Arduino implementation' was written.

 

There is a very big difference between reading Shakespeare and writing Shakespeare !

 

Believe me.     An ASM programmer can read a C program.     A C programmer can read a C++ program.     Anyone can read an ASM program.     (They might get a headache when they try to keep all the details in perspective)

 

The other advantage of Arduino is that the whole world has the same hardware.     You can get assistance with any problems.

 

David.