compilation error

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

please take a look at this 5 file I can't figure out what the error is

atmel studio gives me an error conflicting types for lfsr.

guys pleaseeeee help me out 

this is lfsr.h

#ifndef LFSR_H 
#define LFSR_H

#include "adc.c"

uint16_t lfsr;
lfsr = ADC_GetOneValue();

void LFSR_Iterate(void);

#endif

this is lfsr.c

#include "lfsr.h"

void LFSR_Iterate()
{
	uint16_t xor_poly = 0x002C & lfsr;
	xor_poly = ((xor_poly >> (15 - 10)) ^ (xor_poly >> (15 - 12)) ^ (xor_poly >> (15 - 13)) ^ (xor_poly >> (15 - 15)) << 15);
	lfsr = lfsr >> 1;
	lfsr = xor_poly | lfsr;
}

this is adc.h

#ifndef ADC_H
#define ADC_H
 
inline uint16_t ADC_GetOneValue(void);

#endif

this is adc.c 

#include "adc.h"

inline uint16_t ADC_GetOneValue()
{
	ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
	
	while (!((1 << ADIF) & ADCSRA));
	
	ADCSRA = 0;
	
	return ADC;
}

this is main.c

/*
 * oled lcd.c
 *
 * Created: 24-02-2020 18:10:18
 * Author : jeet
 */ 
#define F_CPU 16000000UL


#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "lfsr.c"
#include "oled.c"


int main(void)
{
	OLED_Initialize();
	
	sei();
	
	int8_t arr[10][2] = {{0,0},{0,127},{63,127},{63,0},{0,0}};
	//OLED_DrawPolygon(arr,4);
	
	
	while (1)
	{
		LFSR_Iterate();
		OLED_ClearScreen();
		OLED_PrintLongInteger(lfsr,0);
		OLED_Render();
		_delay_ms(1000);
	}
	
}

i know the error is at the 7th line of lfsr.h

Attachment(s): 

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

jeet55 wrote:

#include "adc.c"

I stopped reading at that point. Not only are you including .c files but you appear to be doing it in a .h file?!?

 

(ask yourself what happens if that .h file then gets included in more than one other .c file!!)

 

In the tutorial forum there is an article about "managing large projects" which talks about how to split code across multiple C files. Suggest you familiarize yourself with that!

 

PS can you confirm if you are using Studio 7? If you are I'll make a project with these things correctly connected together and no #include's of .c files.

Last Edited: Thu. Jul 2, 2020 - 02:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jeet55 wrote:

#include "adc.c"

don't include c files in your headers!

jeet55 wrote:

lfsr = ADC_GetOneValue();

don't put code in headers, put code in c files!

There is a tutorial about managing large projects in the tutorial forums here.  This is normal C stuff, not related to AVR's!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

clawson has already pulled you up on #including .c files - in your previous thread:

 

https://www.avrfreaks.net/commen...

 

and the next post there: https://www.avrfreaks.net/commen...

 

So time to read those linked articles, and put it into practice!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jeet55 wrote:
atmel studio gives me an error ...

See https://www.avrfreaks.net/commen... for how to read and interpret an error message from GCC

 

Also see https://www.avrfreaks.net/commen... for how to use the 'Output' window of Atmel Studio to get the full error messages - rather than the unhelpful 'Error List'

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

OK I took a punt on AS7 being available so attached is a project that builds. There was SO much wrong with the existing files that it was almost impossible to follow what you were trying to achieve (and it wasn't helped by your omission of oled.c and oled.h !) so I had to make some assumptions about things.

 

What I've tried to do is make sure the .h files only have declarations and there is ONE implementation (definition) of everything required in one of the .c files

 

As noted above you actually had 'lfsr' defined in a .h file but then had a call to an ADC function to set it outside the body of any function. So I have made an assumption that this is something you planned to put into the while(1) loop in main before each call to LFSR_Iterate()

 

Two things this does tell me though:

 

1) you only have a very distant grasp of the C programming language. You need to learn the core language first. Don't attempt to do this on an AVR - do it in the comfort and luxury of a PC environment (Visual Studio maybe?) where you have easy access to things like printf() to try stuff out

 

2) you seem to write software by just throwing code at your editor and then trying to work out afterwards how to glue it all together. This is the wrong approach to software engineering - you need to spend some time in a DESIGN PHASE working out how you plan for parts of the system to interact and what each subsection's function will be. Then you write the sub-sections ("modules") and test each in turn and when you have some "solid bricks" to build on you can create the overall final design. 10 minutes of thought up front can save hours of trying to unwind the knots and dig you out of the holes you otherwise create by trying to write code without a clear overall picture of what you are trying to achieve.

 

EDIT: oh yeah, the attachment...

Attachment(s): 

Last Edited: Thu. Jul 2, 2020 - 03:13 PM