Problem eingene Inlude / Own problems include

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

Hallo Leute,

ich habe von meinen Microchip Studio Projekt erstellt und habe einen Include erstellt (Header-Datei und C-Datei). Nach Kompilieren kommt eine Fehlermeldung die ich nicht weis was der Fehler ist.

Könnt ihr mir helfen?

 

Grüße

Patrick Dreger

 

-----------------------------------------------------------------

Hi guys,
I have created from my Microchip Studio project and have created an include (header file and C file). After compiling comes an error message which I don't know what the error is.
Can you help me?

Greetings
Patrick Dreger

 

Error-Code

Severity    |Description	                                    |Line   |Column
Error	    |invalid operands (*UND* and *UND* sections) for `/'    |29	    |1
Error	    |invalid operands (*UND* and *UND* sections) for `|'    |53	    |1
Error	    |recipe for target 'Includes/I2C_Master.o' failed	    |82	    |1

OUTPUT:
------ Build started: Project: Leuchtmitteltester, Configuration: Debug AVR ------
Build started.
Project "Leuchtmitteltester.cppproj" (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 "E:\Microchip Studio\Leuchtmitteltester\Leuchtmitteltester\Leuchtmitteltester.cppproj" (target "Build" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrGCC.dll".
	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 8 --output-sync
		Building file: ../Includes/I2C_Master.c
		Invoking: AVR8/GNU C Compiler : 5.4.0
		C:\Users\PATRIC~1\AppData\Local\Temp\ccs5r0nb.s: Assembler messages:
C:\Users\Patrick Dreger\AppData\Local\Temp\ccs5r0nb.s(29,1): error: invalid operands (*UND* and *UND* sections) for `/'
C:\Users\Patrick Dreger\AppData\Local\Temp\ccs5r0nb.s(53,1): error: invalid operands (*UND* and *UND* sections) for `|'
		make: *** [Includes/I2C_Master.o] Error 1
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include"  -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega32 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega32" -c -std=gnu99 -MD -MP -MF "Includes/I2C_Master.d" -MT"Includes/I2C_Master.d" -MT"Includes/I2C_Master.o"   -o "Includes/I2C_Master.o" "../Includes/I2C_Master.c"
E:\Microchip Studio\Leuchtmitteltester\Leuchtmitteltester\Debug\Makefile(82,1): error: recipe for target 'Includes/I2C_Master.o' failed
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "Leuchtmitteltester.cppproj" -- FAILED.
Done building project "Leuchtmitteltester.cppproj" -- FAILED.

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

 

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

Welcome to AVRFreaks!

 

Seems that you have problem with text commenting.

 

Care on /*, perhaps.

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

Danke für den klaren Hinweis :-)

 

Mein I2C-Routine ist in Assembler geschrieben und will meine Befehle akzeptieren.

 

---------------------------------------

 

Thanks for the clear hint :-)

My I2C routine is written in assembler and wants to accept my commands.

 

void I2C_Init()
{
	asm("push r16");
	// Clock
	asm("ldi  r16, ((F_CPU / TWI_CLOCK)-16) / 2"); // <----- 
	asm("out  TWSR,R16");
	// TWI-Status-Register (Vorteiler)
	asm("ldi  r16,0");
	asm("ldi  r16,TWI_ADR");
	// Bus-Adresse
	asm("ldi  r16,TWI_ADR");
	asm("out  TWAR,r16");
	// Enable
	asm("ldi  r16,_TWINT | _TWEN"); // <-----
	asm("out  TWCR,r16");
	asm("pop  r16");
}

 

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


Zip the project and attach it to a post here. As grohote says the error is:

		C:\Users\PATRIC~1\AppData\Local\Temp\ccs5r0nb.s: Assembler messages:
C:\Users\Patrick Dreger\AppData\Local\Temp\ccs5r0nb.s(29,1): error: invalid operands (*UND* and *UND* sections) for `/'
C:\Users\Patrick Dreger\AppData\Local\Temp\ccs5r0nb.s(53,1): error: invalid operands (*UND* and *UND* sections) for `|'

but the thing is that the .c code you write is first pre-processed and macros and includes and such should all be expanded and comments removed. Then that is passed to the C compiler that generates an assembler source file (type .s) tat is then passed to the assembler. By this stage it should only contain avr-as opcodes and directives so it is kind of curious that errors are being reported at that stage.

 

One thing you can try is to find this option in the project settings:

 

 

and make sure it is ticked. Now when you build the ./Debug/ (could be ./Release/) directory for your project will contain files called I2C_Master.i and I2C_Master.s. The .i file is the code after it has been pre-processed and the .s is the asm source after it has been converted in to Assembler. The error messages say the problems are on lines 29 and 53 of that file.

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

You should tell us more about Project. As you are not setting TWBR seems that your M32 acts as a Slave.

 

What is in the other side, please.

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

It's probably NOT the issue but your Device Pack is hopelessly out-of-date. We're on 3.0.158 now. Update your ATmega_DFP pack and try again.

-I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include"

 

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

I have to admit that I think 1.6.364 is probably still the "current" one on my machine too blush

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

Ich hab etwas herum Experimentiert.

Das erste Problem ist I2C-Clock zu konfigurieren und I2C zu aktivieren.

------------------- ENGLISH ------------------------------------------------------------

I have been experimenting around a bit.
The first problem is to configure I2C clock and enable I2C.

asm("ldi  r16, ((F_CPU / TWI_CLOCK)-16) / 2");
asm("ldi  r16,_TWINT | _TWEN");

 

Ich habe jetzt die Routine geändert.

------------------- ENGLISH ------------------------------------------------------------

I have now changed the routine.

void I2C_Init()
{
	// Clock
	TWBR = ((16000000 / TWI_CLOCK) -16) /2;
	asm("push r16");
	// TWI-Status-Register (Vorteiler)
	asm("ldi  r16,0");
	asm("ldi  r16,TWI_ADR");
	// Bus-Adresse
	asm("ldi  r16,TWI_ADR");
	asm("out  TWAR,r16");
	// Enable
	TWCR = _TWINT | _TWEN;
	asm("pop  r16");
}

 

Trotzdem. Kann mir einer erklären wie so als Assembler-Funktion nicht an nimmt?

------------------- ENGLISH ------------------------------------------------------------

Nevertheless. Can someone explain to me how so as assembler function does not take?

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

Why on earth are you using asm() ? Surely the while point of C is you just write "REG = val" and C generates all the LDI's and OUT/ST's you need. What is to be gained by using asm() ?

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

Hold on, you really needs TWSR, do restore it back. TWBR, only in case it is a Master. Choose some value, for example: 10.

 

Why ASM, then?

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

Ich schreibe das erstmal mit AVR Mikrocontroller mit C/C++. Vorher habe ich mit Bascom-AVR entwickelt.

Durch meinen Display kann ich mit BASCOM-AVR nicht weiter nutzen.

Also möchte ich mein Projekt in C/C++ schreiben.

Die Funktionen für I²C habe aus einen Einsteigerbuch und ist nur in Assembler geschrieben.

Um es zu testet habe ich den Original-Code von Buch abgeschrieben. Um Assembler-Routinen zu nutzen, muss ich ASM() Funktion nutzen.

Am ende wenn I²C läuft und funktioniert, hätte ich es in C/C++ umgeschrieben.

 

Die Fertigen Codes die ich gefunden für C/C++, gibt es kein I²C-Timeout und Rückgabe für Acknowledge-Status.

 

----------------------------- ENGLISH --------------------------------------------------------------

 

I write this first with AVR microcontroller with C/C++. Before I developed with Bascom-AVR.
Because of my display I can't use BASCOM-AVR any more.
So I want to write my project in C/C++.
The functions for I²C I got from a beginners book and is written only in assembler.
To test it I copied the original code from the book. To use assembler routines I have to use ASM() function.
At the end when I²C is running and working, I would have rewritten it in C/C++.
The ready made codes I found for C/C++, there is no I²C timeout and return for acknowledge status.

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


If you are doing ASM, here is a place I used in the past...gives asm routines for I2C...worked out well, but it has been a while...

 

http://www.avrbeginners.net/

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

patrick_cpp wrote:
So I want to write my project in C/C++

 

Then do it!

 

Just checked my ASM file for I2C, it does have 170 lines of code ... no, you do not need ASM.

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

There are many examples of TWI code around. I would suggest starting with non-interrupt versions. This demonstrates that your electronics and understanding of the various chips is sound.
 

You can then transition to interrupt based routines if required.

Although you can use assembler… It is all quite possible in C/C++
 

Viel Glueck

regards
Greg

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

Hi guys,
I have rewritten my I2C routine in C.

This is my result:

 

I2C_Master.c

#include <avr/io.h>
#include <avr/iom32.h>
#include "../Clock.h"
#include "I2C_Master.h"

//------------------------------------------------------------------------
// I2C-Master initialisieren
//------------------------------------------------------------------------
void I2C_Init()
{
  // Clock
  TWBR=((F_CPU/TWI_CLOCK)-16)/2;
  // TWI-Status-Register (Vorteiler)
  TWSR=0;
  // Bus-Addr
  TWAR=TWI_ADR;
  // Enable
  TWCR=_TWINT|_TWEN;
}

//------------------------------------------------------------------------
// Start I2C (ohne Interrupt)
//------------------------------------------------------------------------
void I2C_Start()
{
  uint8_t x=TWCR;
  x&=_TWEN|_TWIE;         // nur Beibehalten von Enable und InterruptJ/N
  TWCR=x|_TWINT|_TWSTA;
  // warten bis fertig
  while( !(TWCR & _TWINT))
  {}
}

//------------------------------------------------------------------------
// Stop I2C (ohne Interrupt)
//------------------------------------------------------------------------
void I2C_Stop()
{
  uint8_t x=TWCR;
  x&=_TWEN|_TWIE;         // nur Beibehalten von Enable und InterruptJ/N
  TWCR=x|_TWINT|_TWSTO;
}

//------------------------------------------------------------------------
// Write Byte per TWI (ohne Interrupt)
// PE: val  = zu sendende Daten
//     ackn = wenn !=0 wird Acknowledge (=TWEA) gesetzt
//------------------------------------------------------------------------
uint8_t I2C_Write(uint8_t val, uint8_t ackn)
{
  TWDR=val;                // Daten bereitlegen
  // Befehl zusammenstellen
  uint8_t x=TWCR;
  x&=_TWEN|_TWIE;                //nur Beibehalten von Enable und InterruptJ/N
  x|=_TWINT;
  if(ackn)
  x|=_TWEA;        // evt. TWEA setzen, für Datenanforderung
  TWCR=x;                        // senden
  // warten bis fertig
  while( !(TWCR & _TWINT))
  {}
  return 0;
}

//------------------------------------------------------------------------
// Read Byte per TWI (ohne Interrupt)
// PE: ackn = wenn !=0 wird Acknowledge (=TWEA) gesetzt
// PA: Data
//------------------------------------------------------------------------
uint8_t I2C_Read(uint8_t ackn)
{
  // Befehl zusammenstellen
  uint8_t x=TWCR;
  x&=_TWEN|_TWIE;                //nur Beibehalten von Enable und InterruptJ/N
  x|=_TWINT;
  if(ackn)
  x|=_TWEA;        // evt. TWEA setzen, für Datenanforderung
  TWCR=x;                        // senden
  // warten bis fertig
  while( !(TWCR & _TWINT))
  {}
  return TWDR;
}

I2C_Master.h

#ifndef I2C_MASTER_H_
#define I2C_MASTER_H_
//-----------------------------------------------------------------------------
#define TWI_CLOCK 100000 // Geschwindigkeit des TWI-Busses
#define TWI_READ  0b00000001
#define TWI_WRITE 0b00000000
//-----------------------------------------------------------------------------
#define _TWINT    0b10000000
#define _TWEA     0b01000000
#define _TWSTA    0b00100000
#define _TWSTO    0b00010000
#define _TWWC     0b00001000
#define _TWEN     0b00000100
#define _TWIE     0b00000001
//-----------------------------------------------------------------------------
#define TWI_ADR   0x00

void I2C_Init(void);
void I2C_Start(void);
void I2C_Stop(void);
uint8_t I2C_Write(uint8_t val, uint8_t ackn);
uint8_t I2C_Read(uint8_t ackn);

#endif /* I2C_MASTER_H_ */

 

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

patrick_cpp wrote:

#define TWI_ADR   0x00

 

Do change it, address 0 is a special address called the "general call address." Any slave device on the bus can respond to this address.

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

I have changed TWR_ADR from 0x00 to 0x80 (128).

I use I2C only as master, it doesn't really matter. Only when I change as slave.

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

patrick_cpp wrote:
0x80

 

Now, this notorious problem of Address*2... It should be 127 (maximum) instead.