PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : implicit declaration of function `sbi'



veloxid
07.07.2005, 09:12
HI ich hab hier einen programm text, mit dem unterprogramm i2c.c von Pascal Stang. Bei dem wird die funkttion sbi aufgerufen. Bei makefile gibt er mir dann die oben genannte fehlermeldung aus.
Die funktion wird in der main unit aufgerufen und gibt dort keinen error aus.
Woran kann das liegen?

Hier das UNterprogamm bis einschließlich dem fehler:

/*! \file i2c.c \brief I2C interface using AVR Two-Wire Interface (TWI) hardware. */
//************************************************** ***************************
//
// File Name : 'i2c.c'
// Title : I2C interface using AVR Two-Wire Interface (TWI) hardware
// Author : Pascal Stang - Copyright (C) 2002-2003
// Created : 2002.06.25
// Revised : 2003.03.02
// Version : 0.9
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// Description : I2C (pronounced "eye-squared-see") is a two-wire bidirectional
// network designed for easy transfer of information between a wide variety
// of intelligent devices. Many of the Atmel AVR series processors have
// hardware support for transmitting and receiving using an I2C-type bus.
// In addition to the AVRs, there are thousands of other parts made by
// manufacturers like Philips, Maxim, National, TI, etc that use I2C as
// their primary means of communication and control. Common device types
// are A/D & D/A converters, temp sensors, intelligent battery monitors,
// MP3 decoder chips, EEPROM chips, multiplexing switches, etc.
//
// I2C uses only two wires (SDA and SCL) to communicate bidirectionally
// between devices. I2C is a multidrop network, meaning that you can have
// several devices on a single bus. Because I2C uses a 7-bit number to
// identify which device it wants to talk to, you cannot have more than
// 127 devices on a single bus.
//
// I2C ordinarily requires two 4.7K pull-up resistors to power (one each on
// SDA and SCL), but for small numbers of devices (maybe 1-4), it is enough
// to activate the internal pull-up resistors in the AVR processor. To do
// this, set the port pins, which correspond to the I2C pins SDA/SCL, high.
// For example, on the mega163, sbi(PORTC, 0); sbi(PORTC, 1);.
//
// For complete information about I2C, see the Philips Semiconductor
// website. They created I2C and have the largest family of devices that
// work with I2C.
//
// Note: Many manufacturers market I2C bus devices under a different or generic
// bus name like "Two-Wire Interface". This is because Philips still holds
// "I2C" as a trademark. For example, SMBus and SMBus devices are hardware
// compatible and closely related to I2C. They can be directly connected
// to an I2C bus along with other I2C devices are are generally accessed in
// the same way as I2C devices. SMBus is often found on modern motherboards
// for temp sensing and other low-level control tasks.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//************************************************** ***************************

#include <inttypes.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <stdlib.h>
#include <math.h>
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>

#include <compat/twi.h>

#include "i2c.h"

//#include "stdserial.h"

// Standard I2C bit rates are:
// 100KHz for slow speed
// 400KHz for high speed

#define I2C_DEBUG

// I2C state and address variables
static volatile eI2cStateType I2cState;
static u08 I2cDeviceAddrRW;
// send/transmit buffer (outgoing data)
static u08 I2cSendData[I2C_SEND_DATA_BUFFER_SIZE];
static u08 I2cSendDataIndex;
static u08 I2cSendDataLength;
// receive buffer (incoming data)
static u08 I2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE];
static u08 I2cReceiveDataIndex;
static u08 I2cReceiveDataLength;

// function pointer to i2c receive routine
//! I2cSlaveReceive is called when this processor
// is addressed as a slave for writing
static void (*i2cSlaveReceive)(u08 receiveDataLength, u08* recieveData);
//! I2cSlaveTransmit is called when this processor
// is addressed as a slave for reading
static u08 (*i2cSlaveTransmit)(u08 transmitDataLengthMax, u08* transmitData);

// functions
void i2c_Init(void)
{
// set pull-up resistors on I2C bus pins
sbi(PORTC, 0); // i2c SCL on ATmega163,323,16,32,etc
sbi(PORTC, 1); // i2c SDA on ATmega163,323,16,32,etc
//sbi(PORTD, 0); // i2c SCL on ATmega128,64
//sbi(PORTD, 1); // i2c SDA on ATmega128,64

// clear SlaveReceive and SlaveTransmit handler to null
i2cSlaveReceive = 0;
i2cSlaveTransmit = 0;
// set i2c bit rate to 100KHz
i2cSetBitrate(100);
// enable TWI (two-wire interface)
sbi(TWCR, TWEN);
// set state
I2cState = I2C_IDLE;
// enable TWI interrupt and slave address ACK
sbi(TWCR, TWIE);
sbi(TWCR, TWEA);
//outb(TWCR, (inb(TWCR)&TWCR_CMD_MASK)|BV(TWINT)|BV(TWEA));
// enable interrupts
sei();
}



es kommen anschließend noch mal die gleichen fehlerjedoch andere functions:
cbi
outp
inp
BV

SprinterSB
07.07.2005, 09:36
Dein gcc findet keinen Prototyp für diese Funktion.
sbi() solltest du mit

#include <avr/io.h>

bekommen. Dieses includiert avr/sfr_defs.h, welches ein Makro auf
sbi() legt. Es ist also zu vermuten, daß der Include-Pfad nicht gefunden wurde. Schau mal in die precompilierte Quelle rein (*.i, wird erzeugt mit gcc-Schalter -save-temps). Da siehst du mehr.
Evtl verbose übersetzen (gcc-Schalter -v).

Wie sieht denn deine make-Regel zum compilieren aus?

veloxid
07.07.2005, 10:10
hi das #include <avr/io.h> hab ich ja benutzt.

Ich arbeite das 1. mal mit nem atmel daher noch nicht so sicher mit proggen, aber ich vermute daß das hier die make regln sin:
> "make.exe" all
avr-gcc -g -Wall -O2 -mmcu=atmega16 -I../include -c -o i2c.o i2c.c

wo finde/erzeuge ich die precompilierte quelle? ich benutze das programmers notepad für winavr.

OldBug
07.07.2005, 11:49
sbi/cbi/inp/outp/etc sind schon seit Ewigkeiten abgekündigt gewesen und in der aktuellen avr-libc nicht mehr enthalten!

SprinterSB
07.07.2005, 11:57
Wie sesagt: Precompilat erhälst du mit gcc-Schalter -save-temps, also
avr-gcc -save-temps ...
Dort, wo dein Objekt *.o erstellt wird, sollte danach ein *.i und ein *.s (Assembler) zu finden sein. In deinem Falle also i2c.i und i2c.s, das *.s natürlich nur, wenn das Compilieren funktioniert.

Bei dem Listing der Include-Pfade sollte auch dein
AVR_INSTALL_PATH/avr/include auftauchen.

Warum das sbi() nicht gefunden wird, ist mir schleierhaft.
Bei mir funktioniert das problemlos und erscheint im asm auch als sbi.

Johann

SprinterSB
07.07.2005, 12:06
avr/sfr_defs.h (avr-gcc 3.4.1):

/* Backwards compatibility, do not use in new programs. */

/** \name Deprecated Macros */
/*@{*/


/** \def cbi
\ingroup avr_sfr
\deprecated
\code #include <avr/io.h>\endcode
For backwards compatibility only. This macro will eventually be removed.

Clear bit \c bit in IO register \c sfr. */

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

Dein Problem ist also wohl eine zu neue gcc-Version bzw die Verwendung eines deprecated (veralteten) Macros.


Johann

veloxid
07.07.2005, 12:29
ja ok
ich versteh nur noch bahnhof.
was muss ich jetzt machen

Kjion
07.07.2005, 13:05
Enweder du ersetzt zB. sbi(PORTC, 2) durch PORTC |= (1<<2); oder du benutzt entsprechende Makros:

#define sbi(p,n) (p) |= (1<<(n))
#define cbi(p,n) (p) &= ~(1<<(n))
#define outb(p,n) (p) = (n)
#define inb(p) (p)

MfG Kjion