• AVR Freaks

Hot!MPU6050 with PIC18F4550 (I²C)

Author
du.facc
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2014/02/01 11:09:01
  • Location: 0
  • Status: offline
2014/02/28 11:35:36 (permalink)
0

MPU6050 with PIC18F4550 (I²C)

Hi all, my name is Eduardo, i need to read that sensor MPU6050 for a final project for my college.
 
I found on web a library for it, but i cant compile with MPLABX. I think the problem is that library with my actually library for I²C
 
This is my mpu library :
 

 

#include <plib\i2c.h>
#ifdef USE_MPU6050_SOFT_I2C
 #define MPU6050_I2C_Wr Soft_I2C_Write
 #define MPU6050_I2C_Rd Soft_I2C_Read
 #define MPU6050_I2C_Stop Soft_I2C_Stop
 #define MPU6050_I2C_Start Soft_I2C_Start
 #define MPU6050_Scl Soft_I2C_Scl
 #define MPU6050_Sda Soft_I2C_Sda
 #define MPU6050_Scl_Direction Soft_I2C_Scl_Direction
 #define MPU6050_Sda_Direction Soft_I2C_Sda_Direction
#else
 #define MPU6050_I2C_Wr I2C1_Wr
 #define MPU6050_I2C_Rd I2C1_Rd
 #define MPU6050_I2C_Stop StopI2C1
 #define MPU6050_I2C_Start StartI2C
