Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

showing error of multiple definition

Status
Not open for further replies.

vinay shabad

Junior Member level 3
Joined
Dec 13, 2010
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,769
hiii i wrote a program for i2c comm with sensor when i am compiling individual evry thing is fine but when i am building all it showing the fallowing error


C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\I2C_HAL.c:5: multiple definition of `I2c_init'
main.o(.text+0x462):C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\main.c:5: first defined here
I2C_HAL.o(.text+0x1e): In function `I2c_startCondition':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\I2C_HAL.c:17: multiple definition of `I2c_startCondition'
main.o(.text+0x480):C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\main.c:17: first defined here
I2C_HAL.o(.text+0x3c): In function `I2c_stopCondition':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\I2C_HAL.c:29: multiple definition of `I2c_stopCondition'
main.o(.text+0x49e):C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\main.c:29: first defined here
I2C_HAL.o(.text+0x5a): In function `I2c_writeByte':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\I2C_HAL.c:41: multiple definition of `I2c_writeByte'
main.o(.text+0x4bc):C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\main.c:41: first defined here
I2C_HAL.o(.text+0xc6): In function `I2c_readByte':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\I2C_HAL.c:66: multiple definition of `I2c_readByte'
main.o(.text+0x528):C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\main.c:66: first defined here
c:\program files\microchip\mplabc30\v3.25\bin\bin\..\bin/pic30-coff-ld.exe: Link terminated due to previous error(s).











this is my header file






#ifndef I2C_HAL_H
#define I2C_HAL_H
//==============================================================================
// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
//==============================================================================
// Project : SHT2x Sample Code (V1.2)
// File : I2C_HAL.h
// Author : MST
// Controller: NEC V850/SG3 (uPD70F3740)
// Compiler : IAR compiler for V850 (3.50A)
// Brief : I2C Hardware abstraction layer
//==============================================================================
//---------- Includes ----------------------------------------------------------
#include "system.h"
//---------- Defines -----------------------------------------------------------
//I2C ports
//The communication on SDA and SCL is done by switching pad direction
//For a low level on SCL or SDA, direction is set to output. For a high level on
//SCL or SDA, direction is set to input. (pull up resistor active)
#define SDA_bit_no0 //SDA on I/O P38 defines direction (input=1/output=0)
#define SDA_CONF_bit_no0 //SDA level on output direction
#define SCL_bit_no1 //SCL on I/O P39 defines direction (input=1/output=0)
#define SCL_CONF_bit_no1 //SCL level on output direction
//---------- Enumerations ------------------------------------------------------
// I2C level
typedef enum{
LOW = 0,
HIGH = 1,
}I2cLevel;
// I2C acknowledge
typedef enum{
ACK = 0,
NO_ACK = 1,
}I2cAck;
//==============================================================================
void I2c_Init ();
//==============================================================================
//Initializes the ports for I2C interface
//==============================================================================
void I2c_StartCondition ();
//==============================================================================
// writes a start condition on I2C-bus
// input : -
// output: -
// return: -
// note : timing (delay) may have to be changed for different microcontroller
// _____
// SDA: |_____
// _______
// SCL : |___
//==============================================================================
void I2c_StopCondition ();
//==============================================================================
// writes a stop condition on I2C-bus
// input : -
// output: -
// return: -
// note : timing (delay) may have to be changed for different microcontroller
// _____

// SDA: _____|
// _______
// SCL : ___|
//===========================================================================
I2c_WriteByte ( txByte);
//===========================================================================
// writes a byte to I2C-bus and checks acknowledge
// input: txByte transmit byte
// output: -
// return: error
// note: timing (delay) may have to be changed for different microcontroller
//===========================================================================
I2c_ReadByte (ack);
//===========================================================================
// reads a byte on I2C-bus
// input: rxByte receive byte
// output: rxByte
// note: timing (delay) may have to be changed for different microcontroller
#endif















this is i2c file



