error: undefined reference to function call

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

Hi all,

I am having a few header problems. When I declare setup(); in main.c, the functions in main.c cannot see the header files in .h file.

These are the errors I am getting when compiling. Can you see any obvious things I have missed?

 

I am currently using Amtel Studio 6.2 and the ATmega328P.

error 1) undefined reference to `assign_channel'

error 2) undefined reference to `write_single_byte'

error 3) undefined reference to `write_single_byte'

error 4) undefined reference to `initialize_serial'

error 5) undefined reference to `initialize_spi'

error 6) undefined reference to `convert_channel'

error 7) undefined reference to `read_voltage_or_resistance_results'
error 8 ) undefined reference to `read_temperature_results'

Below is main.c and the .h file.

Many Thanks, Tuurbo46

 


// main.c


#include <avr/io.h>
#include <stdint.h>
#include <stdbool.h>
#include "stdio.h"
#include "math.h"

#include "LTC2983_configuration_constants.h"
#include "LTC2983_support_functions.h"
#include "LTC2983_table_coeffs.h"

typedef signed char  byte;      
typedef int          boolean;

// Function prototypes
void configure_channels();
void configure_global_parameters();


// -------------- Configure the LTC2983 -------------------------------
void setup() {
	initialize_serial();
	initialize_spi();
	
	configure_channels();
	configure_global_parameters();
}

void configure_channels() {
	byte channel_number; 
	long channel_assignment_data;
	
	// ----- Channel 1: Assign RTD PT-100 -----
	channel_assignment_data =
	(long) SENSOR_TYPE__RTD_PT_100 |
	(long) RTD_RSENSE_CHANNEL__NONE |
	(long) RTD_NUM_WIRES__4_WIRE |
	(long) RTD_EXCITATION_MODE__ROTATION_SHARING |
	(long) RTD_EXCITATION_CURRENT__5UA |
	(long) RTD_STANDARD__AMERICAN;
	 assign_channel(1, channel_assignment_data);

}

void configure_global_parameters() {
	// -- Set global parameters
	write_single_byte(0xF0, TEMP_UNIT__C |
	REJECTION__50_60_HZ);
	// -- Set any extra delay between conversions (in this case, 0*100us)
	write_single_byte(0xFF, 0);
}

// -------------- Run the LTC2983 -------------------------------------
int main(void) {
	setup();
	float temperature_result;
	byte channel_number; 
		
	int channels_to_measure[] = {1};
	int num_measured_channels = sizeof(channels_to_measure)/sizeof(channels_to_measure[0]);

	
	for (int i = 0; i < num_measured_channels; i++) {
		channel_number = channels_to_measure[i];
		convert_channel(channel_number);

		read_voltage_or_resistance_results((channel_number)); // removed int
		read_temperature_results((channel_number));           // removed int

	}

}

 

// header file.h

#ifndef LTC2983_SUPPORT_FUNCTIONS_H_
#define LTC2983_SUPPORT_FUNCTIONS_H_

#include "LTC2983_table_coeffs.h"

typedef signed char  byte;      
typedef int          boolean;

void initialize_serial();
void initialize_spi();

void write_custom_table(struct table_coeffs coefficients[64], long start_address, long table_length);
void write_custom_steinhart_hart(long steinhart_hart_coeffs[6], long start_address);
void write_single_byte(long start_address, int single_byte);
void initialize_memory_write(long start_address);
void write_coefficient(long coeff, int bytes_in_coeff);
void finish_memory_write();
void initialize_memory_read(long start_address);
void finish_memory_read();
void convert_channel(byte channel_number);
boolean conversion_done();

float read_temperature_results(int channel_number);
float read_direct_adc_results(int channel_number);
void get_raw_results(long base_address, int channel_number, unsigned char results[4]);
float convert_to_signed_float(unsigned char results[4]);
float get_temperature(float x);
float get_direct_adc_reading(float x);
void print_temperature_result(int channel_number, float temperature_result);
void print_direct_adc_reading(int channel_number, float direct_adc_reading);
void print_fault_data(unsigned char fault_byte);
bool is_number_in_array(int number, int *array, int array_length);

// -------------- Some raw data result...
float read_voltage_or_resistance_results(int channel_number);
float convert_vr_to_signed_float(unsigned char results[4]);
float get_voltage_or_resistance(float x);
void print_voltage_or_resistance_result(int channel_number, float voltage_or_resistance_result);


#endif

 

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

 

Undefined ref. means you haven't added the C file(s) that provide those functions to the list of C files in the project. It's not enough to simply #include the header files (though you must do that too).

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

main.c, all headers.h and .cpp are in the libraries folder. 

 

The .cpp file works with the header.  In a dumb way does Amtel Studio 6.2 not support .cpp files, or is this file in the wrong place.

 

Thanks for your help.

 

 

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

 

I  already told you what's wrong and how to fix it. Which bit of my answer didn't you understand?

hint: just putting the files in the same directory does NOT add them to the list of files to be compiled and linked.

 

 

 

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

The code looks like a mix of Arduino and common C/C++.

The Arduino IDE scans all the source, finds/includes the necessary libraries in source form, builds the function prototoypes, etc. It's weird.

 

I think your build config lacks the inclusion of the .a libraries for pre-compiled functions you are trying to use.  Not sure where these would come from, sans Arduino's IDE.

 

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

Hi Stevech,

 

Well spotted on the Arduino part.  The sensor is connected to an Arduino developement board.  But now I want to put it on my standard ATmega328P chip.  So I am struggling but slow moving it accross now.

 

Thanks for your help.

 

 

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

You can burn the arduino code onto a mega328. The only 'magic' the arduino uses is the boot loader - and that is not needed if you have a isp programmer.