#endif
#define MPU6050_ADDRESS   0xD0
#define MPU6050_RA_XG_OFFS_TC       0x00 
#define MPU6050_RA_YG_OFFS_TC       0x01 
#define MPU6050_RA_ZG_OFFS_TC       0x02 
#define MPU6050_RA_X_FINE_GAIN      0x03 
#define MPU6050_RA_Y_FINE_GAIN      0x04 
#define MPU6050_RA_Z_FINE_GAIN      0x05 
#define MPU6050_RA_XA_OFFS_H        0x06 
#define MPU6050_RA_XA_OFFS_L_TC     0x07
#define MPU6050_RA_YA_OFFS_H        0x08 
#define MPU6050_RA_YA_OFFS_L_TC     0x09
#define MPU6050_RA_ZA_OFFS_H        0x0A 
#define MPU6050_RA_ZA_OFFS_L_TC     0x0B
#define MPU6050_RA_XG_OFFS_USRH     0x13 
#define MPU6050_RA_XG_OFFS_USRL     0x14
#define MPU6050_RA_YG_OFFS_USRH     0x15 
#define MPU6050_RA_YG_OFFS_USRL     0x16
#define MPU6050_RA_ZG_OFFS_USRH     0x17 
#define MPU6050_RA_ZG_OFFS_USRL     0x18
#define MPU6050_RA_SMPLRT_DIV       0x19
#define MPU6050_RA_CONFIG           0x1A
#define MPU6050_RA_GYRO_CONFIG      0x1B
#define MPU6050_RA_ACCEL_CONFIG     0x1C
#define MPU6050_RA_FF_THR           0x1D
#define MPU6050_RA_FF_DUR           0x1E
#define MPU6050_RA_MOT_THR          0x1F
#define MPU6050_RA_MOT_DUR          0x20
#define MPU6050_RA_ZRMOT_THR        0x21
#define MPU6050_RA_ZRMOT_DUR        0x22
#define MPU6050_RA_FIFO_EN          0x23
#define MPU6050_RA_I2C_MST_CTRL     0x24
#define MPU6050_RA_I2C_SLV0_ADDR    0x25
#define MPU6050_RA_I2C_SLV0_REG     0x26
#define MPU6050_RA_I2C_SLV0_CTRL    0x27
#define MPU6050_RA_I2C_SLV1_ADDR    0x28
#define MPU6050_RA_I2C_SLV1_REG     0x29
#define MPU6050_RA_I2C_SLV1_CTRL    0x2A
#define MPU6050_RA_I2C_SLV2_ADDR    0x2B
#define MPU6050_RA_I2C_SLV2_REG     0x2C
#define MPU6050_RA_I2C_SLV2_CTRL    0x2D
#define MPU6050_RA_I2C_SLV3_ADDR    0x2E
#define MPU6050_RA_I2C_SLV3_REG     0x2F
#define MPU6050_RA_I2C_SLV3_CTRL    0x30
#define MPU6050_RA_I2C_SLV4_ADDR    0x31
#define MPU6050_RA_I2C_SLV4_REG     0x32
#define MPU6050_RA_I2C_SLV4_DO      0x33
#define MPU6050_RA_I2C_SLV4_CTRL    0x34
#define MPU6050_RA_I2C_SLV4_DI      0x35
#define MPU6050_RA_I2C_MST_STATUS   0x36
#define MPU6050_RA_INT_PIN_CFG      0x37
#define MPU6050_RA_INT_ENABLE       0x38
#define MPU6050_RA_DMP_INT_STATUS   0x39
#define MPU6050_RA_INT_STATUS       0x3A
#define MPU6050_RA_ACCEL_XOUT_H     0x3B
#define MPU6050_RA_ACCEL_XOUT_L     0x3C
#define MPU6050_RA_ACCEL_YOUT_H     0x3D
#define MPU6050_RA_ACCEL_YOUT_L     0x3E
#define MPU6050_RA_ACCEL_ZOUT_H     0x3F
#define MPU6050_RA_ACCEL_ZOUT_L     0x40
#define MPU6050_RA_TEMP_OUT_H       0x41
#define MPU6050_RA_TEMP_OUT_L       0x42
#define MPU6050_RA_GYRO_XOUT_H      0x43
#define MPU6050_RA_GYRO_XOUT_L      0x44
#define MPU6050_RA_GYRO_YOUT_H      0x45
#define MPU6050_RA_GYRO_YOUT_L      0x46
#define MPU6050_RA_GYRO_ZOUT_H      0x47
#define MPU6050_RA_GYRO_ZOUT_L      0x48
#define MPU6050_RA_EXT_SENS_DATA_00 0x49
#define MPU6050_RA_EXT_SENS_DATA_01 0x4A
#define MPU6050_RA_EXT_SENS_DATA_02 0x4B
#define MPU6050_RA_EXT_SENS_DATA_03 0x4C
#define MPU6050_RA_EXT_SENS_DATA_04 0x4D
#define MPU6050_RA_EXT_SENS_DATA_05 0x4E
#define MPU6050_RA_EXT_SENS_DATA_06 0x4F
#define MPU6050_RA_EXT_SENS_DATA_07 0x50
#define MPU6050_RA_EXT_SENS_DATA_08 0x51
#define MPU6050_RA_EXT_SENS_DATA_09 0x52
#define MPU6050_RA_EXT_SENS_DATA_10 0x53
#define MPU6050_RA_EXT_SENS_DATA_11 0x54
#define MPU6050_RA_EXT_SENS_DATA_12 0x55
#define MPU6050_RA_EXT_SENS_DATA_13 0x56
#define MPU6050_RA_EXT_SENS_DATA_14 0x57
#define MPU6050_RA_EXT_SENS_DATA_15 0x58
#define MPU6050_RA_EXT_SENS_DATA_16 0x59
#define MPU6050_RA_EXT_SENS_DATA_17 0x5A
#define MPU6050_RA_EXT_SENS_DATA_18 0x5B
#define MPU6050_RA_EXT_SENS_DATA_19 0x5C
#define MPU6050_RA_EXT_SENS_DATA_20 0x5D
#define MPU6050_RA_EXT_SENS_DATA_21 0x5E
#define MPU6050_RA_EXT_SENS_DATA_22 0x5F
#define MPU6050_RA_EXT_SENS_DATA_23 0x60
#define MPU6050_RA_MOT_DETECT_STATUS    0x61
#define MPU6050_RA_I2C_SLV0_DO      0x63
#define MPU6050_RA_I2C_SLV1_DO      0x64
#define MPU6050_RA_I2C_SLV2_DO      0x65
#define MPU6050_RA_I2C_SLV3_DO      0x66
#define MPU6050_RA_I2C_MST_DELAY_CTRL   0x67
#define MPU6050_RA_SIGNAL_PATH_RESET    0x68
#define MPU6050_RA_MOT_DETECT_CTRL      0x69
#define MPU6050_RA_USER_CTRL        0x6A
#define MPU6050_RA_PWR_MGMT_1       0x6B
#define MPU6050_RA_PWR_MGMT_2       0x6C
#define MPU6050_RA_BANK_SEL         0x6D
#define MPU6050_RA_MEM_START_ADDR   0x6E
#define MPU6050_RA_MEM_R_W          0x6F
#define MPU6050_RA_DMP_CFG_1        0x70
#define MPU6050_RA_DMP_CFG_2        0x71
#define MPU6050_RA_FIFO_COUNTH      0x72
#define MPU6050_RA_FIFO_COUNTL      0x73
#define MPU6050_RA_FIFO_R_W         0x74
#define MPU6050_RA_WHO_AM_I         0x75
typedef struct
{
 struct
 {
  signed int X;
  signed int Y;
  signed int Z;
 }Accel;
 signed int Temperatura;
 struct
 {
  signed int X;
  signed int Y;
  signed int Z;
 }Gyro;
}MPU6050;
void MPU6050_Init()
{
 MPU6050_I2C_Start();
 MPU6050_I2C_Wr( MPU6050_ADDRESS );
 MPU6050_I2C_Wr( MPU6050_RA_PWR_MGMT_1 );
 MPU6050_I2C_Wr( 2 ); //Sleep OFF
 MPU6050_I2C_Wr( 0 ); 
 MPU6050_I2C_Stop();
  MPU6050_I2C1_Stop();
 MPU6050_I2C_Start();
 MPU6050_I2C_Wr( MPU6050_ADDRESS );
 MPU6050_I2C_Wr( MPU6050_RA_GYRO_CONFIG );
 MPU6050_I2C_Wr( 0 ); //gyro_config, +-250 °/s
 MPU6050_I2C_Wr( 0 ); //accel_config +-2g
 MPU6050_I2C_Stop();
  MPU6050_I2C1_Stop();
}
void MPU6050_Read( MPU6050 *Sensor )
{
 MPU6050_I2C_Start();
 MPU6050_I2C_Wr( MPU6050_ADDRESS );
 MPU6050_I2C_Wr( MPU6050_RA_ACCEL_XOUT_H );
 MPU6050_I2C_Start();
 MPU6050_I2C_Wr( MPU6050_ADDRESS | 1 );
 Sensor->Accel.X = ( MPU6050_I2C_Rd(1) << 8 ) | MPU6050_I2C_Rd(1);
 Sensor->Accel.Y = ( MPU6050_I2C_Rd(1) << 8 ) | MPU6050_I2C_Rd(1);
 Sensor->Accel.Z = ( MPU6050_I2C_Rd(1) << 8 ) | MPU6050_I2C_Rd(1);
 Sensor->Temperatura = ( MPU6050_I2C_Rd(1) << 8 ) | MPU6050_I2C_Rd(1);
 Sensor->Gyro.X = ( MPU6050_I2C_Rd(1) << 8 ) | MPU6050_I2C_Rd(1);
 Sensor->Gyro.Y = ( MPU6050_I2C_Rd(1) << 8 ) | MPU6050_I2C_Rd(1);
 Sensor->Gyro.Z = ( MPU6050_I2C_Rd(1) << 8 ) | MPU6050_I2C_Rd(0);
 MPU6050_I2C_Stop();
 Sensor->Temperatura += 12421;
 Sensor->Temperatura /= 340;
}
 

 
And this is my I²C lib:
 

