problem in running a code

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

any help! i'm using avr gcc and avr studio 4!

when i run the this code, it gives the error:
undefined reference to `adc_init'
the code

#include "main.h"
#include "adc.h"

int main()
{
	initialize();

	while(1)

	{
	}
}

void initialize(void)
{
	adc_init();//initialize adc
        sei();//enable global interrupts

}

and i have defined these:
main.h

#include 
#include 
#include 




void initialize(void);

adc.h


//function declaration
void adc_init(void);

and adc.c

#include "main.h"
#include "adc.h"



void adc_init(void)
{
	//select reference voltage
    //AVCC with external capacitor at AREF pin
	ADMUX |= (1<<REFS0);

    //enable ADC with dummy conversion
	ADCSRA |= (1<<ADEN)|(1<<ADIE);	
    
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to declare adc_init as external in adc.h, e.g.

extern void adc_init(void);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Compiles ok for me. (You don't need extern on a function prototype).

I would guess adc.c is not being compiled for some reason. If I remove adc.c from the project, I can duplicate your error message.

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

Looks like the linker is not including adc.o. Check your makefile....

C: i = "told you so";

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

curtvm wrote:
Compiles ok for me. (You don't need extern on a function prototype).

I would guess adc.c is not being compiled for some reason. If I remove adc.c from the project, I can duplicate your error message.


what have you done?

You need to declare adc_init as external in adc.h, e.g. 
Code:
extern void adc_init(void);

it can't compile successfully even when i have declared with extern.

Looks like the linker is not including adc.o. Check your makefile....

how do i check my makefile

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

Quote:
i'm using avr gcc and avr studio 4
maybe you forgot to add the adc.c file to the project (it should be listed in the Source Files folder on the left in avr studio).

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

Quote:
maybe you forgot to add the adc.c file to the project (it should be listed in the Source Files folder on the left in avr studio).

that was the problem, it compiles ok now!
thanks a lot and keep it up!