![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
rajm
Joined: 06 Nov 2012 Posts: 29
|
MinIMU-9 v2 from Pololu interfacing with PIC |
Posted: Fri Feb 22, 2013 3:43 am |
|
|
I have written code to read only gyro values from the the sensor, but I'm not getting anything with this code. Can any one help in this problem ?
My datasheet is from: http://www.pololu.com/catalog/product/1268
my code is:
Code: |
#include <18f4550.h>
//#include <L3G20.h>
#device ADC=10
#fuses HS,MCLR,NOWDT,NOPROTECT,NOLVP,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=Rec_Dat)
#use I2C(master,sda=PIN_B0, scl=PIN_B1) /*Set I2C Settings */
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C0
#define LCD_RW_PIN PIN_C1
#define DATA_PORT PORTD
#include <lcd.c>
//long int n,ch0;
unsigned int i,I2c_Data[10];
void WriteData(unsigned char address, unsigned char data)
{
i2c_start();
i2c_write(0x98);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(100);
}
void main()
{
lcd_init();
set_tris_c(0xff);
set_tris_d(0x00);
//i2c_start();
//i2c_write(0x6B);
//WriteData(0x30,0xFF);
while(true)
{
lcd_gotoxy(1,1);
lcd_putc(" acc:");
WriteData(0x30,0xFF);
i2c_start(); /* Read Mode */
//i2c_write(0x99);
//i2c_write(0x6B);
for(i=0;i<7;i++)
{
I2c_Data[i]=i2c_read(0x28); /* Read Data */
}
//I2c_Data[i]=i2c_read(0);
// lcd_gotoxy(2,2);
printf("\n\rX=%u",I2c_Data[0]); /* Send X-axis value */
printf(" Y=%u",I2c_Data[1]); /* Send Y-axis value */
printf(" Z=%u",I2c_Data[2]); /* Send Z-axis value */
i2c_stop();
//delay_ms(1000);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19383
|
|
Posted: Fri Feb 22, 2013 5:28 am |
|
|
One 'glaring thing', before we look any deeper.
Try the fuse NOPBADEN.
The chip defaults to having the PORTB pins setup for ADC use. If you look at the datasheet, this overrides the peripherals on PORTB.
Come back if this doesn't work, and then we'll look at the code.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9178 Location: Greensville,Ontario
|
|
Posted: Fri Feb 22, 2013 6:25 am |
|
|
With ANY program using an I2C device, first download PCMprogrammer's I2C 'scanner' program located here or in the code forum.
Run it FIRST to confirm your hardware is OK BEFORE you cut your own code.
You'll save countless hours trying to debug.Right now it might be hardware or it might be software.
Running his program will QUICKLY confirm where you have to spend your time!
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|