#ifndef __I2C_H
#define __I2C_H
/******************************************************************************
 // *                   I2C PERIPHERAL LIBRARY HEADER FILE
 ******************************************************************************
 * FileName:         i2c.h
 * Dependencies:     See include below
 * Processor:       PIC18
 * Compiler:         MCC18
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 * The software supplied herewith by Microchip Technology Incorporated
 * (the “Company”) for its PICmicro® Microcontroller is intended and
 * supplied to you, the Company’s customer, for use solely and
 * exclusively on Microchip PICmicro Microcontroller products. The
 * software is owned by the Company and/or its supplier, and is
 * protected under applicable copyright laws. All rights are reserved.
 * Any use in violation of the foregoing restrictions may subject the
 * user to criminal sanctions under applicable laws, as well as to
 * civil liability for the breach of the terms and conditions of this
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *****************************************************************************/
 
#include "pconfig.h"
/* SSPCON1 REGISTER */
#define   SSPENB     0b00100000   /* Enable serial port and configures SCK, SDO, SDI*/
#define   SLAVE_7   0b00000110     /* I2C Slave mode, 7-bit address*/
#define   SLAVE_10   0b00000111     /* I2C Slave mode, 10-bit address*/
#define   MASTER     0b00001000     /* I2C Master mode */
#define   MASTER_FIRMW 0b00001011 //I2C Firmware Controlled Master mode (slave Idle)
#define   SLAVE_7_STSP_INT 0b00001110 //I2C Slave mode, 7-bit address with Start and Stop bit interrupts enabled
#define   SLAVE_10_STSP_INT 0b00001111 //I2C Slave mode, 10-bit address with Start and Stop bit interrupts enabled
/* SSPSTAT REGISTER */
#define   SLEW_OFF   0b10000000   /* Slew rate disabled for 100kHz mode */
#define   SLEW_ON   0b00000000   /* Slew rate enabled for 400kHz mode  */
#if defined (I2C_V2) || defined (I2C_V3) || defined (I2C_V5) || defined (I2C_V6) || defined (I2C_V6_1) || defined (I2C_V6_2)/* These versions have MSSP1 */
/* ***** I2C1 ***** */
/***********************************************************************************
Macro       : EnableIntI2C1
Include     : i2c.h
Description : Macro enables I2C  Interrupt
 
Arguments   : None
 
Remarks     : None
***********************************************************************************/
#define EnableIntI2C1                   (PIE1bits.SSP1IE = 1)
/***********************************************************************************
Macro       : DisableIntI2C1
Include     : i2c.h
Description : Macro disables I2C  Interrupt
 
Arguments   : None
 
Remarks     : None
***********************************************************************************/
#define DisableIntI2C1                   (PIE1bits.SSP1IE = 0)
/***********************************************************************************
Macro       : SetPriorityIntI2C1(priority)
 
Include     : i2c.h
 
Description : Macro sets the priority level for I2C interrupt
 
Arguments   : priority - This input parameter is the level of interrupt priority.
* 0 -- Low priority (Default Value)
* 1 -- High Priority
 Remarks     : None
***********************************************************************************/
#define SetPriorityIntI2C1(priority)     (IPR1bits.SSP1IP = priority)
/*******************************************************************
Macro       : I2C1_Clear_Intr_Status_Bit
Include     : i2c.h
Description : Macro to Clear I2C  Interrupt Status bit
Arguments   : None
Remarks     : None
*******************************************************************/
#define I2C1_Clear_Intr_Status_Bit     (PIR1bits.SSP1IF = 0)
/*******************************************************************
Macro       : I2C1_Intr_Status
Include     : i2c.h 
Description : Macro to return I2C Interrupt Status
Arguments   : None
Remarks     : None
*******************************************************************/
#define I2C1_Intr_Status PIR1bits.SSP1IF
/*******************************************************************
Macro       : StopI2C1()
Include     : i2c.h
Description : Macro to initiate stop condition
Arguments   : None
Remarks     : This macro initiates stop condition and waits till the stop signal
sequence is terminated.This macro is applicable only to master
*******************************************************************/
#define StopI2C1()  SSP1CON2bits.PEN=1;while(SSP1CON2bits.PEN)
#define StopI2C StopI2C1
/*******************************************************************
Macro       : StartI2C1()
Include     : i2c.h
Description : Macro to initiate start condition
Arguments   : None
Remarks     : This macro initiates start condition and waits till the start signal
sequence is terminated. This macro is applicable only to master
*******************************************************************/
#define StartI2C1()  SSP1CON2bits.SEN=1;while(SSP1CON2bits.SEN)
#define StartI2C StartI2C1 
/*******************************************************************
Macro       : RestartI2C1()
Include     : i2c.h
Description : Macro to initiate Restart condition
Arguments   : None
Remarks     : This macro initiates Restart condition and waits till the Restart signal
sequence is terminated. This macro is applicable only to master
*******************************************************************/
#define RestartI2C1()  SSP1CON2bits.RSEN=1;while(SSP1CON2bits.RSEN)
#define RestartI2C RestartI2C1
/*******************************************************************
Macro       : NotAckI2C1()
Include     : i2c.h
Description : Macro to initiate negetive acknowledgement sequence
Arguments   : None
Remarks     : This macro initiates negetive acknowledgement condition and 
waits till the acknowledgement sequence is terminated.
This macro is applicable only to master
*******************************************************************/
#define NotAckI2C1()     SSP1CON2bits.ACKDT=1, SSP1CON2bits.ACKEN=1;while(SSP1CON2bits.ACKEN)
#define NotAckI2C NotAckI2C1
/*******************************************************************
Macro       : AckI2C1()
Include     : i2c.h
Description : Macro to initiate positive acknowledgement sequence
Arguments   : None
Remarks     : This macro initiates positive acknowledgement condition and 
waits till the acknowledgement sequence is terminated.
This macro is applicable only to master
*******************************************************************/
#define AckI2C1()        SSP1CON2bits.ACKDT=0, SSP1CON2bits.ACKEN=1;while(SSP1CON2bits.ACKEN)
#define AckI2C AckI2C1
/**********************************************************************************************
Macro :  IdleI2C1() 
Include            : i2c.h 
Description        : This Macro generates Wait condition until I2C bus is Idle.
Arguments          : None 
Remarks            : This Macro will be in a wait state until Start Condition Enable bit,
                     Stop Condition Enable bit, Receive Enable bit, Acknowledge Sequence
                     Enable bit of I2C Control register and Transmit Status bit I2C Status
                     register are clear. The IdleI2C function is required since the hardware
                     I2C peripheral does not allow for spooling of bus sequence. The I2C
                     peripheral must be in Idle state before an I2C operation can be initiated
                     or write collision will be generated.
***********************************************************************************************/
#if defined (I2C_V2) || defined (I2C_V3) || defined (I2C_V5) || defined (I2C_V6) || defined (I2C_V6_1)
#define IdleI2C1()    while ((SSP1CON2 & 0x1F) | (SSP1STATbits.R_W))
#endif
#if defined (I2C_V6_2)
#define IdleI2C1()    while ((SSP1CON2 & 0x1F) | (SSP1STATbits.R_NOT_W))
#endif
#define IdleI2C IdleI2C1
/*********************************************************************
Macro  :  CloseI2C1()
Include            : i2c.h 
Description        : This Macro turns off the I2C module 
Arguments          : None 
Return Value       : None 
Remarks            : This Macro disables the I2C module.
*********************************************************************/
#define CloseI2C1()  SSP1CON1 &=0xDF
#define CloseI2C CloseI2C1
void OpenI2C1(  unsigned char sync_mode,  unsigned char slew );
#define OpenI2C OpenI2C1
/************************************************************************
Macro :  DataRdyI2C1() 
Include            : i2c.h 
Description        : This Macro provides status back to user if SSPxBUF
register contain data. 
                     
Arguments          : None 
Remarks            : This Macro determines if there is any byte to read from
SSPxBUF register.
*************************************************************************/
#define DataRdyI2C1()    (SSP1STATbits.BF)
#define DataRdyI2C DataRdyI2C1
unsigned char ReadI2C1( void );
#define ReadI2C ReadI2C1
/**************************************************************************
Macro       : getcI2C1
Description : macro is identical to ReadI2C1,#define to ReadI2C1 in i2c.h
 
Arguments   : None
 
Remarks     : None 
***************************************************************************/
#define  getcI2C1  ReadI2C1
#define  getcI2C getcI2C1
signed char WriteI2C1(  unsigned char data_out );
#define WriteI2C WriteI2C1
/**************************************************************************
Macro       : putcI2C1
Description : macro is identical to WriteI2C1,#define to WriteI2C1 in i2c.h
 
Arguments   : None
 
Remarks     : None 
***************************************************************************/
#define  putcI2C1  WriteI2C1
#define  putcI2C putcI2C1
signed char getsI2C1(  unsigned char *rdptr,  unsigned char length );
#define getsI2C getsI2C1
signed char putsI2C1(  unsigned char *wrptr );
#define putsI2C putsI2C1
//****************** I2C EEPROM Function prototype ******************************
signed char EEAckPolling1(  unsigned char control );
#define EEAckPolling EEAckPolling1
signed char EEByteWrite1(  unsigned char control,
                            unsigned char address,
                            unsigned char data );
