AnalogReference (EXTERNAL) undeclared?

  • Thread starter Thread starter CognitiveNet
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on an issue with the Arduino code where the constant EXTERNAL is reported as undeclared when attempting to set the analog reference voltage using analogReference(EXTERNAL). The user is likely missing the necessary include file that defines EXTERNAL. To resolve this, ensure that the appropriate libraries for the Teensy platform are included in the code.

PREREQUISITES
  • Familiarity with Arduino programming and syntax
  • Understanding of analog input and output concepts
  • Knowledge of Teensy microcontroller architecture
  • Experience with including libraries in C/C++ code
NEXT STEPS
  • Research the Teensyduino library and its documentation
  • Learn about the analogReference() function and its parameters
  • Explore how to include external libraries in Arduino sketches
  • Investigate common issues related to undeclared constants in C/C++
USEFUL FOR

Arduino developers, Teensy users, and anyone troubleshooting analog input issues in embedded systems programming.

CognitiveNet
Messages
50
Reaction score
1
Hi! I'm trying to read the voltage( from ARef I assume) by using analogRead.
I've set analogReference to EXTERNAL, and I'm doing this in main.
Yet, I'm told that EXERNAL is undeclared. What am I doing wrong?

#include<avr/io.h>
#include<teensy_pins.h>
#include<timer0.h>
#include<util/delay.h>
#define CPU_PRESCALE(n)(CLKPR=0x80,CLKPR=(n))
#define CPU_16MHz 0x00

int main(void)
{
CPU_PRESCALE(CPU_16MHz);

// Initialize DDR
DDRC = 0x0e; // Output (Lamp Status) (Sets output to 3 pins)
DDRD = 0x00; // Input (Switch Status)

// Initialize PORT
PORTD = 0xff;
--------------------------------------------------------------------------
int analogInput = 0;
int analogAmount = ;

void setup()
{
analogReference(EXTERNAL); // use AREF for reference voltage
}


while(1)
{

analogAmount = analogRead(analogInput);

//--------------------- D4 ---------------------
if (!(PIND & 0x10))
{
PORTC = 0x0e;
_delay_ms(250);
PORTC = 0x00;
_delay_ms(250);
}
//--------------------- D5 ---------------------
if (!(PIND & 0x20))
{
PORTC = 0x0e;
}
else
{
PORTC = 0x00;
}
//----------------------------------------------
}
}
 
Technology news on Phys.org
I wrapped your code in [ code ] [ /code ] tags (without the spaces) so that your indentation is preserved. When you post code, you should do that, too.
CognitiveNet said:
Hi! I'm trying to read the voltage( from ARef I assume) by using analogRead.
I've set analogReference to EXTERNAL, and I'm doing this in main.

Yet, I'm told that EXERNAL is undeclared. What am I doing wrong?
Is EXTERNAL a macro with a value, or are you trying to tell the compiler that analogReference is a function that is defined in an external file.

It's possible that you are missing the include file that defines EXTERNAL.
CognitiveNet said:
Code:
#include<avr/io.h>
#include<teensy_pins.h>
#include<timer0.h>
#include<util/delay.h>
#define CPU_PRESCALE(n)(CLKPR=0x80,CLKPR=(n))
#define CPU_16MHz 0x00

int main(void)
{
	CPU_PRESCALE(CPU_16MHz);

	// Initialize DDR
	DDRC = 0x0e; // Output 	(Lamp Status)	(Sets output to 3 pins)
	DDRD = 0x00; // Input	(Switch Status)

	// Initialize PORT
	PORTD = 0xff;
	--------------------------------------------------------------------------
        int analogInput = 0;
	int analogAmount = ;

	void setup()
	{
	analogReference(EXTERNAL); // use AREF for reference voltage
	}
	

	while(1)
	{

		analogAmount = analogRead(analogInput);

		//--------------------- D4 ---------------------
		if (!(PIND & 0x10))
		{
		PORTC = 0x0e;
		_delay_ms(250);
		PORTC = 0x00;
		_delay_ms(250);
		}
		//--------------------- D5 ---------------------
		if (!(PIND & 0x20))
		{
			PORTC = 0x0e;
		}
		else
		{
		PORTC = 0x00;
		}
		//----------------------------------------------
	}
}