|
|
View previous topic :: View next topic |
Author |
Message |
ROBO12
Joined: 28 Aug 2012 Posts: 4
|
|
Posted: Sun Sep 02, 2012 4:20 am |
|
|
Ttelmah wrote: | You have to send the device address again after a restart.
Sequence is:
start
device address with direction bit set to write
register address
data to go to register (optional - remember register will normally increment)
restart
device address with direction bit set to read
read data from register
stop.
Best Wishes |
sorry.I forgot
but
this code is not Not working :
Code: | #include <16F877a.h>
#use delay(clock=4000000)
#define use_portb_lcd TRUE
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_TYPE 2
#use I2C(master,sda=PIN_C4,scl=PIN_C3,slow,restart_wdt)
#include <lcd.c>
void main()
{
set_tris_b(0x00);
lcd_init();
int8 x;
while(true)
{
i2c_start();
i2c_write(0xd0);
i2c_write(0x3c);
i2c_start();
i2c_write(0xd1);
x=i2c_read(0);
i2c_stop();
lcd_gotoxy(1,1);
printf(lcd_putc,"%u",x);
}
} |
|
|
|
pictrance
Joined: 18 Jul 2010 Posts: 14 Location: Puebla, Mexico
|
|
Posted: Sat Nov 03, 2012 1:57 pm |
|
|
Hello, you can try this code
Code: | #include <18f2550.h> //PIC utilizado
#device adc=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48M)
//Pal bootloader
#build (reset=0x1000,interrupt=0x1008)
#org 0x0000,0x0FFF{}
#use i2c(Master,fast,sda=PIN_A5,scl=PIN_A4)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "lcd20x4.c"
//La dirección del sensor se basa en el PIN AD0 del MPU6050
//es 0b11010010 sí el pin AD0 esta en 1, es 0b11010000 si el Pin AD0 esta en 0
#define MPU6050_W 0b11010010
#define MPU6050_R 0b11010011
#define MPU6050_RA_WHO_AM_I 0x75 //quien soy
void main(){
int8 x1;
SETUP_ADC(ADC_OFF);
lcd_init();
lcd_putc("\fSensor\nMPU6050");
delay_ms(500);
i2c_start();
i2c_write(MPU6050_W);
i2c_write(MPU6050_RA_WHO_AM_I);
i2c_start();
i2c_write(MPU6050_R);
x1=i2c_read(0);
i2c_stop();
Printf(lcd_putc, "\f0x%x", x1); //el resultado debe ser 0x68
while(true){
}
}
|
por el momento el sensor ya me responde, lo que no consigo es que me mande los datos del gyros y el acelerometro
saludos _________________ Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto. |
|
|
germin01
Joined: 29 Nov 2012 Posts: 1
|
|
Posted: Thu Nov 29, 2012 12:14 pm |
|
|
bkamen wrote: | Ttelmah wrote: | No, the reason that only software will work, is the input, not the output.
The hardware MSSP (I2C) module has a Vih, of 0.8* the PIC's Vdd. So with a 5v PIC, 4v. So if it is being being driven off an I2C device with the pull-ups going to 3v, it'll never see a 'high', and won't work....
This is the point about choosing pins with TTL input buffers, where Vih is low enough to happily work off the 3v device. |
That's a good point.. I work with the lower voltage devices so regularly now...
Ahhh, mixing I2C bus voltages... something I make it a point to avoid. |
I have found this wonder: NVT2002 from NXP Semiconductors
http://www.nxp.com/documents/data_sheet/NVT2001_NVT2002.pdf
It is used to translate voltages, and it is specially oriented to I2C communication (take a look at the datasheet, page 6). There is an example of conection using 1.8v & 3.3v (figure 6), but it works too with 3.3v & 5v.
Figure 7 is for devices using 3.3v & 5v, and a controller using from 1v to 1.8v: Isn't it wonderful??
I'm going to use it with a MPU6050 and ATMega168, and then will post the results. |
|
|
endezya04
Joined: 29 Mar 2013 Posts: 2
|
MPU6050 and PIC16F877 with CCS C |
Posted: Sun Mar 31, 2013 6:42 am |
|
|
ROBO12 wrote: | Hi. I bought an mpu6050 sensor and I was able to set it up but there is a problem. There are 2 parameters for each axis. For example in x accel axis there are 2 contain, Xout_H[15:8] and Xout_L[7:0]. In accel_XOUT_H I can read data and it is clear on lcd but in XOUT_L the data is not clear and altered.
The register address for _H = 0x3b
The register address for _L = 0x3c
Code for _H:
Code: |
i2c_start();
i2c_write(0xd0);
i2c_write(0x3b);
i2c_start():
i2c_write(0xd1);
x=i2c_read(0);
i2c_stop();
|
code for _L:
Code: |
i2c_start();
i2c_write(0xd0);
i2c_write(0x3c);
i2c_start():
i2c_write(0xd1);
y=i2c_read(0);
i2c_stop(); |
Where is the problem? |
hi Guys! I am making a quadcopter with MPU6050 and PIC16F877.But I dont know how can ı connect each other.and I use CCS C as software but I dont do it too.This mpu6050 sensor works with I2C PROTOKOL. can Anyone help me about this issue. Wait your helps.. please..! |
|
|
ALCION
Joined: 31 May 2007 Posts: 16
|
Re: MPU6050 and PIC16F877 with CCS C |
Posted: Sat Nov 23, 2013 7:18 pm |
|
|
Hi
You could run the MPU-6050?
regards |
|
|
|
|
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
|