#define EEByteWrite EEByteWrite1
signed int  EECurrentAddRead1(  unsigned char control );
#define EECurrentAddRead EECurrentAddRead1
signed char EEPageWrite1(  unsigned char control,
                            unsigned char address,
                            unsigned char *wrptr );
#define EEPageWrite EEPageWrite1
signed int  EERandomRead1(  unsigned char control,  unsigned char address );
#define EERandomRead EERandomRead1
signed char EESequentialRead1(  unsigned char control,
                                 unsigned char address,
                                 unsigned char *rdptr,
                                 unsigned char length );
#define EESequentialRead EESequentialRead1
#endif
#if defined (I2C_V3) || defined (I2C_V6) || defined (I2C_V6_1) /*This version has MSSP2*/
/* ***** I2C2 ***** */
#if defined (I2C_V3) || defined (I2C_V6)
/***********************************************************************************
Macro       : EnableIntI2C2
Include     : i2c.h
Description : Macro enables I2C  Interrupt 
 
Arguments   : None
 
Remarks     : None 
***********************************************************************************/
#define EnableIntI2C2                   (PIE3bits.SSP2IE = 1)
/***********************************************************************************
Macro       : DisableIntI2C2
Include     : i2c.h
Description : Macro disables I2C  Interrupt 
 
Arguments   : None
 
Remarks     : None 
***********************************************************************************/
#define DisableIntI2C2                   (PIE3bits.SSP2IE = 0)
/***********************************************************************************
Macro       : SetPriorityIntI2C2(priority)
 
Include     : i2c.h
 
Description : Macro sets the priority level for I2C interrupt.
 
Arguments   : priority - This input parameter is the level of interrupt priority.
* 0 -- Low priority (Default Value)
* 1 -- High Priority
 Remarks     : None
***********************************************************************************/
#define SetPriorityIntI2C2(priority)     (IPR3bits.SSP2IP = priority)
/*******************************************************************
Macro       : I2C2_Clear_Intr_Status_Bit
Include     : i2c.h 
Description : Macro to Clear I2C  Interrupt Status bit 
Arguments   : None 
Remarks     : None 
*******************************************************************/
#define I2C2_Clear_Intr_Status_Bit     (PIR3bits.SSP2IF = 0)
/*******************************************************************
Macro       : I2C2_Intr_Status
Include     : i2c.h 
Description : Macro to return I2C Interrupt Status  
Arguments   : None 
Remarks     : None 
*******************************************************************/
#define I2C2_Intr_Status PIR3bits.SSP2IF
#elif defined(I2C_V6_1)
/***********************************************************************************
Macro       : EnableIntI2C2
Include     : i2c.h
Description : Macro enables I2C  Interrupt 
 
Arguments   : None
 
Remarks     : None 
***********************************************************************************/
#define EnableIntI2C2                   (PIE2bits.SSP2IE = 1)
/***********************************************************************************
Macro       : DisableIntI2C2
Include     : i2c.h
Description : Macro disables I2C  Interrupt 
 
Arguments   : None
 
Remarks     : None 
***********************************************************************************/
#define DisableIntI2C2                   (PIE2bits.SSP2IE = 0)
/***********************************************************************************
Macro       : SetPriorityIntI2C2(priority)
 
Include     : i2c.h
 
Description : Macro sets the priority level for I2C interrupt.
 
Arguments   : priority - This input parameter is the level of interrupt priority.
* 0 -- Low priority (Default Value)
* 1 -- High Priority
 Remarks     : None
***********************************************************************************/
#define SetPriorityIntI2C2(priority)     (IPR2bits.SSP2IP = priority)
/*******************************************************************
Macro       : I2C2_Clear_Intr_Status_Bit
Include     : i2c.h 
Description : Macro to Clear I2C  Interrupt Status bit 
Arguments   : None 
Remarks     : None 
*******************************************************************/
#define I2C2_Clear_Intr_Status_Bit     (PIR2bits.SSP2IF = 0)
/*******************************************************************
Macro       : I2C2_Intr_Status
Include     : i2c.h 
Description : Macro to return I2C Interrupt Status  
Arguments   : None 
Remarks     : None 
*******************************************************************/
#define I2C2_Intr_Status PIR2bits.SSP2IF
#endif
/*******************************************************************
Macro       : StopI2C2()
Include     : i2c.h
Description : Macro to initiate stop condition
Arguments   : None
Remarks     : This macro initiates stop condition and waits till the stop signal
sequence is terminated.This macro is applicable only to master
*******************************************************************/
#define StopI2C2()  SSP2CON2bits.PEN=1;while(SSP2CON2bits.PEN)
/*******************************************************************
Macro       : StartI2C2()
Include     : i2c.h
Description : Macro to initiate start condition
Arguments   : None
Remarks     : This macro initiates start condition and waits till the start signal
sequence is terminated. This macro is applicable only to master
*******************************************************************/
#define StartI2C2()  SSP2CON2bits.SEN=1;while(SSP2CON2bits.SEN)
/*******************************************************************
Macro       : RestartI2C2()
Include     : i2c.h
Description : Macro to initiate Restart condition
Arguments   : None
Remarks     : This macro initiates Restart condition and waits till the Restart signal
sequence is terminated. This macro is applicable only to master
*******************************************************************/
#define RestartI2C2()  SSP2CON2bits.RSEN=1;while(SSP2CON2bits.RSEN)
/*******************************************************************
Macro       : NotAckI2C2()
Include     : i2c.h
Description : Macro to initiate negetive acknowledgement sequence
Arguments   : None
Remarks     : This macro initiates negetive acknowledgement condition and 
waits till the acknowledgement sequence is terminated.
This macro is applicable only to master
*******************************************************************/
#define NotAckI2C2()     SSP2CON2bits.ACKDT=1, SSP2CON2bits.ACKEN=1;while(SSP2CON2bits.ACKEN)
/*******************************************************************
Macro       : AckI2C2()
Include     : i2c.h
Description : Macro to initiate positive acknowledgement sequence
Arguments   : None
Remarks     : This macro initiates positive acknowledgement condition and 
waits till the acknowledgement sequence is terminated.
This macro is applicable only to master
*******************************************************************/
#define AckI2C2()        SSP2CON2bits.ACKDT=0, SSP2CON2bits.ACKEN=1;while(SSP2CON2bits.ACKEN)
#if defined (I2C_SFR_V1)
/**********************************************************************************************
Macro :  IdleI2C2() 
Include            : i2c.h 
Description        : This Macro generates Wait condition until I2C bus is Idle.
Arguments          : None 
Remarks            : This Macro will be in a wait state until Start Condition Enable bit,
                     Stop Condition Enable bit, Receive Enable bit, Acknowledge Sequence
                     Enable bit of I2C Control register and Transmit Status bit I2C Status
                     register are clear. The IdleI2C function is required since the hardware
                     I2C peripheral does not allow for spooling of bus sequence. The I2C
                     peripheral must be in Idle state before an I2C operation can be initiated
                     or write collision will be generated.
***********************************************************************************************/
#define IdleI2C2()    while ((SSP2CON2 & 0x1F) | (SSP2STATbits.R_NOT_W))
#else
/**********************************************************************************************
Macro :  IdleI2C2() 
Include            : i2c.h 
Description        : This Macro generates Wait condition until I2C bus is Idle.
Arguments          : None 
Remarks            : This Macro will be in a wait state until Start Condition Enable bit,
                     Stop Condition Enable bit, Receive Enable bit, Acknowledge Sequence
                     Enable bit of I2C Control register and Transmit Status bit I2C Status
                     register are clear. The IdleI2C function is required since the hardware
                     I2C peripheral does not allow for spooling of bus sequence. The I2C
                     peripheral must be in Idle state before an I2C operation can be initiated
                     or write collision will be generated.
***********************************************************************************************/
#define IdleI2C2()    while ((SSP2CON2 & 0x1F) | (SSP2STATbits.R_W))
#endif
/*********************************************************************
Macro  :  CloseI2C2()
Include            : i2c.h 
Description        : This Macro turns off the I2C module 
Arguments          : None 
Return Value       : None 
Remarks            : This Macro disables the I2C module.
*********************************************************************/
#define CloseI2C2()  SSP2CON1 &=0xDF
void OpenI2C2(  unsigned char sync_mode,  unsigned char slew );
/************************************************************************
Macro :  DataRdyI2C2() 
Include            : i2c.h 
Description        : This Macro provides status back to user if SSPxBUF
register contain data. 
                     
Arguments          : None 
Remarks            : This Macro determines if there is any byte to read from
SSPxBUF register.
*************************************************************************/
#define DataRdyI2C2()    (SSP2STATbits.BF)
unsigned char ReadI2C2( void );
/**************************************************************************
Macro       : getcI2C2
Description : macro is identical to ReadI2C2,#define to ReadI2C2 in i2c.h
 
Arguments   : None
 
Remarks     : None 
***************************************************************************/
#define  getcI2C2  ReadI2C2
signed char WriteI2C2(  unsigned char data_out );
/**************************************************************************
Macro       : putcI2C2
Description : macro is identical to WriteI2C2,#define to WriteI2C2 in i2c.h
 
Arguments   : None
 
Remarks     : None 
***************************************************************************/
#define  putcI2C2  WriteI2C2
signed char getsI2C2(  unsigned char *rdptr,  unsigned char length );
signed char putsI2C2(  unsigned char *wrptr );
//******************* I2C EEPROM Function Prototype ******************************
signed char EEAckPolling2(  unsigned char control );
signed char EEByteWrite2(  unsigned char control,
                            unsigned char address,
                            unsigned char data );
