Reputation: 25
I'm trying to pass struct variables to a function, but I receive:
error: conflicting types for 'referenzspannung'
void referenzspannung(struct ADMESSUNG *mess) {
^~~~~~~~~~~~~~~~
In my measure.h
I wrote the prototype:
void referenzspannung(struct ADMESSUNG *mess);
and in the measure.c
there is the struct+function:
struct ADMESSUNG {
unsigned long Coderef;
double Uref;
double Stcal;
double Offset;
unsigned long Temperaturcode;
double Temperaturavin;
double RTD;
double R;
double Tempwert;
unsigned long Phcode;
double Phavin;
double Stprobe;
double PHWert;
};
struct ADMESSUNG mess;
void referenzspannung(struct ADMESSUNG *mess) {
AD7793_SetIntReference(AD7793_REFSEL_INT);
AD7793_SetExcitDirection(AD7793_DIR_IEXC1_IOUT2_IEXC2_IOUT1);
AD7793_SetExcitCurrent(AD7793_EN_IXCEN_210uA);
AD7793_SetChannel(AD7793_CH_AIN3P_AIN3M);
mess->Coderef = AD7793_ContinuousReadAvg(50);
mess->Uref = ((mess->Coderef / 8388608) - 1) * 1.17; // code in voltage
}
In my main.c
I call the function then:
referenzspannung(struct ADMESSUNG *mess);
Does anyone see a mistake? I think I did everything in the right order and I have the syntax from multiple websites.
Upvotes: 1
Views: 76
Reputation: 7051
Move the definition struct ADMESSUNG {...}
to your .h file.
The compiler makes assumptions about what the struct looks like when it encounters void referenzspannung(struct ADMESSUNG *mess);
with out knowing what the struct looks like.
The compiler would warn you about these assumptions. In gcc use -Wall
to get all warnings.
The instance declaration struct ADMESSUNG mess;
needs to be in the main.c to be visible where it is referenced or should be in the .h with an extern
modifier.
The function call should reference the struct instance referenzspannung(&mess);
as it is not a pointer.
Upvotes: 1