Hi all, Im new to forum and arduino. Im currently trying to run this code I found for the MMA7455 acclerometer. I'm getting this error message when i compile it. If anyone could help me figure out whats the problem i would be very thankful.
This the error im getting
main.cpp.o: In function main': C:\Users\MJ\Desktop\arduino-1.0-windows\arduino-1.0\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to
setup'
C:\Users\MJ\Desktop\arduino-1.0-windows\arduino-1.0\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop'
Heres the code.
MMA_7455.cpp
#include <wire.h>
#include <stdio.h>
#define MMA7455_I2C_ADDRESS 0x1D
//MMA7455 Registers
#define MMA7455_XOUTL 0x00
#define MMA7455_XOUTH 0x01
#define MMA7455_YOUTL 0x02
#define MMA7455_YOUTH 0x03
#define MMA7455_ZOUTL 0x04
#define MMA7455_ZOUTH 0x05
#define MMA7455_XOUT8 0x06
#define MMA7455_YOUT8 0x07
#define MMA7455_ZOUT8 0x08
#define MMA7455_STATUS 0x09
#define MMA7455_DETSRC 0x0A
#define MMA7455_TOUT 0x0B
#define MMA7455_I2CAD 0x0D
#define MMA7455_USRINF 0x0E
#define MMA7455_WHOAMI 0x0F
#define MMA7455_XOFFL 0x10
#define MMA7455_XOFFH 0x11
#define MMA7455_YOFFL 0x12
#define MMA7455_YOFFH 0x13
#define MMA7455_ZOFFL 0x14
#define MMA7455_ZOFFH 0x15
#define MMA7455_MCTL 0x16
#define MMA7455_INTRST 0x17
#define MMA7455_CTL1 0x18
#define MMA7455_CTL2 0x19
#define MMA7455_LDTH 0x1A
#define MMA7455_PDTH 0x1B
#define MMA7455_PW 0x1C
#define MMA7455_LT 0x1D
#define MMA7455_TW 0x1E
static FILE uartout = {0} ;
static int uart_putchar (char c, FILE *stream)
{
Serial.write(c) ;
return 0 ;
}
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
// The uart is the standard output device STDOUT.
stdout = &uartout ;
mma7455WriteReg(MMA7455_MCTL, 0x01);
}
unsigned char mma7455ReadReg(unsigned char reg)
{
//Write register address first
Wire.beginTransmission(MMA7455_I2C_ADDRESS);
Wire.write(reg);
Wire.endTransmission();
//Then read the data back
Wire.requestFrom(MMA7455_I2C_ADDRESS, 1);
if(Wire.available())
{
return Wire.read();
}
//Return zero if no data available
return 0;
}
void mma7455WriteReg(unsigned char reg, unsigned char value)
{
//Write register address first
Wire.beginTransmission(MMA7455_I2C_ADDRESS);
Wire.write(reg);
//And then write data
Wire.write(value);
Wire.endTransmission();
}
void loop()
{
printf("X = %u\n\r", mma7455ReadReg(MMA7455_XOUT8));
printf("Y = %u\n\r", mma7455ReadReg(MMA7455_YOUT8));
printf("Z = %u\n\r", mma7455ReadReg(MMA7455_ZOUT8));
delay(500);
}
</stdio.h></wire.h>
MMA_7455.h
[quote]
#ifndef MMA_7455_h
#define MMA_7455_h
#include [color=#006699]"Arduino.h"[/color] [color=#7E7E7E]//#include "WProgram.h"[/color]
#include [color=#006699]"Wire.h"[/color]
[color=#CC6600]class[/color] MMA_7455
{
[color=#CC6600]public[/color]:
MMA_7455();
[color=#CC6600]void[/color] initSensitivity([color=#CC6600]int[/color] sensitivity);
[color=#CC6600]void[/color] calibrateOffset([color=#CC6600]float[/color] x_axis_offset, [color=#CC6600]float[/color] y_axis_offset, [color=#CC6600]float[/color] z_axis_offset);
[color=#CC6600]unsigned[/color] [color=#CC6600]char[/color] readAxis([color=#CC6600]char[/color] axis);
[color=#CC6600]private[/color]:
[color=#CC6600]unsigned[/color] [color=#CC6600]char[/color] _buffer;
[color=#CC6600]float[/color] _x_axis_offset;
[color=#CC6600]float[/color] _y_axis_offset;
[color=#CC6600]float[/color] _z_axis_offset;
};
#endif
[/quote]