Beschleunigungssensor über I2C auslesen Kategorie: I²C-Bus (von Tim - 15.12.2010 19:50) | ||
| ||
Hallo, ich beschäftige mich seit kurzer Zeit mit dem Programmieren. Nun versuche ich schon seit Tagen einen Beschleunigungssenor (BMA150) über I2C auszulesen. Mit Hilfe dieses und anderen Foren konnte ich mir diesen Code erstellen: void main(void) { word adresse; adresse=0x02; int x_long,y_long,z_long; unsigned int x_short,y_short,z_short; float x,y,z; I2C_Init(I2C_100kHz); I2C_Start(); I2C_Write(0x70); I2C_Write(adresse); I2C_Stop(); I2C_Start(); I2C_Write(0x71); x_short=I2C_Read_ACK(); x_long=I2C_Read_ACK(); x_long=(((x_long)*4)+(x_short/64)); if (x_long > 512) { x_long= (x_long - 512); x_long= (512 - x_long); x_long= (x_long*(-1)); x= (x_long * 0.00390625); } else { x= (x_long * 0.00390625); } y_short=I2C_Read_ACK(); y_long=I2C_Read_ACK(); y_long=(((y_long)*4)+(y_short/64)); if (y_long > 512) { y_long= (y_long - 512); y_long= (512 - y_long); y_long= (y_long*(-1)); y= (y_long * 0.00390625); } else { y= (y_long * 0.00390625); } z_short=I2C_Read_ACK(); z_long=I2C_Read_NACK(); z_long=(((z_long)*4)+(z_short/64)); if (z_long > 512) { z_long= (z_long - 512); z_long= (512 - z_long); z_long= (z_long*(-1)); z= (z_long *0.00390625); } else { z= (z_long *0.00390625); } I2C_Stop(); Msg_WriteFloat(x); Msg_WriteChar(13); Msg_WriteFloat(y); Msg_WriteChar(13); Msg_WriteFloat(z); Msg_WriteChar(13); } Leider gibt mir das C-Control Programm für x, y und z nur 0.00000 heraus. Also kann irgendetwas nicht stimmen. Hat mir jemand einen Tipp? Danke schonmal für die Mühe. Gru� Tim | ||
Antwort schreiben Antworten: ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum