Build FAILED

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

Can you help me out with this message I'm a hardware guy doing software - thanks

                                                 

------ Build started: Project: ROBOTROL, Configuration: Debug AVR ------

Build started.

Project "ROBOTROL.cproj" (default targets):

Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').

Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "H:\Robotrol\ROBOTROL_1023_PM\ROBOTROL\ROBOTROL.cproj" (target "Build" depends on it):

Task "RunCompilerTask"

Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils

C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 4 --output-sync 

Building target: ROBOTROL.elf

Invoking: AVR/GNU Linker : 5.4.0

src/main.o: In function `main':

H:\Robotrol\ROBOTROL_1023_PM\ROBOTROL\src\main.c(37,1): error: multiple definition of `main'

main.o:H:\Robotrol\ROBOTROL_1023_PM\ROBOTROL\Debug/.././main.c:94: first defined here

Disabling relaxation: it will not work with multiple definitionscannot find -lspi.hcannot find -lspi.ccollect2.exe(0,0): error: ld returned 1 exit status

make: *** [ROBOTROL.elf] Error 1

"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -o ROBOTROL.elf  main.o src/ASF/mega/boards/stk600/rcx_x/init.o src/main.o   -Wl,-Map="ROBOTROL.map" -Wl,--start-group -Wl,-lm -Wl,-lspi.h -Wl,-lspi.c  -Wl,--end-group -Wl,-L"C:\Users\121776\AppData\Local\Microsoft\Windows\INetCache\IE\024VA9JK" -Wl,-L"C:\Users\121776\AppData\Local\Microsoft\Windows\INetCache\IE\869TXY3E" -Wl,-L"C:\Users\121776\Downloads\avr-spi-20100224\spi"  -Wl,--gc-sections -mmcu=atmega328 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328" -Wl,--relax  

H:\Robotrol\ROBOTROL_1023_PM\ROBOTROL\Debug\Makefile(151,1): error: recipe for target 'ROBOTROL.elf' failed

The command exited with code 2.

Done executing task "RunCompilerTask" -- FAILED.

Done building target "CoreBuild" in project "ROBOTROL.cproj" -- FAILED.

Done building project "ROBOTROL.cproj" -- FAILED.

 

Build FAILED.

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========


/* robotrol10_23.c
 *
 * Created: 10/23/2017 10:30:27 AM
 * Author : 121776
 */
//#include <spi.h>
#include <avr/io.h>
#include<avr/interrupt.h>
#include <stdint.h>
#include "C:\Users\121776\Downloads\avr-spi-20100224\spi\spi.h"

#define false 0
#define true 1

#define DAC_SETUP  8
#define busWrtADC PC5								//pin 28
#define busWrtDAC PC4								//pin 27
# define ADC0_SELECT PB2					//select for MCP3208  ch0-7	                       // commented out for debug - required in final version
# define ADC1_SELECT PB1							// pin 16 select for MCP3208  ch8-15
#define lowByte(w) ((w) & 0xff)
#define highByte(w) ((w) >> 8)

#define  DAC_SEL  8								// pin 14
#define  DAC_SEL_bit 0							// pin 14 when used as set and clr
#define IN  0B00000000
#define  OUT  0B11111111
#define PortC_Config 0B001111				//pins 27,28 input, 26,25,24,23 output
#define PortB_Config  0B101111				//?????????????
#define DACLO_REG  0
#define DACHI_REG  1
#define DAC_REF_INT  1
#define DESEL 7
#define mwr_ADC_LO_REG  4						//4 because of hardware decode
#define mwr_ADC_HI_REG 3						//3 because of hardware decode
#define ADC_CMD_REG  2
#define STATUS_REG 5
#define  PORT_SEL_DISABLE  7
#define STATUS_LED  3
#define InputBufferFull 2						//IBF bit position
#define OutBufferFull 0						//OBF bit position

#define DAC_UPDATE  3
#define FILLER_BYTE  0
//macros
#define  DAC_SEL_bit  0
#define DAC_disable (PORTB |= (1<< DAC_SEL_bit))
#define DAC_enable (PORTB &=~ (1<< DAC_SEL_bit))

#define  ADC0_SEL  2														 //transfer complete return high both selects
#define  ADC1_SEL 1
#define  ADC1_disable (PORTB |= (1<<  ADC1_SEL))
#define  ADC1_enable (PORTB &=~ (1<< ADC1_SEL))


#define  ADC0_disable (PORTB |= (1<<  ADC0_SEL))
#define  ADC0_enable (PORTB &=~ (1<< ADC0_SEL))


//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; global;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
int g_stat_reg_val = 0;
int g_adc_msb = 0;
int g_adc_lsb = 0;

