![](/media/cache/profiles/98740b855aad6c1dda41b6a6b223f66a.jpg.50x50_q85.png)
code c++ carte KL25Z avec écran TFT Qr4 526S01 TP28017 oscilloscope (en développement)
Dependencies: poirier-proj-95 TFT_fonts mbed
perso/diver.h@5:960d4056d774, 2015-11-28 (annotated)
- Committer:
- xpoirier
- Date:
- Sat Nov 28 12:00:07 2015 +0000
- Revision:
- 5:960d4056d774
- Parent:
- 3:24069293d35d
Projet - oscilloscope - iut neuville sur oise
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dujardin | 3:24069293d35d | 1 | |
dujardin | 3:24069293d35d | 2 | // pour lecture I2C accelerometre |
dujardin | 3:24069293d35d | 3 | PinName const SDA = PTE25; |
dujardin | 3:24069293d35d | 4 | PinName const SCL = PTE24; |
dujardin | 3:24069293d35d | 5 | I2C i2c(SDA,SCL); |
dujardin | 3:24069293d35d | 6 | |
dujardin | 3:24069293d35d | 7 | #define REG_WHO_AM_I 0x0D |
dujardin | 3:24069293d35d | 8 | #define REG_CTRL_REG_1 0x2A |
dujardin | 3:24069293d35d | 9 | #define REG_OUT_X_MSB 0x01 |
dujardin | 3:24069293d35d | 10 | #define REG_OUT_Y_MSB 0x03 |
dujardin | 3:24069293d35d | 11 | #define REG_OUT_Z_MSB 0x05 |
dujardin | 3:24069293d35d | 12 | |
dujardin | 3:24069293d35d | 13 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
dujardin | 3:24069293d35d | 14 | |
dujardin | 3:24069293d35d | 15 | // #define UINT14_MAX 16383 |
dujardin | 3:24069293d35d | 16 | #define UINT14_MAX 16384 |
dujardin | 2:1d66e2e776bc | 17 | |
dujardin | 2:1d66e2e776bc | 18 | |
dujardin | 3:24069293d35d | 19 | static const float redx=0.0f; |
dujardin | 3:24069293d35d | 20 | static const float redy=1.0f; |
dujardin | 3:24069293d35d | 21 | static const float greenx=sqrt(3.0f)/2.0f; |
dujardin | 3:24069293d35d | 22 | static const float greeny=-0.5f; |
dujardin | 3:24069293d35d | 23 | static const float bluex=-sqrt(3.0f)/2.0f; |
dujardin | 3:24069293d35d | 24 | static const float bluey=-0.5f; |
dujardin | 3:24069293d35d | 25 | |
dujardin | 3:24069293d35d | 26 | static const float twothirds=2.0f/3.0f; |
dujardin | 3:24069293d35d | 27 | |
dujardin | 3:24069293d35d | 28 | |
dujardin | 3:24069293d35d | 29 | float acclnread(uint8_t reg) |
dujardin | 3:24069293d35d | 30 | { |
dujardin | 3:24069293d35d | 31 | // Normalisation here seems wrong |
dujardin | 3:24069293d35d | 32 | char t[1]= {reg}; |
dujardin | 3:24069293d35d | 33 | i2c.write(MMA8451_I2C_ADDRESS,t,1,true); |
dujardin | 3:24069293d35d | 34 | uint8_t xbits[2] = {0,0}; |
dujardin | 3:24069293d35d | 35 | i2c.read(MMA8451_I2C_ADDRESS,(char *)xbits,2); |
dujardin | 3:24069293d35d | 36 | int16_t xint = 0; |
dujardin | 3:24069293d35d | 37 | xint=(xbits[0]<<6)|(xbits[1]>>2); |
dujardin | 3:24069293d35d | 38 | // this sign flip code looks wrong, UINT14_MAX maps to 0 |
dujardin | 3:24069293d35d | 39 | // UINT14_MAX=16383, should it be UINT14_MAX=16384 |
dujardin | 3:24069293d35d | 40 | if (xint > UINT14_MAX>>1) |
dujardin | 3:24069293d35d | 41 | xint -= UINT14_MAX; |
dujardin | 3:24069293d35d | 42 | return float(xint)/4096.0f; |
dujardin | 3:24069293d35d | 43 | // return float(xint); |
dujardin | 3:24069293d35d | 44 | } |