PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Include i2cmaster - Fehlermeldung 'I2C_BUF_SIZE' undeclared



schmitzens
02.01.2010, 18:06
Moin,

ich benutze das AVR Studio (4.18 ) und möchte nun in meinem Projekt mit
I2C arbeiten. Dankenswerterweise gibt es dazu ja die I2C Bibliothek von
Peter Fleury:

Diese habe ich mir nun heruntergeladen und in das WinAVR
Includeverzeichnis kopiert.

In meiner C-Datei steht nun unter anderem im Kopf:

#include <nibobee/usart.h>
#include <nibobee/motpwm.h>
#include <nibobee/analog.h>
#include <nibobee/odometry.h>
#include <nibobee/i2cmaster.h>
#include <nibobee/lcdi2c.h>
#include <avr/io.h>
#include <avr/interrupt.h>


Nur bringt mir AVR-Studio beim builden die folgende Fehlermeldung:

\..\..\..\Programme\NIBObeeLib\include/nibobee/i2cmaster.h:58: error: 'I2C_BUF_SIZE' undeclared here (not in a function)

Nachfolgend die i2cmaster.h:



/* BSD-License:

Copyright (c) 2007 by Nils Springob, nicai-systems, Germany

All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name nicai-systems nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

/*! @file i2cmaster.h
* @brief Routinen zur Kommunikation ueber den I2C Bus
* @author Nils Springob (nils@nicai-systems.de)
* @date 2007-07-13
*/

#ifndef NIBOBEE_I2CMASTER_H_
#define NIBOBEE_I2CMASTER_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif


/*!
* Anzahl der zu sendenden / zu empfangenden Zeichen
*/
extern volatile uint8_t i2c_size;


/*!
* Puffer zur Datenübertragung
*/
extern uint8_t i2c_buf[I2C_BUF_SIZE];

/*!
* I2C Status
*/
enum {
I2C_BUSY,
I2C_IDLE,
I2C_SUCCESS,
I2C_ERROR=0x10
};

/*!
* Initialisierung der I2C Schnittstelle
*/
void i2c_init(void);

/*!
* Start der Datenübertragung. Die Daten sind im @ref i2c_buf gespeichert
*/
uint8_t i2c_start_transmission(void);

/*!
* Hole den aktuellen I2C-Status
*/
uint8_t i2c_status(void);

extern volatile uint8_t i2c_last_TWSR;
extern volatile uint8_t i2c_pos;

/*!
* Warte bis Ãœbertragung beendet wurde
*/
uint8_t i2c_wait_transmission(void);

#define I2C_TX(ADDR) ((ADDR)<<1)
#define I2C_RX(ADDR) (((ADDR)<<1)+1)

#ifdef __cplusplus
} // extern "C"
#endif

#endif // NIBOBEE_I2CMASTER_H_

Kann mir jemand einen Tipp geben?

Gruß

