Hey,
i'm trying to comunicate with an Minimu9 from Pololu, but it shows some strange behavior. I use the following code:
#include "mbed.h"
#include "Gyro.h"
using namespace std;
Serial pc(USBTX, USBRX);
Gyro gyro(p28, p27);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
int main()
{
wait(5);
pc.printf("1\n");
int status = (int)gyro.readRegister(L3G4200D_WHO_AM_I);
wait(1);
pc.printf("Who am i: _%i_ \n", status);
pc.printf("2\n");
wait(1);
status = (int)gyro.readRegister(L3G4200D_STATUS_REG);
pc.printf("Status: _%i_ \n", status);
pc.printf("3\n");
led1 = 1;
}
The class Gyro:
#include "Gyro.h"
#include "mbed.h"
Gyro::Gyro(PinName sda, PinName scl): _i2c(sda, scl)
{
writeRegister(L3G4200D_CTRL_REG1, 0x0F);
}
int Gyro::writeRegister(char regAdresse, char value)
{
char daten[2] = {regAdresse, value};
return _i2c.write(GYR_ADDRESS, daten, 2);
}
char Gyro::readRegister(char regAdresse)
{
char ret[1];
char Adresse[1] = {regAdresse};
_i2c.write(GYR_ADDRESS, Adresse, 1, 1);
_i2c.read(GYR_ADDRESS, ret, 1);
return ret[0];
}
If i connect it and let the program run, the output is:
Quote:
1
Who am i: _17_
2
Status: _189_
3
If i change the code to:
#include "mbed.h"
#include "Gyro.h"
using namespace std;
Serial pc(USBTX, USBRX);
Gyro gyro(p28, p27);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
int main()
{
wait(5);
pc.printf("100\n"); //<---
int status = (int)gyro.readRegister(L3G4200D_WHO_AM_I);
wait(1);
pc.printf("Who am i: _%i_ \n", status);
pc.printf("200\n"); //<---
wait(1);
status = (int)gyro.readRegister(L3G4200D_STATUS_REG);
pc.printf("Status: _%i_ \n", status);
pc.printf("300\n"); //<---
led1 = 1;
}
the output is:
Quote:
100
Who am i: _17_
200
Status: _201_
300
I think the reading of the WHO_AM_I register should produce an integer of 211 and not 17.
I have no pullup resistors connected because the imu (if i read the schematics right) has an internal pullup: http://www.pololu.com/file/0J502/MinIMU-9_schematic.pdf
I hope someone could help me, cause im a kind of desperated with this right now, don't know if i destroyed the mbed in some way. The imu is definitely working, i tested it.
Hey,
i'm trying to comunicate with an Minimu9 from Pololu, but it shows some strange behavior. I use the following code:
The class Gyro:
If i connect it and let the program run, the output is:
Quote:
1 Who am i: _17_ 2 Status: _189_ 3
If i change the code to:
the output is:
Quote:
100 Who am i: _17_ 200 Status: _201_ 300
I think the reading of the WHO_AM_I register should produce an integer of 211 and not 17.
I have no pullup resistors connected because the imu (if i read the schematics right) has an internal pullup: http://www.pololu.com/file/0J502/MinIMU-9_schematic.pdf
I hope someone could help me, cause im a kind of desperated with this right now, don't know if i destroyed the mbed in some way. The imu is definitely working, i tested it.