|
|
View previous topic :: View next topic |
Author |
Message |
nOgUkO Guest
|
Problems with accelerometer MMA7455L |
Posted: Tue Apr 28, 2009 2:59 am |
|
|
Hi Guys!
I´m using the accelerometer of freescale MMA7455L via I2C.
The microcontroller that i´m using is the PIC18LF4553 runing at 3.3V
I have some problems when i try reading the registers 0x06 0x07 0x08 (8 bit value of x y and z axis); the data displayed in my LCD varies constantly: sometimes read 245, 231, 255, 1, 0, 10, 7... random values
There is the code:
Code: |
#include <18F4553.h>
#fusesXTPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL1,CPUDIV1,USBDV,NOVREGEN
#use delay(clock=48000000)
#define USB_CON_SENSE_PIN PIN_C0
#include <usb_cdc.h>
#include <lcd.c>
#use i2c(master,slow,sda=PIN_B0, scl=PIN_B1,FORCE_HW)
int data=0;
void main() {
delay_ms(100);
lcd_init();
i2c_start();
i2c_write(0x3A); //0x1D shifted in with a 0 had been 0x3A
i2c_write(0x16); //MODE CONTROL REGISTER
i2c_write(0x05); //CONTINOUS MEASUREMENT
i2c_stop();
delay_ms(30);
loop:
i2c_start();
i2c_write(0x3A);
i2c_write(0x08); //8 bits output value Z
i2c_start();
i2c_write(0x3B); //0x1D shifted in with a 1 had been 0x3B
data=i2c_read(0);
i2c_stop();
delay_ms(500);
printf(lcd_putc,"\f %u",data);//PRINT DATA INTO LCD
goto loop;
}
|
Someting is wrong in my code?
Please help me!
Thanks! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Apr 28, 2009 3:48 am |
|
|
If readback of configuration registers is correct (constant), it's most likely sensor noise. The values you gave, are at least in an allowed range for zero readings. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|