BurningWave
02.01.2010, 20:23
Ich kann dir anhand deies Codeausschnittes nicht sagen, für was die Variable i2c_buf genau da ist, auf jeden Fall ist sie ein Array, dessen Größe mit dem Symbol I2C_BUF_SIZE definiert wird. Ich vermute, dass in ihr einfach zu sendende oder empfangene Daten gespeichert werden. I2C_BUF_SIZE musst du wahrscheinlich in deiner Hauptdatei, in der du die Header einbindest (vor #include) selbst definieren. Es kommt darauf an, wie groß deine Datenmengen sind. Probiere einfach mal #define I2C_BUF_SIZE 32 aus.

schmitzens
02.01.2010, 23:20
Ich habe nun wie vorgeschlagen die I2C Buffer Size definiert. Der Fehler ist nun weg, jedoch habe ich nun 5 neue!

c:50: undefined reference to `i2c_init'
c:51: undefined reference to `lcd_init'
c:52: undefined reference to `lcd_setBacklight'
c:131: undefined reference to `lcd_setCursor'
c:136: undefined reference to `lcd_setCursor'



#define I2C_BUF_SIZE 32

#include <nibobee/iodefs.h>
#include <nibobee/usart.h>
#include <nibobee/motpwm.h>
#include <nibobee/analog.h>
#include <nibobee/odometry.h>
#include <nibobee/led.h>
#include <nibobee/i2cmaster.h>
#include <nibobee/lcdi2c.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>


int8_t decode_l (uint8_t val) {
if (val==0x01) return -1;
if (val==0x02) return 1;
return 0;
}

int8_t decode_r (uint8_t val) {
if (val==0x01) return -1;
if (val==0x02) return 1;
return 0;
}

void print_hex (uint8_t val) {
char c1=val/16;
char c2=val%16;
if (c1<10) c1+='0'; else c1+='a'-10;
if (c2<10) c2+='0'; else c2+='a'-10;
usart_putchar(c1);
usart_putchar(c2);
}


int main() {
int odoL,odoR;

activate_output_group(IO_LEDS); // LED bits als Output
usart_setbaudrate(9600);
usart_enable();
motpwm_init();
odometry_init();
motpwm_setLeft(0);
motpwm_setRight(0);
analog_init();
i2c_init();
lcd_init(0x27);
lcd_setBacklight(0);
printf("NIBObee LCD V%d.%d",0,2);
set_output_group(IO_SENS); // Pull-ups aktivieren
activate_output_bit(IO_LINE_EN);
odoL = 0;
odoR = 0;

while(1) {
sei();
int8_t left = decode_l((PINC & 0x30)>>4);
int8_t right = decode_r((PINC & 0xc0)>>6);
int16_t speed_l = 0;
int16_t speed_r = 0;

switch (left) {
case -1: speed_l=-500; break;
case +1: speed_l=+500; break;
case 0: speed_l= 0; break;
}

switch (right) {
case -1: speed_r=-500; break;
case +1: speed_r=+500; break;
case 0: speed_r= 0; break;
}

motpwm_setLeft(speed_l);
motpwm_setRight(speed_r);

int16_t lval = analog_getValue(ANALOG_L1)-(int16_t)analog_getValue(ANALOG_L0) - 40;
int16_t cval = (3*(analog_getValue(ANALOG_C1)-(int16_t)analog_getValue(ANALOG_C0)))/4 - 60;
int16_t rval = analog_getValue(ANALOG_R1)-(int16_t)analog_getValue(ANALOG_R0) - 40;

if ((speed_l==0) && (speed_r==0)) {

if (lval<0) lval=0;
if (cval<0) cval=0;
if (rval<0) rval=0;

if (usart_txempty()) {
print_hex(LOBYTE(lval>>4));
usart_putchar(':');
print_hex(LOBYTE(cval>>4));
usart_putchar(':');
print_hex(LOBYTE(rval>>4));
usart_putchar(10);
usart_putchar(13);
}


uint8_t rule_l = 0;
uint8_t rule_c = 0;
uint8_t rule_r = 0;

if (lval+lval > rval+cval) rule_l=1;
if (cval+cval > lval+rval) rule_c=1;
if (rval+rval > lval+cval) rule_r=1;

if (lval > 300) rule_l=1;
if (cval > 300) rule_c=1;
if (rval > 300) rule_r=1;

if (lval < 100) rule_l=0;
if (cval < 100) rule_c=0;
if (rval < 100) rule_r=0;

led_set(LED_L_RD, rule_l);
led_set(LED_R_RD, rule_r);

led_set(LED_L_YE, (PIND & 0x04));
led_set(LED_R_YE, (PIND & 0x08));
}
else {
led_set(LED_L_RD, (speed_l>0));
led_set(LED_R_RD, (speed_r>0));
led_set(LED_L_YE, (speed_l<0));
led_set(LED_R_YE, (speed_r<0));
}

lcd_setCursor(0,1);
printf("L: %3x %3x %3x ", rval, cval,lval);

odoL += odometry_getLeft(1);
odoR += odometry_getRight(1);
lcd_setCursor(0,2);
printf("O: %4d %4d", odoR,odoL);

_delay_ms(100);

}

return 0; /* Diese Zeile ist eigentlich nicht



Hat jeman ein Idee? Bei einem anderen user läuft dieser Code ohne Probleme :-k

BurningWave
03.01.2010, 10:57
Dein Compiler erkennt diese Funktionen nicht, dass kann mehrere Ursachen haben: Du könntest den Namen der Funktionen falsch geschriben haben, vergessen haben eine Header einzubinden, diese Funktionen sind einfach nirgends definiert,...

Schau dir deinen Code und die Funktionsdeklerationen noch mal genau an, ob du vielleicht irgendeinen Schreibfehler oder so etwas gemacht hast.

mfg

Jaecko
03.01.2010, 11:28
Ist es bei dem anderen User exakt der gleiche Code?
Liegen die Dateien dort in den gleichen Ordnern?
Wird bei beiden die gleiche Version von WinAVR verwendet?