NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Basic Electronics » Temperature project unclear explanation of error in uncompiled code

July 19, 2011
by codenamejupiterx
codenamejupiterx's Avatar

I was doing the temperature project and I ran the code there were bugs but i got as many as I could out. There are still a couple and i am having trouble figuring out what they mean:

    make -C ../libnerdkits
    make[1]: Nothing to be done for `all'.
    avr-gcc -g -Os -Wall -mmcu=atmega168  -Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm -o              
     tempsensor.o tempsensor.c ../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o
      tempsensor.c: In function 'main':
       tempsensor.c:71: warning: implicit declaration of function 'lcd_unit'
       tempsensor.c:103: warning: implicit declaration of function 'lcd_write_init16'
        /var/folders/jQ/jQWh7bOj2RyQ3k+8ZONKx++++TI/-Tmp-//ccn77Z2P.o: In function `main':
       /Users/benjaminhall/Desktop/NerdKit Folder/Code/tempsensor_edu/tempsensor.c:71: undefined reference to           
      `lcd_unit'
      /Users/benjaminhall/Desktop/NerdKit Folder/Code/tempsensor_edu/tempsensor.c:103: undefined reference          
        to `lcd_write_init16'
      make: *** [tempsensor.hex] Error 1

What does implicit declaration mean? What does undefined reference mean?

all the errors seem to be either one of the two.......

July 20, 2011
by carlhako
carlhako's Avatar

Hi codenamejupiterx

I came across one of these errors for the first time the other day. "implicit declaration of function" I had this error when I forgot to put an open bracket when declaring a new function. In your case I suspect you are missing the following line

int main() {

Or you have left the { off. It could easily be something else its hard to tell without your full code. Could you please post all your code?

regards

Carl

July 20, 2011
by codenamejupiterx
codenamejupiterx's Avatar

Thanks for responding Carl. My code is posted below:

// tempsensor.c
// for NerdKits with ATmega168
// mrobbins@mit.edu

#define F_CPU 14745600

#include <stdio.h>
#include <math.h>

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/delay.h"
#include "../libnerdkits/lcd.h"
#include "../libnerdkits/uart.h"

// PIN DEFINITIONS:
//
// PC0 -- temperature sensor analog input

void adc_init() {
//set analog to digital converter
//to be enabled, with a clock prescale of 1/128
//so that the ADC clock runs at 115.2kHz.

ADMUX=0;
ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);

//fire a conversion just to get the ADC warmed up
ADCSRA |= (1<<ADSC);

}

uint16_t adc_read() {
//read from ADC, waiting for convsion to finish
//(assumed someone else asked for a conversion.)
//wait for it to be cleared
    while(ADCSRA & (1<<ADSC)){
    // do nothing ..just hold your breath
    }///end while
    ////bit is cleared so we have a result.

    /////read from the ADCL/ADCH registers, and combine the result
    //NOTE: ADCL must be read first (datasheet pp. 259)

    uint16_t result=ADCL;
    uint16_t temp=ADCH;
    result=result + (temp<<8);

    //set ADSC bit to get the *next* conversion started
    ADCSRA |= (1<<ADSC);

    return result; 
}//////end uint16_t

double sampleToFahrenheit(uint16_t sample) {

//conversion ratio in DEGREES/STEP:
//(5000 mV /1024 steps) * (1 degree / 10mV)
//   ^^^^^^^^^^^^             ^^^^^^^^^^^
//       from ADC              from LM34

return sample * (5000.0 / 1024.0 / 10.0);

}

int main() {
// start up the LCD
lcd_unit();
FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
lcd_home();

//start up the analog to digital converter
adc_init();

//start up serial port
uart_init();
FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
stdin = stdout=&uart_stream;

//holder variables for temperature data
uint16_t last_sample=0;
double this_temp;
double temp_avg;
uint8_t i;
while(1) {
// take 100 samples and average them!
temp_avg=0.0;
    for(i=0; i<100; i++) {
    last_sample = adc_read();
    this_temp= sampleToFahrenheit(last_sample);

    //add this contribution to the average
    temp_avg = temp_avg + this_temp/100.0;
    }/////end for loop

// write message to LCD
lcd_home();
lcd_write_string(PSTR(" ADC value:  "));
lcd_write_init16(last_sample);
lcd_write_string(PSTR("  of 1024    "));
lcd_line_two();
fprintf_P(&lcd_stream,  PSTR("Temperature:  %.2f"), temp_avg);
lcd_write_data(0xdf);
lcd_write_string(PSTR("F      "));

//write message to serial port
printf_P(PSTR("%.2f degrees F\r\n"), temp_avg);

}

return 0;
}
July 20, 2011
by bretm
bretm's Avatar

You wrote lcd_unit instead of lcd_init, and lcd_write_init16 instead of lcd_write_int16.

July 20, 2011
by codenamejupiterx
codenamejupiterx's Avatar

Thank You bretm!!!!!! I corrected the codeand loaded it onto the chip and my temperature sensor is working perfectly!!!!! Again Thanks!!!!

Post a Reply

Please log in to post a reply.

Did you know that first-order systems have a exponentially decaying response to step inputs? Learn more...