10 years, 1 month ago.

i2c comunication with gyro

Hi, I’m beginner in mbed, I want to read a gyro (L3GD20) by i2c, however I can’t read. I need to read only 2 registers(out_x_L , o_x_ H ), Do someone know my mistake?. Is there library for gyro L3GD20 in mbed?, I appreciate your help.

It’s my program

  1. include "mbed.h"

I2C i2c(PTE0,PTE1); SDA,SCL Serial pc(USBTX, USBRX); tx, rx DigitalOut myled(LED1); OUT_X_L=0x28,OUT_X_H=0x29.

int main() { i2c.frequency(100000); configuration frequency char OXL[1]; OXH[1]; char X1[1]; while(1){ OXL[0]= 0x28; i2c.start(); i2c.write(0xD4,OXL,1); wait_ms(5); OXL[0]= 0x27; i2c.write(0xD4,OXL,1); wait_ms(5); i2c.start(); i2c.read(0xD5,X1,1); wait_ms(5); i2c.stop();

printf("VALOR X1[0] = %X\n",X1[0]); printf("VALOR X1[1] = %X\n",X1[1]);

myled = 1; wait_ms(200); myled = 0; wait_ms(200); }}

2 Answers

10 years, 1 month ago.

Look here:

http://mbed.org/search/?type=&q=+L3GD20+

This may help you get started

Raul San
poster
10 years, 1 month ago.

Thanks a lot Paul, I'll check it.