I'm trying to read an accelerometer MMA7660 with a PIC microcontroller and a program
CCS.
The code I'm using is this:
#define DIR_MMA7660 0x4C
#define RegX 0
#define RegY 1
#define RegZ 2
#define I2C_LEER 1
#define I2C_ESCRIBIR 0
int8 EjeX, EjeY, EjeZ;
void LecturaMMA7660() {
i2c_start();
i2c_write(DIR_MMA7660 | I2C_ESCRIBIR);
i2c_write(RegX);
i2c_start();
i2c_write(DIR_MMA7660 | I2C_LEER);
EjeX=i2c_read(1);
EjeY=i2c_read(1);
EjeZ=i2c_read(0);
i2c_stop();
}
but can not get no result. Can anyone give me some advice?
Solved! Go to Solution.
Thanks.
My problem is solved with this initialization:
i2c_start();
i2c_write(DIR_MMA7660|I2C_ESCRIBIR);
i2c_write(RegMode);
i2c_write(1);
i2c_stop();
i2c_start();
i2c_write(DIR_MMA7660|I2C_ESCRIBIR);
i2c_write(RegSR);
i2c_write(0b011);
i2c_stop();
The accelerometer works fine.
Thanks
Hola, podrias decirme cual fue el pic que utilizaste y como lo conectaste al MMA7660FC?
Hello
Try first set registers:
REFERENCE CODE:
//Configure MMA7660FC as Portrait/Landscape Detection
Write to the MODE register = 0x00 //Standby Mode
Write to the SPCNT register = 0x00 //No sleep count
Write to the INTSU register = 0x03 //Configure GINT Interrupt
Write to the PDET register = 0xE0 //No tap detection enabled
Write to the SR register = 0x34 //8 samples/s, TILT debounce filter = 2
Write to the PD register = 0x00 //No tap detection debounce count enabled
Write to the MODE register = 0x41 //Active Mode, INT = push-pull and active low
(from application note AN3837)
Thanks.
My problem is solved with this initialization:
i2c_start();
i2c_write(DIR_MMA7660|I2C_ESCRIBIR);
i2c_write(RegMode);
i2c_write(1);
i2c_stop();
i2c_start();
i2c_write(DIR_MMA7660|I2C_ESCRIBIR);
i2c_write(RegSR);
i2c_write(0b011);
i2c_stop();
The accelerometer works fine.
Thanks
Hola se que resolviste el problema y me gustaria saber cual fue la secuencia que usaste para leerlo. Porque estoy intentando pero sin buenos resultados.. la lectura es siempre la misma para cualquiera de los ejes que lea.
Gracias
Salu2!
Así:
Ahhh ok ok.. muchas gracias, pero me queda una duda... cuando vos haces:
No es necesario, cuando lo pones a leer, cada byte que leas es el que corresponda a la siguiente dirección de memoria.
ahhh gracias capo, me parecio haber leido algo de autoincremento en los valores del registro pero no le di mucha im portancia, la verdad que me sacaste de un valle en el que estaba.
De nuevo gracias!
Salu2!
De nada, me alegro que lo solucionaras.