Éric Bisson
/
Code_APP3_R
app3
Fork of Code_APP1 by
main.cpp@0:52fba6f1554b, 2017-01-14 (annotated)
- Committer:
- LouBe4
- Date:
- Sat Jan 14 21:12:38 2017 +0000
- Revision:
- 0:52fba6f1554b
- Child:
- 1:3430643e8ed4
Base Code pour APP1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LouBe4 | 0:52fba6f1554b | 1 | #include "mbed.h" |
LouBe4 | 0:52fba6f1554b | 2 | |
LouBe4 | 0:52fba6f1554b | 3 | Serial pc(USBTX, USBRX); |
LouBe4 | 0:52fba6f1554b | 4 | SPI spi(p11, p12, p13); |
LouBe4 | 0:52fba6f1554b | 5 | DigitalOut cs(p14); |
LouBe4 | 0:52fba6f1554b | 6 | I2C i2c(p28, p27); |
LouBe4 | 0:52fba6f1554b | 7 | PwmOut led1(LED1); |
LouBe4 | 0:52fba6f1554b | 8 | int addrChip = 0x3A; |
LouBe4 | 0:52fba6f1554b | 9 | char buffer[6]; |
LouBe4 | 0:52fba6f1554b | 10 | int resultat[3]; |
LouBe4 | 0:52fba6f1554b | 11 | |
LouBe4 | 0:52fba6f1554b | 12 | int main() { |
LouBe4 | 0:52fba6f1554b | 13 | |
LouBe4 | 0:52fba6f1554b | 14 | //Activer l'accéléromètre |
LouBe4 | 0:52fba6f1554b | 15 | char addrIdle[2] = {0x2A, 0x01}; |
LouBe4 | 0:52fba6f1554b | 16 | i2c.write(addrChip, addrIdle, 2, true); |
LouBe4 | 0:52fba6f1554b | 17 | |
LouBe4 | 0:52fba6f1554b | 18 | //Aller lire les valeurs d'accélération |
LouBe4 | 0:52fba6f1554b | 19 | buffer[0] = 0x01; |
LouBe4 | 0:52fba6f1554b | 20 | i2c.write(addrChip, buffer, 1, true); |
LouBe4 | 0:52fba6f1554b | 21 | i2c.read(addrChip, buffer, 6); |
LouBe4 | 0:52fba6f1554b | 22 | pc.printf("%03x\t", buffer[2]); |
LouBe4 | 0:52fba6f1554b | 23 | pc.printf("%03x\t", buffer[3]); |
LouBe4 | 0:52fba6f1554b | 24 | char temp[1]; |
LouBe4 | 0:52fba6f1554b | 25 | temp[0] = ("%02x"+"%02x", buffer[2], buffer[3]); |
LouBe4 | 0:52fba6f1554b | 26 | pc.printf("%02x\n", temp[0]); |
LouBe4 | 0:52fba6f1554b | 27 | //resultat[0] = buffer[0]+buffer[1] |
LouBe4 | 0:52fba6f1554b | 28 | |
LouBe4 | 0:52fba6f1554b | 29 | |
LouBe4 | 0:52fba6f1554b | 30 | /*pc.printf("%02x\n", buffer[0]); |
LouBe4 | 0:52fba6f1554b | 31 | pc.printf("%02x\n", buffer[1]); |
LouBe4 | 0:52fba6f1554b | 32 | pc.printf("%02x\n", buffer[2]); |
LouBe4 | 0:52fba6f1554b | 33 | pc.printf("%02x\n", buffer[3]); |
LouBe4 | 0:52fba6f1554b | 34 | pc.printf("%02x\n", buffer[4]); |
LouBe4 | 0:52fba6f1554b | 35 | pc.printf("%02x\n", buffer[5]);*/ |
LouBe4 | 0:52fba6f1554b | 36 | |
LouBe4 | 0:52fba6f1554b | 37 | //----Base SPI---- |
LouBe4 | 0:52fba6f1554b | 38 | cs = 0; |
LouBe4 | 0:52fba6f1554b | 39 | spi.format(8,0); |
LouBe4 | 0:52fba6f1554b | 40 | spi.frequency(250000); |
LouBe4 | 0:52fba6f1554b | 41 | spi.write(buffer[0]); |
LouBe4 | 0:52fba6f1554b | 42 | spi.write(buffer[1]); |
LouBe4 | 0:52fba6f1554b | 43 | spi.write(buffer[2]); |
LouBe4 | 0:52fba6f1554b | 44 | spi.write(buffer[3]); |
LouBe4 | 0:52fba6f1554b | 45 | |
LouBe4 | 0:52fba6f1554b | 46 | } |