Ok, thanks for the replies guys.
It looks like I've been breaking a few rules with my 'include code.c'
Ian, I'll have a read of your multi-file link later tonight. Thanks.
Now that I've tried to implement the code correctly I'm getting some errors. I hope the following makes sense.
I've done the following:- I've removed the "include TSYS01.c" from my main code.
- For my 2nd code file TSYS01.c, I've separated out the header file stuff (variable definitions and function declarations) into TSYS01.h.
- I've added the TSYS01.h file to the project and have added the TSYS01.c file as a source file.
So I now have 4 files:
main.c
main.h
TSYS01.c //functions for TSYS01 sensor.
TSYS01.h
Prior to these changes the code compiled and ran fine on the hardware.
Now when I compile a get some errors:TSYS01.c:26: warning: (361) function declared implicit int
(908) exit status = 1
TSYS01.c:27: warning: (361) function declared implicit int
TSYS01.c:28: warning: (361) function declared implicit int
TSYS01.c:29: warning: (361) function declared implicit int
TSYS01.c:30: warning: (361) function declared implicit int
TSYS01.c:39: error: (984) type redeclared
TSYS01.c:39: error: (1098) conflicting declarations for variable "TSYS01_reset" (TSYS01.c:38)
make[2]: *** [build/default/debug/TSYS01.p1] Error 1
make[2]: *** Waiting for unfinished jobs....
nbproject/Makefile-default.mk:99: recipe for target 'build/default/debug/TSYS01.p1' failed
main_temp.c:686: warning: (343) implicit return at end of non-void function
make[1]: *** [.build-conf] Error 2
make[2]: Leaving directory 'C:/Users/home/MPLABXProjects/SDI12_TEMP.X'
make: *** [.build-impl] Error 2
nbproject/Makefile-default.mk:84: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/home/MPLABXProjects/SDI12_TEMP.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 429ms)
Googling tells me the "function declared implicit int" warnings (functions are in TSYS01.c) mean that the functions prototypes are missing so it assumes it takes no arguments and returns an int.
Yet I have declared the functions in the header file TSYS01.h which is included by the line 'include TSYS01.h' the main.c program.
The type "TSYS01.c:39: error: (984) type redeclared" error is pointing at the function below in the TSYS01.c file
void TSYS01_reset(void) //reset the TSYS01 IC
{}
The second error "TSYS01.c:39: error: (1098) conflicting declarations for variable "TSYS01_reset" (TSYS01.c:38)" is pointing at the {} brackets of the same function.
main.c - includes
// all pragma statements snipped for brevity
//###################################################################
// I N C L U D E F I L E S
// "local project file"
//###################################################################
#include "temp.h" // header file for main
#include "TSYS01.h" //header file for TSYS01 sensor code
#include "usart.h" // adds h/w serial support
#include <string.h> // adds string tools
#include <delays.h> // adds the delays lib
#include <timers.h> // adds the timer lib
#include <stdlib.h> // adds data conversion lib
#include <stdio.h>
#include <i2c.h> // for I2C sensor
//#include "TSYS01.c"
// rest of code snipped for brevity
TSYS01.h
//******************************************************************************
// TSYS01.h
//******************************************************************************
//TSYS01 variable declarations
unsigned short long ADC16; // was double
unsigned long ADC24 = 9378708; // TSYS01 temperature result, was double
unsigned short long ADC_MSB = 0; // 3 x 8 bit bytes read from TSYS01 combined = ADC24
unsigned int ADC_MID = 0;
unsigned int ADC_LSB = 0;
float Temp_C; //calculated temperature Celcius
//unsigned char TempStr[8]="."; //temp ascii string
//calibration coefficients, 16 bit integers
double k4 = 28446;//unsigned int
unsigned int k3 = 0;//24926;
unsigned int k2 = 0;//36016;
unsigned int k1 = 0;//32791;
unsigned int k0 = 0;//40781;
//calibration coefficient nibbles
unsigned char k4MSB = 0;
unsigned char k4LSB = 0;
unsigned char k3MSB = 0;
unsigned char k3LSB = 0;
unsigned char k2MSB = 0;
unsigned char k2LSB = 0;
unsigned char k1MSB = 0;
unsigned char k1LSB = 0;
unsigned char k0MSB = 0;
unsigned char k0LSB = 0;
//TSYS01 function declarations
void TSYS01_read(void); //Reads sensor using functions below
void TSYS01_reset(void); //Reset the TSYS01 sensor IC
void TSYS01_read_coeffs(void); //Reads 5 x 16 bit coefficients from the TSYS01
void TSYS01_convert(void); //Instructs TSYS01 sensor to do a measurement
void TSYS01_read_ADC(void); //Reads TSYS01 ADC result, ADC result left in ADC24
void TSYS01_calc(void); //Calc temp using ADC val & coeffs from TSYS01
TSYS01.c
//*****************************************************************************
//TSYS01.c F U N C T I O N S F O R T S Y S 0 1 T E M P S E N S O R
//*****************************************************************************
//
// void TSYS01_read(void) Reads sensor using functions below
//
// void TSYS01_reset(void) Reset the TSYS01 sensor IC
// void TSYS01_read_coeffs(void) Reads 5 x 16 bit coefficients from the TSYS01
// void TSYS01_convert(void) Instructs TSYS01 sensor to do a measurement
// void TSYS01_read_ADC(void) Reads TSYS01 ADC result, ADC result left in ADC24
// void TSYS01_calc(void) Calc temp using ADC val & coeffs from TSYS01
//
// Use TSYS01_read() function to read the sensor. It uses all the other functions.
// It: resets IC, reads coeffs, starts conversion, reads ADC & then calls calc.
// After calc the temp is stored as a string TempStr[] and as a float Temp_C
//
//*****************************************************************************
//*********************************************************************
// void TSYS01_read(void)
// Read the sensor using functions below
//*********************************************************************
void TSYS01_read(void)
{
TSYS01_reset(); // reset the TSYS01 IC
TSYS01_read_coeffs(); // read the calc coefficients from the TSYS01 sensor
TSYS01_convert(); // instruct TSYS01 sensor to perform a conversion [takes 15mS]
TSYS01_read_ADC(); // read the ADC temp value from the TSYS01 sensor
TSYS01_calc(); // calc temp from TSYS01 ADC value, result in T &
}
//*********************************************************************
// void TSYS01_reset(void)
// Reset the TSYS01 sensor IC
//*********************************************************************
void TSYS01_reset(void) //reset the TSYS01 IC
{
unsigned char data = 0;
data = SSPBUF; //read anything in buffer to clr buffer full status
IdleI2C(); //wait until I2C bus is idle
StartI2C(); //send start
WriteI2C(0xEE); //write address of TSYS01 = 0xEE
IdleI2C();
WriteI2C(0x1E); //write reset command 0x1E to I2C slave
IdleI2C();
StopI2C();
} //close of TSYS01_reset()
//rest of functions snipped for brevity