Ich bin gerade dabei I2C mit der MPU6050/9150 zumindest erstmal per
Polling zum Laufen zu bringen.
Es funktioniert soweit das ich Register auslesen kann. Ausprobiert habe
ich das indem ich mir die I2C Adresse aus dem WHO_AM_I Register
ausgelesen habe.
Auch das andere Register was am Anfang einen anderen Wert als 0 hat,
habe ich erfolgreich auslesen können.
Wenn ich jetzt aber Register setze und dann wieder auslese, um sicher zu
stellen das es auch geklappt hat, bekomme ich immer 0 zurück.
Dies ist meine Lesefunktion:
1 | uint8_t
|
2 | I2C3_Recv(uint8_t addr,
|
3 | uint8_t reg)
|
4 | {
|
5 | uint8_t res;
|
6 | /// DEBUG
|
7 | DigitalOutput_DebugPinB0(true);
|
8 | /// DEBUG
|
9 | //specify that we are writing (a register address) to the
|
10 | //slave device
|
11 | I2CMasterSlaveAddrSet(I2C3_BASE,addr,false);
|
12 | //specify register to be read
|
13 | I2CMasterDataPut(I2C3_BASE,reg);
|
14 | //send control byte and register address byte to slave device
|
15 | I2CMasterControl(I2C3_BASE,I2C_MASTER_CMD_BURST_SEND_START);
|
16 | //wait for MCU to finish transaction
|
17 | while(I2CMasterBusy(I2C3_BASE));
|
18 | //specify that we are going to read from slave device
|
19 | I2CMasterSlaveAddrSet(I2C3_BASE,addr,true);
|
20 | //send control byte and read from the register we
|
21 | //specified
|
22 | I2CMasterControl(I2C3_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE);
|
23 | //wait for MCU to finish transaction
|
24 | while(I2CMasterBusy(I2C3_BASE));
|
25 | //return data pulled from the specified register
|
26 | res = I2CMasterDataGet(I2C3_BASE);
|
27 | /// DEBUG
|
28 | DigitalOutput_DebugPinB0(false);
|
29 | /// DEBUG
|
30 | return res;
|
31 | }
|
Dies ist meine Schreibefunktion:
1 | void
|
2 | I2C3_Send(uint8_t addr,
|
3 | uint8_t reg,
|
4 | uint8_t data)
|
5 | {
|
6 | /// DEBUG
|
7 | DigitalOutput_DebugPinB0(true);
|
8 | /// DEBUG
|
9 | // Tell the master module what address it will place on the bus when
|
10 | // communicating with the slave.
|
11 | I2CMasterSlaveAddrSet(I2C3_BASE,addr,false);
|
12 | // put reg into FIFO
|
13 | I2CMasterDataPut(I2C3_BASE,reg);
|
14 | // Initiate send of data from the MCU
|
15 | I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_START);
|
16 | // Wait until MCU is done transferring.
|
17 | while(I2CMasterBusy(I2C3_BASE));
|
18 | // put data into FIFO
|
19 | I2CMasterDataPut(I2C3_BASE,data);
|
20 | // Initiate send of data from the MCU
|
21 | I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
|
22 | // Wait until MCU is done transferring.
|
23 | while(I2CMasterBusy(I2C3_BASE));
|
24 | /// DEBUG
|
25 | DigitalOutput_DebugPinB0(false);
|
26 | /// DEBUG
|
27 | }
|
Hat jemand eine Idee, warum das Schreiben nicht klappt? Auf dem
Logicanalyzer sieht es gut aus, nur scheinbar nimmt es der Sensor nicht
an.