int adc_msb_array[16] = {};
int adc_lsb_array[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

int dac_msb_array[8] = {};
int dac_lsb_array[8] = {};

//************************* volatile dec *******************************************
volatile int v_adc_flag = false;
volatile int v_dac_flag = false;
volatile int v_adc_ch;
volatile int  v_dac_hi_reg;
volatile int  v_dac_lo_reg;
volatile uint8_t previous_pin_state = 0xFF;     // default is high because the pull-up

// function prototypes

int  micro_rd_data_reg(int reg);       //reads a int from register specified
void micro_wrt_data_reg (int reg, int wrt_value);         //writes a int to register specified
void config_DAC(void);										//configure ad5628
unsigned int readADC(int channel);
void SPI_MasterInit(void);
void SPI_MasterTransmit(char cData);

int main(void)
  {


// ******************************* SETUP RUN ONCE****************************

	UCSR0B = 0;														//disable uart pin 2,3 -cannot use Port D unless this is run

	DDRD = IN;
	DDRC = PortC_Config;											//enable input on pin 24, 25
	DDRB = PortB_Config;
	PORTB|= (1<<DAC_SEL_bit);						   			//init to inactive state
	PORTB|= (1<<ADC0_SEL);
	PORTB|= (1<< ADC1_SEL);

	PORTC|=(1<<busWrtADC);							//INTERRUPT  PIN ADC COMMAND - set pull on
	PORTC|=(1<<busWrtDAC);							//INTERRUPT  PIN DAC COMMAND

	int junk = micro_rd_data_reg(DACLO_REG);					// CLEAR DAC IS FF
	junk = micro_rd_data_reg(ADC_CMD_REG);					// CLEAR DC IS FF
	PORTC = PORT_SEL_DISABLE;
	g_stat_reg_val = 0;												 //obf must be 1 to start
	g_stat_reg_val |= OutBufferFull;
	micro_wrt_data_reg(STATUS_REG, g_stat_reg_val);

	DAC_disable ;                          // disable DAC

	//SPISettings settings(SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE0);
	setup_spi(SPI_MODE_0, SPI_MSB, SPI_NO_INTERRUPT, SPI_MSTR_CLK16);

	//pin interrupts
	PCICR |= 0b00000010;				// turn on port c					// set PCIE0 to enable PCMSK0 scan
	PCMSK1 |= 0b00110000; 				// set int on pin 27,28


	TCNT1 = 63974;   // for 1 sec at 16 MHz
	TCCR1A = 0x00;
	TCCR1B = (1<<CS10) | (1<<CS12);				// Timer mode with 1024 prescaler
	TIMSK0 = (1 << TOIE1) ;   // Enable timer1 overflow interrupt(TOIE1)
	sei();

send_spi(0xFF);

		//^^^^^^^^^^^^^^^^^^^^^^^^^^^ main loop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 while (1)
			{

			int  dac_lo = 0, dac_ch = 0, dac_hi = 0;
			unsigned int temp1 = 0;
			unsigned int temp2 = 0;
			int adc_lsb,adc_msb;

			if (v_adc_flag == true){												//when new adc command written

					int index_ch = v_adc_ch & 0x0f;
					adc_lsb = adc_lsb_array[index_ch];                              // array written by timer task
					adc_msb = adc_msb_array[index_ch];
					micro_wrt_data_reg(mwr_ADC_HI_REG, adc_msb);
					micro_wrt_data_reg(mwr_ADC_LO_REG, adc_lsb);
					g_stat_reg_val |= OutBufferFull;                                          //data available
					micro_wrt_data_reg(STATUS_REG, g_stat_reg_val);
					v_adc_flag = false;													// process by setting v_adc_flag to true
					int junk = micro_rd_data_reg(ADC_CMD_REG);
			}
			// if dac status flag is TRUE the InputBufferFull flag is set  micro writes dac value from int routine into AD5628 chip
			//	, clears when done InputBufferFull*/

			if (v_dac_flag == true){

				dac_ch = v_dac_lo_reg & 0x07;
				dac_hi = v_dac_hi_reg >> 4;                                  //         DA11, DA10, DA9, DA8, DA7, DA6, DA5, DA4->X, X, X, X, DA11, DA10, DA9, DA8
				temp1 = v_dac_lo_reg >> 4;                                                              //        DA3, DA2, DA1, D0, X, X, X, X -> X, X, X, X, DA3, DA2, DA1, D0
				temp2 = (v_dac_hi_reg & 0x0f) << 4;							//		 DA11, DA10, DA9, DA8, DA7, DA6, DA5, DA4   ->   DA7, DA6, DA5, DA4, X, X, X, X
				dac_lo = temp2 | temp1;										//		 DA7, DA6, DA5, DA4, DA3, DA2, DA1, D0

				dac_lsb_array[dac_ch] = dac_lo;
				dac_lsb_array[dac_ch] = dac_hi;

			}

			//OutBufferFull flag  is cleared then the micro writes adc value byte hi and lo  from int routine into reg adchi and adc lo
			//then sets the OutBufferFull flag indicating new data available

			}

  }

		//++++++++++++++++++++++++++++++ functions start here ++++++++++++++++++++++++++++

	
	int micro_rd_data_reg(int reg)         //reads a int from register specified
		{

			int rd_val = 0;
			DDRD = IN;								//set port D 1 to 8 as input
			PORTC = reg & 7;							//SELECT PORT - LOW
			//delayMicroseconds(5);					//ok
			rd_val = PIND;							// input data
			PORTC = PORT_SEL_DISABLE;       	//de SELECT PORT - HIGH
			return rd_val;
		}

	void micro_wrt_data_reg (int reg, int wrt_value)         //writes a int to register specified

		{
			DDRD = OUT;							//set port D 1 to 8 as output
			PORTD = wrt_value;					// output  data
			PORTC = reg & 7;							//SELECT PORT - LOW
			//delayMicroseconds(5);					//ok
			PORTC = PORT_SEL_DISABLE;       	//de SELECT PORT - HIGH
		}

		//********************** write to  ad5628 dac  channel*************************************************************************
		// output is 2 x 2.5v internal reference x ( xxxx dac hi value and dac lo) or 5v fullscale.
		//	On board hardware multiplies  by 2 for 5v full scale.

		void wrt_dac(int dac_ch,int dac_lo,int dac_hi )
		{
			//int dac_ch,dac_lo,dac_hi;
			int address_value = 0;
								// pin 14 when used as set and clr
			// in case SPI port was modified by an analog read.
			address_value = ((dac_ch << 4) | dac_hi);                          // combining the channel and high byte changed from + to |

			DAC_enable;
			// delayMicroseconds(5);
			send_spi(DAC_UPDATE);            //3
			send_spi(address_value);
			send_spi(dac_lo);
			send_spi(FILLER_BYTE);      //00
			DAC_disable ;
		}

		//=======================configure  ad5628 dac 8 ch  =========================================================

	void config_DAC(void)
		 {
			DAC_enable;
			send_spi(DAC_SETUP);
			send_spi(FILLER_BYTE);
			send_spi(FILLER_BYTE);
			send_spi(DAC_REF_INT);      // to use internal ref.
			DAC_disable;
	}


/************************        improved read_adc********************************/
unsigned int readADC(int channel)                                                        //change to byte 8 11 not tested
		//returns uint formatted x,x,x,x,x,d11,d10,d9,d8,d7,d6,d5,d4,d3,d2,d1,d0
		//Hardware /2 for 5v fullscale =4095.    i.e.10v to 5v
		//10v fs /2 = 5 =4095

		{
			/*	Byte I
			In this byte the Master Writes a bit sequence as shown below
			’0? ’0? ’0? ’0? ’0? ’1? ‘S’ ‘D2?
			Where S is the bit which selects single ended operation.  this bit must be 1.
			Byte II
			In this byte MASTER Writes the following sequence
			‘D1? ‘D0? ‘X’ ‘X’ ‘X’ ‘X’ ‘X ‘X’
			Where D2, D1, D0 selects the input channel.
			Byte III is xxxxxxxx don't care
			*/
			int adc_msb, adc_lsb, int2;
			unsigned int adc_word;

			if (channel < 8){
				ADC0_enable;		//Select the Connected MCP3208 0 by pulling _CS_PIN_ LOW. ch 0 -7
			}
			else{
				channel -= 8;                                           //convert ch 8 -15 to 0 to 7
				ADC1_enable ;			//Select the Connected MCP3208 1 by pulling _CS_PIN_ LOW. ch 8-15
			}

			int2 = 0;								/* determine int 1 based on ch*/

			if (channel > 3){
				send_spi(0B00000111);				//set D2 value high int 1 required by mcp3208
			}
			else{
				send_spi(0B00000110);
			}
			int2 = channel << 6;
			adc_msb = send_spi(int2);			 //Transfers 2nd int from MCU to MCP3208 which returns  MSB of the read data.
			adc_lsb = send_spi(0);					//Transfers 3rd int from MCU to MCP3208 which returns  LSB of the read data. don't care

			adc_word = ((adc_msb << 8) & 0x0f) | adc_lsb;

			ADC0_disable;                //transfer complete return high both selects
			ADC1_disable;

			return adc_word;
		}
		// Initialize SPI Master Device (without interrupt)

		void spi_init_master (void)
			{
			// Set MOSI, SCK as Output
			DDRB = (1<<5)|(1<<3);

			// Enable SPI, Set as Master
			//Prescaler: Fosc/16, Enable Interrupts
			SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
			}
	//Function to send and receive data for both master and slave

		//Function to send and receive data for both master and slave
		unsigned char send_spi (unsigned char data)
		{
			// Load data into the buffer
			SPDR = data;

			//Wait until transmission complete
			while(!(SPSR & (1<<SPIF) ));

			// Return received data
			return(SPDR);
		}


		//++++++++++++++++++++++++++++++ end  functions ++++++++++++++++++++++++++++

		//******************** INTERRUPT  ROUTINES ***********************************

		// when remote computer writes to BASE+  2 this routine will  grab the adc ch info adn set the v_adc_flag to true
		// reading ADC_CMD_REG resets the hardware FF


		// when remote computer writes to BASE+ 0 this routine will  grab the dac low reg and dac high reg info
		//info and set the v_dac_flag to true, DAC HI int must be written by host before Lo int since low int trigger timer_task_ timer_task_adc_converts int

		ISR (PCINT1_vect){
		uint8_t changedbits;
        changedbits	= PINC ^ previous_pin_state;

		if (changedbits ==0b010000){
											//DAC COMMAND

				v_dac_lo_reg = 0;
				DDRD = IN;									//set port D 1 to 8 as input
				PORTC = DACLO_REG;							//SELECT PORT - LOW
				v_dac_lo_reg = PIND;							// input data
				PORTC = PORT_SEL_DISABLE;       	//de SELECT PORT - HIGH
				PORTC = DACHI_REG;
				v_dac_hi_reg = PIND;
				PORTC = PORT_SEL_DISABLE;       	//de SELECT PORT - HIGH */
				v_dac_flag = true;
				}

				if (changedbits == 0b100000){						//ADC COMMAND

				v_adc_ch = 0;									//clear old data
				g_stat_reg_val = g_stat_reg_val & (~ OutBufferFull);                                    // data not ready
				micro_wrt_data_reg(STATUS_REG, g_stat_reg_val);
				DDRD = IN;
				PORTC = ADC_CMD_REG;
				v_adc_ch = PIND;								//ch is lower 4 ints
				PORTC = PORT_SEL_DISABLE;       			//de SELECT PORT - HIGH */
				v_adc_flag = true;							//valid write from PC to addr 122 or 182h starts the a/d
				// process by setting v_adc_flag to true
				}
		}

		/******************************************** end of code***************************************/

		/*faster code  remove delay too                                   */
		/*		int dac[] = { DAC_UPDATE, address_value, dac_lo_byte, FILLER_BYTE };

		bitClear(PORTB, DAC_SEL_bit);
		for (int i = 0; i < 4; i++){
		send_spi(dac[i]);
		// delayMicroseconds(5);
		}
		*/

		// scheduler

		ISR (TIMER0_OVF_vect)
		{   // Timer1 ISR

			int timer_tick;
			int adc_channel;
			int dac_channel;

			timer_tick++;							//increment the clock tick, rollover at 255

			switch (timer_tick)
			{
			//case 30: PORTC ^= (1 << PC3);

				case 60:
						++adc_channel;
						if (adc_channel > 15){							//cycle thru adc channels
						adc_channel = 0;
						}
						unsigned int adc_word = readADC(adc_channel);
						adc_word <<= 4;
						adc_msb_array[adc_channel] = highByte( adc_word);
						adc_lsb_array[adc_channel] = lowByte(adc_word) | adc_channel;
						break;

				case 90: if ( dac_channel > 6){
						dac_channel = 0;

						g_stat_reg_val |= InputBufferFull;								// NOT READY
						micro_wrt_data_reg(STATUS_REG, g_stat_reg_val);					 //set buffer full flag

						int dac_lsb = dac_lsb_array[v_adc_ch & 0x0f];
						int dac_msb = dac_msb_array[v_adc_ch & 0x0f];
				 		wrt_dac(dac_channel, dac_msb, dac_lsb);
				}
			}
		}

 

Last Edited: Thu. Oct 26, 2017 - 11:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. The errors you get are not the same as those in the original post, so your problem probably has little or nothing in common with the original post. You should have started a new thread.

 

2. You show a file robotrol10_23.c , but the error messages are referring to a file main.c. In fact, in your complete build output there seems to be no mention at all of a file robotrol10_23.c .

 

3. The linker reports that you have two definitions (implementations) of the function main():

src/main.o: In function `main':

H:\Robotrol\ROBOTROL_1023_PM\ROBOTROL\src\main.c(37,1): error: multiple definition of `main'

main.o:H:\Robotrol\ROBOTROL_1023_PM\ROBOTROL\Debug/.././main.c:94: first defined here

There are two definitions of main(), apparently in two different files (in different directories) both named main.c;

H:\Robotrol\ROBOTROL_1023_PM\ROBOTROL\src\main.c

H:\Robotrol\ROBOTROL_1023_PM\ROBOTROL\main.c

 

Both files are (presumably) added to your project. You probably want only one of those.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Thanks for the quick response I'll fix that and be more careful where I post in the future.