Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

L3GD20 problem in reading values usng PIC18f4550

Status
Not open for further replies.

rajesh1987

Junior Member level 2
Joined
Dec 5, 2012
Messages
21
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,430
hi
I have got Pololu minIMU-9V2, in which I'm trying to read gyroscope values. When i connect my sensor its always showing X=-1, and when i disconnect my sensor its showing X=10223 0r X=10877. Since it has got pull up resistor i didn't connect external pull up resistor.
my code is
Code:
#Include <18f4550.h>
//#use delay(xtal=20Mhz)
//#fuses NOWDT,HS
#fuses HS,MCLR,NOWDT,NOPROTECT,NOLVP,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=2000000)
#use i2c(Master,sda=PIN_B0,scl=PIN_B1)
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C1
#define LCD_RW_PIN PIN_C0
#define DATA_PORT  PORTD
#include <lcd.c>

#define gyro_ADD_R 0xD3
#define gyro_ADD_W 0xD2
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24

int16 x=0;
int8 xM=0,xL=0;

void writeRegister(int8 reg,int8 value)
 {
    i2c_start();
    i2c_write(gyro_ADD_W);     
    i2c_write(reg);       
    i2c_write(value);           
    i2c_stop();             
 }

void init_gyro()
{
writeRegister(CTRL_REG1,0b00001111);
writeRegister(CTRL_REG2,0b00001000);
writeRegister(CTRL_REG3,0b00001000);
writeRegister(CTRL_REG4,0b10110000);        //10110000
writeRegister(CTRL_REG5,0b00000000);
}

void main()
{
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc," L3GD20");   // l3g4200d
delay_ms(1000);
init_gyro();

while(true)
{
    i2c_start();
    i2c_write(0XD2);             
    i2c_write(0x28);
    i2c_start();
    i2c_write(0XD3);           
    xL=i2c_read();         
    xM=i2c_read(0);
    x=make16(xM,xL);
    i2c_stop();
    printf(lcd_putc"\f");
    lcd_gotoxy(1,2);
    printf(lcd_putc,"x=%Ld",x);
    delay_ms(50);
}

}

regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top