#include "I2C_HAL.h"
//==============================================================================
void I2c_init ()
//==============================================================================
{
unsigned char SDA,SCL,LOW,HIGH,SDA_CONF,SCL_CONF;
SDA=LOW; // Set port as output for configuration
SCL=LOW; // Set port as output for configuration
SDA_CONF=LOW; // Set SDA level as low for output mode
SCL_CONF=LOW; // Set SCL level as low for output mode
SDA=HIGH; // I2C-bus idle mode SDA released (input)
SCL=HIGH; // I2C-bus idle mode SCL released (input)
}
//==============================================================================
void I2c_startCondition ()
//==============================================================================
{
unsigned char SDA,SCL,LOW,HIGH;
SDA=HIGH;
SCL=HIGH;
SDA=LOW;
DelayMicroSeconds(10); // hold time start condition (t_HD;STA)
SCL=LOW;
DelayMicroSeconds(10);
}
//==============================================================================
void I2c_stopCondition ()
//==============================================================================
{
unsigned char SDA,SCL,LOW,HIGH;
SDA=LOW;
SCL=LOW;
SCL=HIGH;
DelayMicroSeconds(10); // set-up time stop condition (t_SU;STO)
SDA=HIGH;
DelayMicroSeconds(10);
}
//==============================================================================
I2c_writeByte (txByte)
//==============================================================================
{
unsigned char SDA,SCL,LOW,HIGH, mask,error,ACK_ERROR,SDA_CONF;
error=0;
for (mask=0x80; mask>0; mask>>=1) //shift bit for masking (8 times)
{ if ((mask & txByte) == 0) SDA=LOW;//masking txByte, write bit to SDA-Line
else SDA=HIGH;
DelayMicroSeconds(1); //data set-up time (t_SU;DAT)
SCL=HIGH; //generate clock pulse on SCL
DelayMicroSeconds(5); //SCL high time (t_HIGH)
SCL=LOW;
DelayMicroSeconds(1); //data hold time(t_HD;DAT)
}

SDA=HIGH; //release SDA-line
SCL=HIGH; //clk #9 for ack
DelayMicroSeconds(1); //data set-up time (t_SU;DAT)
if(SDA_CONF==HIGH)
error=ACK_ERROR; //check ack from i2c slave
SCL=LOW;
DelayMicroSeconds(20); //wait time to see byte package on scope
return error; //return error code
}
//==============================================================================
I2c_readByte ( ack)
//==============================================================================
{
unsigned char SDA,SCL,LOW,HIGH, mask,rxByte,SDA_CONF;
rxByte=0;
SDA=HIGH; //release SDA-line
for (mask=0x80; mask>0; mask>>=1) //shift bit for masking (8 times)
{ SCL=HIGH; //start clock on SCL-line
DelayMicroSeconds(1); //data set-up time (t_SU;DAT)
DelayMicroSeconds(3); //SCL high time (t_HIGH)
if (SDA_CONF==1) rxByte=(rxByte | mask); //read bit
SCL=LOW;
DelayMicroSeconds(1); //data hold time(t_HD;DAT)
}
SDA=ack; //send acknowledge if necessary
DelayMicroSeconds(1); //data set-up time (t_SU;DAT)
SCL=HIGH; //clk #9 for ack
DelayMicroSeconds(5); //SCL high time (t_HIGH)
SCL=LOW;
SDA=HIGH; //release SDA-line
DelayMicroSeconds(20); //wait time to see byte package on scope
return rxByte; //return error code
}



can any one please help me i strucked at this point.Thankyou in advance.
 

vinay shabad

Junior Member level 3
Joined
Dec 13, 2010
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,769
thank you for ur response
but, its still showing same error
 

horace1

Advanced Member level 5
Joined
Nov 18, 2008
Messages
2,123
Helped
596
Reputation
1,188
Reaction score
573
Trophy points
1,393
Location
Norwich, UK
Activity points
13,071
multiple definition means you have not just declared a function prototype more than once but you have defined the function (i.e. a function header with a body that implements the function code) more than once.
e.g.
Code:
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_ 24F\I2C_HAL.c:5: multiple definition of `I2c_init'
main.o(.text+0x462):C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_ 24F\main.c:5: first defined here
look in file I2C_HAL.c and main.c for function definitions such as
Code:
int I2c_init()
{
     code
}
remove one of them (probably the one in main()) - similar with all the other multiple definitions
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top