Split from: MPU6050 init Problem

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

* Original post split off and placed in a New thread created in the correct forum. Moderator *

 * Original at http://www.avrfreaks.net/comment...

 

Hi Chris, as what I can see you are using PC4 and PC5 as SDA and SCL. However, when I looked up to Peter Fleury's library, he defined PD4 and PD5.

;*************************************************************************

#include <avr/io.h>

#undef SCL_PORT
#undef SCL_DDR

;******----- Adapt these SCA and SCL port and pin definition to your target !!
;
#define SDA             4           // SDA Port D, Pin 4
#define SCL             5           // SCL Port D, Pin 5
#define SDA_PORT        PORTD       // SDA Port D
#define SCL_PORT        PORTD       // SCL Port D         

;******----------------------------------------------------------------------

;-- map the IO register back into the IO address space
#define SDA_DDR		(_SFR_IO_ADDR(SDA_PORT) - 1)
#define SCL_DDR		(_SFR_IO_ADDR(SCL_PORT) - 1)
#define SDA_OUT		_SFR_IO_ADDR(SDA_PORT)
#define SCL_OUT		_SFR_IO_ADDR(SCL_PORT)
#define SDA_IN		(_SFR_IO_ADDR(SDA_PORT) - 2)
#define SCL_IN		(_SFR_IO_ADDR(SCL_PORT) - 2)

#ifndef __tmp_reg__
#define __tmp_reg__ 0
#endif

	.section .text

Did you make any changes of the above or somewhere else? For me, I could not build solution and the error message is " undefined reference to PORTD". Have you seen such a similar error? I'm really weak at programming. Many thanks.

Last Edited: Mon. Sep 25, 2017 - 03:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Wenyu, please indicate what device you are targeting.

David (aka frog_jr)

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

Hey Wenryu!

It depends on what device you are using. For example for me it is:

 

I think Peter's library is rather universal. I have used it successfully already, however didn't make any changes to the library itself. (in my current project after downloading it I used it as blackbox - without even looking inside).

 

However if it doesnt work for you, I'd definetely change the adresses to be adequate for the device you are using - just to test it.

Probably it is something different that is not working but if nothing comes to mind - in my opinion worth a shot!

 

Chris

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

Thank you. Chris.

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

Hi frog... The device that I am using is Xmega128 a1u. There are multiple I2C bus in the chip. Do you know how I should change the library in order to choose one of the port for my I2C bus?

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

Wenyu wrote:
The device that I am using is Xmega128

So you've hijacked a thread for a totally different device, then!

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

I am not an xmega user, but I believe you will need to change PORT, PIN & DDR references to utilize the PORT_t structure.

e.g.

PORTD.DIR = 0xAA;   \\ DDR equivalent
PORTD.OUT = 0x02;
uint8_t Input_Value = PORTD.IN;

 

David (aka frog_jr)