signed int  EECurrentAddRead2(  unsigned char control );
signed char EEPageWrite2(  unsigned char control,
                            unsigned char address,
                            unsigned char *wrptr );
signed int  EERandomRead2(  unsigned char control,  unsigned char address );
signed char EESequentialRead2(  unsigned char control,
                                 unsigned char address,
                                 unsigned char *rdptr,
                                 unsigned char length );
#endif
#if defined (I2C_V1) || defined (I2C_V4)    /* Parts with only one I2C, MSSP */
//******** I2C **********
/***********************************************************************************
Macro       : EnableIntI2C
Include     : i2c.h
Description : Macro enables I2C  Interrupt 
 
Arguments   : None
 
Remarks     : None 
***********************************************************************************/
#define EnableIntI2C                   (PIE1bits.SSPIE = 1)
#define EnableIntI2C1 EnableIntI2C
/***********************************************************************************
Macro       : DisableIntI2C
Include     : i2c.h
Description : Macro disables I2C  Interrupt 
 
Arguments   : None
 
Remarks     : None 
***********************************************************************************/
#define DisableIntI2C                   (PIE1bits.SSPIE = 0)
#define DisableIntI2C1 DisableIntI2C
/***********************************************************************************
Macro       : SetPriorityIntI2C(priority)
 
Include     : i2c.h
 
Description : Macro sets the priority level for I2C interrupt.
 
Arguments   : priority - This input parameter is the level of interrupt priority.
* 0 -- Low priority (Default Value)
* 1 -- High Priority
 Remarks     : None
***********************************************************************************/
#define SetPriorityIntI2C(priority)     (IPR1bits.SSPIP = priority)
#define SetPriorityIntI2C1 SetPriorityIntI2C
/*******************************************************************
Macro       : I2C_Clear_Intr_Status_Bit
Include     : i2c.h 
Description : Macro to Clear I2C  Interrupt Status bit 
Arguments   : None 
Remarks     : None 
*******************************************************************/
#define I2C_Clear_Intr_Status_Bit     (PIR1bits.SSPIF = 0)
#define I2C1_Clear_Intr_Status_Bit I2C_Clear_Intr_Status_Bit
/*******************************************************************
Macro       : I2C_Intr_Status
Include     : i2c.h 
Description : Macro to return I2C Interrupt Status  
Arguments   : None 
Remarks     : None 
*******************************************************************/
#define I2C_Intr_Status PIR1bits.SSPIF
#define I2C1_Intr_Status I2C_Intr_Status
/**************************************************************************
Macro       : getcI2C
Description : macro is identical to ReadI2C,#define to ReadI2C in i2c.h
 
Arguments   : None
 
Remarks     : None 
***************************************************************************/
#define  getcI2C  ReadI2C
/**************************************************************************
Macro       : putcI2C
Description : macro is identical to WriteI2C,#define to WriteI2C in i2c.h
 
Arguments   : None
 
Remarks     : None 
***************************************************************************/
#define  putcI2C  WriteI2C
void IdleI2C( void );
void OpenI2C(  unsigned char sync_mode,  unsigned char slew );
signed char WriteI2C( unsigned char data_out );
signed char putsI2C(  unsigned char *wrptr );
unsigned char ReadI2C( void );
void CloseI2C( void );
#endif
#if defined (I2C_V1) 
/* CloseI2C
 * Disable SPI module
 */
