PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Nuvoton Cortex-M0 und Sensor SRF02



meemqri
13.11.2012, 13:33
Hoffe hier kann mir jemand helfen. Ich nutze o.g. MC und Sensor und möchte diesen, wie könnte es anders sein, auslesen. Ich schaff es aber nur das LSB auszulesen, das MSB geht "verloren" oder so.
Hier mein Code zum Auslesen der Register von MSB und LSB:

DrvI2C_Ctrl(I2C_PORT1, 1, 0, 1, 0); //Start I2C
while (DrvI2C_GetStatus(I2C_PORT1) != 0x08);

DrvI2C_WriteData(I2C_PORT1, 0xE0); //Slave Address
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0);
while (DrvI2C_GetStatus(I2C_PORT1) != 0x18);

DrvI2C_WriteData(I2C_PORT1, 3); //Register 3
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0);
while (DrvI2C_GetStatus(I2C_PORT1) != 0x28);

DrvI2C_WriteData(I2C_PORT1, 2); //Register 2
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0);
while (DrvI2C_GetStatus(I2C_PORT1) != 0x28);

// DrvI2C_Ctrl(I2C_PORT1, 0, 1, 1, 0); //Stop I2C
// while (DrvI2C_GetStatus(I2C_PORT1) != 0xF8);


DrvI2C_Ctrl(I2C_PORT1, 1, 0, 1, 0); //Restart I2C
while (DrvI2C_GetStatus(I2C_PORT1) != 0x10);

DrvI2C_WriteData(I2C_PORT1, 0xE1); //Slave Address + 1 = Read Command
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0);
while (DrvI2C_GetStatus(I2C_PORT1) != 0x40);

uiMSB = (DrvI2C_ReadData(I2C_PORT1)); //Read MSB
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 1); //Clear Int Flag and ACK
while (DrvI2C_GetStatus(I2C_PORT1) != 0x50);

uiLSB = DrvI2C_ReadData(I2C_PORT1); //Read LSB
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0); //Clear Int Flag and NACK
while (DrvI2C_GetStatus(I2C_PORT1) != 0x58);

DrvI2C_Ctrl(I2C_PORT1, 0, 1, 1, 0); //Stop I2C and Clear Int Flag

Ich kann nur Entfernungen bis exakt 255, also 0xFF messen, danach springt er auf 0 zurück :(

meemqri
16.11.2012, 17:31
Problem gelöst, nun funktioniert es.