View previous topic :: View next topic |
Author |
Message |
Neimen
Joined: 16 Mar 2012 Posts: 3
|
IMU Sensor Stick 9DOF with PIC16F877A |
Posted: Fri Mar 16, 2012 4:19 am |
|
|
Hello,
I'm using the PIC16F877A in order to print data from IMU sensor stick, but having problems. http://www.sparkfun.com/products/10183
The sensors addresses are:
*Digital Accelerometer ADXL345
Read-0xA7
Write-0xA6
*MEMS Gyro ITG3200
Read-0xD1
Write-0xD0
*Digital Compass HMC5843
Read-0x3D
Write-0x3C
I need an example code for reading and printing the data from the sensor stick.
Thank you for the help,
Neimen. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Fri Mar 16, 2012 5:51 am |
|
|
First, you should post your code so we can make comments.
Second, a quick glance of the product sheet says there is a minor defect with the board, so you HAVE done the necessary repairs ???
Third, those read/write addresses make me think the stick is just 3 I2C devices. If so, it's very simple to cut code for the 'drivers'. In fact any or all of them may have been already done. Have you checked the CCS 'drivers' folder, the 'code library', searched this forum?
Forth, I don't have that device so I won't write a driver for it,since I can't test it in the 'real world'. Now, if you want to send me 2 pieces of the device, I'll be happy to cut the code,which I can do in about a week.
5th...be sure to use proper logic level convertors as you've got a 5 volt PIC and a 3 volt peripheral. Be a real shame to destroy them !! |
|
|
SpaceXDebris
Joined: 15 Dec 2009 Posts: 3
|
|
Posted: Wed Mar 21, 2012 5:17 pm |
|
|
I got some numbers from the accel.
The sticking point was forgetting the "force_hw" flag. Without it, I was seeing 0xFF for all the data, which is a problem I've seen noticed mentioned several times around these boards. It's not the cleanest, but I hope that someone finds this code helpful.
Code: |
#include <30F4011.h>
#fuses HS,NOWDT, PUT64
#use delay(clock=30M)
#use rs232(baud=57600, xmit=PIN_F5, rcv=PIN_F4, stream=COM_A)
#use i2c(master, sda=PIN_F2, scl=PIN_F3, force_hw)
#use fast_io(e)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ACCEL_WRITE_ADDR 0xA6
#define ACCEL_READ_ADDR 0xA7
#define ACCEL_DATA_ADDR 0x32
#define ACCEL_PWRCTRL_ADDR 0x2d
#define ACCEL_MEASURE_MODE 0x08
void main ()
{
int i;
int accel_data[6];
set_tris_e(0x00);
// initialize
for (i = 0; i < 6; i++) {
accel_data[i] = 0;
}
while(true) {
// Tell the accelerometer to wake up
i2c_start();
i2c_write(ACCEL_WRITE_ADDR);
i2c_write(ACCEL_PWRCTRL_ADDR);
i2c_write(ACCEL_MEASURE_MODE);
i2c_stop();
// Read data from the accel
i2c_start();
i2c_write(ACCEL_WRITE_ADDR);
i2c_write(ACCEL_DATA_ADDR);
i2c_start();
i2c_write(ACCEL_READ_ADDR);
accel_data[0] = i2c_read(); //x0
accel_data[1] = i2c_read(); //x1
accel_data[2] = i2c_read(); //y0
accel_data[3] = i2c_read(); //y1
accel_data[4] = i2c_read(); //z0
accel_data[5] = i2c_read(0); // z1, NACK on last read
i2c_stop();
// Display
for (i = 0; i < 6; i++) {
fprintf(COM_A,"%x",accel_data[i]);
}
fprintf(COM_A,"\n\r");
delay_ms(10);
}
}
|
Cheers,
Chris |
|
|
Jampe
Joined: 09 Mar 2012 Posts: 27
|
|
Posted: Thu Mar 22, 2012 12:27 am |
|
|
SpaceXDebris, works great! Thank you! |
|
|
Neimen
Joined: 16 Mar 2012 Posts: 3
|
|
Posted: Thu Mar 22, 2012 2:10 am |
|
|
SpaceXDebris Thank you very much! The code works great and it was very helpful! |
|
|
lazuribicci
Joined: 06 Feb 2010 Posts: 10
|
|
Posted: Thu Mar 29, 2012 2:25 am |
|
|
it is not work for me. I read only 0xFF |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19494
|
|
Posted: Thu Mar 29, 2012 2:33 am |
|
|
The usual reason for reading 0xFF on I2C, is no pull up resistors on the bus.
Best Wishes |
|
|
lazuribicci
Joined: 06 Feb 2010 Posts: 10
|
|
Posted: Thu Mar 29, 2012 2:36 am |
|
|
thank you for reply. but I use pull up resistors. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Thu Mar 29, 2012 6:59 am |
|
|
laz....
which PIC are you using ?
did you add pullups or are you just using the modules pullups?
there's an I2C test program on this forum, search for it, then run it, see what happens. |
|
|
lazuribicci
Joined: 06 Feb 2010 Posts: 10
|
|
Posted: Thu Mar 29, 2012 7:17 am |
|
|
I tested circuit with oscilloscope. clock and data signals are seen well. but adxl345 doesn't send anything. data voltage is Vcc during reading.
BTW, CS pin is pulled up and ALT ADDRESS pin is grounded.
mcu is dspic30f4011 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Thu Mar 29, 2012 11:20 am |
|
|
So logic dictates that since the other two sensors are working 100% that the accelerometer chip is kaput. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 29, 2012 12:00 pm |
|
|
Here is an i2c bus scanner program that will report the addresses of any
i2c slave devices that it finds on the bus. Modify the #include, #fuses,
and the #use statements so it will work with your board. Then run it
and see what devices it finds:
http://www.ccsinfo.com/forum/viewtopic.php?t=47707&start=21 |
|
|
|