//#define CloseI2C()  SSPCON1 &=0xDF
/* Idle I2C
 * Test if I2C module is idle
 */
//#define IdleI2C()    while ((SSPCON2 & 0x1F) | (SSPSTATbits.R_W))
/*******************************************************************
Macro       : StopI2C()
Include     : i2c.h
Description : Macro to initiate stop condition
Arguments   : None
Remarks     : This macro initiates stop condition and waits till the stop signal
sequence is terminated.This macro is applicable only to master
*******************************************************************/
#define StopI2C()  SSPCON2bits.PEN=1;while(SSPCON2bits.PEN)
/*******************************************************************
Macro       : StartI2C()
Include     : i2c.h
Description : Macro to initiate start condition
Arguments   : None
Remarks     : This macro initiates start condition and waits till the start signal
sequence is terminated. This macro is applicable only to master
*******************************************************************/
#define StartI2C()  SSPCON2bits.SEN=1;while(SSPCON2bits.SEN)
/*******************************************************************
Macro       : RestartI2C()
Include     : i2c.h
Description : Macro to initiate Restart condition
Arguments   : None
Remarks     : This macro initiates Restart condition and waits till the Restart signal
sequence is terminated. This macro is applicable only to master
*******************************************************************/
#define RestartI2C()  SSPCON2bits.RSEN=1;while(SSPCON2bits.RSEN)
/*******************************************************************
Macro       : NotAckI2C()
Include     : i2c.h
Description : Macro to initiate negetive acknowledgement sequence
Arguments   : None
Remarks     : This macro initiates negetive acknowledgement condition and 
waits till the acknowledgement sequence is terminated.
This macro is applicable only to master
*******************************************************************/
#define NotAckI2C()     SSPCON2bits.ACKDT=1;SSPCON2bits.ACKEN=1;while(SSPCON2bits.ACKEN)
/*******************************************************************
Macro       : AckI2C()
Include     : i2c.h
Description : Macro to initiate positive acknowledgement sequence
Arguments   : None
Remarks     : This macro initiates positive acknowledgement condition and 
waits till the acknowledgement sequence is terminated.
This macro is applicable only to master
*******************************************************************/
#define AckI2C()        SSPCON2bits.ACKDT=0;SSPCON2bits.ACKEN=1;while(SSPCON2bits.ACKEN)
/************************************************************************
Macro :  DataRdyI2C() 
Include            : i2c.h 
Description        : This Macro provides status back to user if SSPxBUF
register contain data. 
                     
Arguments          : None 
Remarks            : This Macro determines if there is any byte to read from
SSPxBUF register.
*************************************************************************/
#define DataRdyI2C()    (SSPSTATbits.BF)
/**************************************************************************
Macro       : putcI2C
Description : macro is identical to WriteI2C,#define to WriteI2C in i2c.h
 
Arguments   : None
 
Remarks     : None 
***************************************************************************/
#define  putcI2C  WriteI2C
signed char WriteI2C(  unsigned char data_out );
signed char getsI2C(  unsigned char *rdptr,  unsigned char length );
//******************* I2C EEPROM Function Prototype ******************************
signed char EEAckPolling(  unsigned char control );
signed char EEByteWrite(  unsigned char control,
                            unsigned char address,
                            unsigned char data );
signed int  EECurrentAddRead(  unsigned char control );
signed char EEPageWrite(  unsigned char control,
                            unsigned char address,
                            unsigned char *wrptr );
signed int  EERandomRead(  unsigned char control,  unsigned char address );
signed char EESequentialRead(  unsigned char control,
                                 unsigned char address,
                                 unsigned char *rdptr,
                                 unsigned char length );
#endif
#if defined (I2C_IO_V1 ) 
#define I2C_SCL TRISCbits.TRISC3
#define I2C_SDA TRISCbits.TRISC4
#endif
#if defined (I2C_IO_V2)
#define I2C_SCL TRISCbits.TRISC5
#define I2C_SDA TRISCbits.TRISC4
#endif
#if defined (I2C_IO_V3)
#define I2C_SCL TRISBbits.TRISB1
#define I2C_SDA TRISBbits.TRISB0
#endif
#if defined (I2C_IO_V4)
#define I2C_SCL TRISBbits.TRISB6
#define I2C_SDA TRISBbits.TRISB4
#endif
#if defined (I2C_IO_V5)
#define I2C1_SCL TRISCbits.TRISC3
#define I2C1_SDA TRISCbits.TRISC4
#endif
#if defined (I2C_IO_V6)
#define I2C2_SCL TRISDbits.TRISD0
#define I2C2_SDA TRISDbits.TRISD1
#endif
#if defined (I2C_IO_V7)
#define I2C2_SCL TRISDbits.TRISD6
#define I2C2_SDA TRISDbits.TRISD5
#endif
#endif
 
 

 
I already commented ALL my code, the only line that i get some error is this :
 
 #define USE_MPU6050_SOFT_I2C
      //Soft_SPI_Init();
      //lcd_inicializa();
      //lcd_LD_cursor(0);
      //StartI2C1();
      //OpenI2C(SLAVE_10, SLEW_ON);
      MPU6050_Init();


 
 
I get this error :
 
 :0: error: undefined symbols:
        _I2C1_Stop(dist/default/production\Teste_MPU.X.production.obj)
_I2C1_Wr(dist/default/production\Teste_MPU.X.production.obj)
_I2C1_Rd(dist/default/production\Teste_MPU.X.production.obj)
_I2C1_Start(dist/default/production\Teste_MPU.X.production.obj)


 
this is weird because I've searched on all lines (ctrl + F) and there is no anyone line that i see _I2C1_Stop or _I2C1_Rd for example
 
Anyone can help me?
 
Thanks 
#1

7 Replies Related Threads

    du.facc
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2014/02/01 11:09:01
    • Location: 0
    • Status: offline
    Re:MPU6050 with PIC18F4550 (I²C) 2014/03/01 16:28:53 (permalink)
    0
    Any idea? =(
    #2
    DavidBLit
    Super Member
    • Total Posts : 1579
    • Reward points : 0
    • Joined: 2012/02/18 13:08:48
    • Location: The Land of Confusion
    • Status: offline
    Re:MPU6050 with PIC18F4550 (I²C) 2014/03/01 18:57:06 (permalink)
    +2 (1)
    I think your "mpu library" doesn't see this:

    #define USE_MPU6050_SOFT_I2C


     
     
    #3
    du.facc
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2014/02/01 11:09:01
    • Location: 0
    • Status: offline
    Re:MPU6050 with PIC18F4550 (I²C) 2014/03/01 19:06:07 (permalink)
    0
    I dont know so much about how works library but, this define dont is this "ifdef" on mpu library?
     
     #ifdef USE_MPU6050_SOFT_I2C
      #define MPU6050_I2C_Wr Soft_I2C_Write
      #define MPU6050_I2C_Rd Soft_I2C_Read
      #define MPU6050_I2C_Stop Soft_I2C_Stop
      #define MPU6050_I2C_Start Soft_I2C_Start
      #define MPU6050_Scl Soft_I2C_Scl
      #define MPU6050_Sda Soft_I2C_Sda
      #define MPU6050_Scl_Direction Soft_I2C_Scl_Direction
      #define MPU6050_Sda_Direction Soft_I2C_Sda_Direction
     #else
      #define MPU6050_I2C_Wr I2C1_Wr
      #define MPU6050_I2C_Rd I2C1_Rd
      #define MPU6050_I2C_Stop StopI2C1
      #define MPU6050_I2C_Start StartI2C
     #endif  
    #4
    DavidBLit
    Super Member
    • Total Posts : 1579
    • Reward points : 0
    • Joined: 2012/02/18 13:08:48
    • Location: The Land of Confusion
    • Status: offline
    Re:MPU6050 with PIC18F4550 (I²C) 2014/03/01 19:47:24 (permalink)
    +2 (1)
    The error you're getting indicates the library code isn't seeing your #define.
     
    This usually happens if the #define is in a source file different from the file that has the #ifdef or the #define is after a #include file that has the #ifdef.
     
    #5
    du.facc
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2014/02/01 11:09:01
    • Location: 0
    • Status: offline
    Re:MPU6050 with PIC18F4550 (I²C) 2014/03/02 08:22:54 (permalink)
    0
    I'm testting right now, but , not is this line the problem. the line is this :
     
     MPU6050_Init();
    When i comment this line, i can compile.  
    #6
    Nacikocan
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2020/04/09 04:10:32
    • Location: 0
    • Status: offline
    Re:MPU6050 with PIC18F4550 (I²C) 2020/06/30 08:57:43 (permalink)
    0
    is it work your code ?
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 18858
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re:MPU6050 with PIC18F4550 (I²C) 2020/06/30 09:49:12 (permalink)
    +1 (1)
    That was 6 years ago, and they have not logged in in 4 years.
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5