Éric Bisson
/
Code_APP3_R
app3
Fork of Code_APP1 by
main.cpp@1:3430643e8ed4, 2017-01-15 (annotated)
- Committer:
- LouBe4
- Date:
- Sun Jan 15 19:36:05 2017 +0000
- Revision:
- 1:3430643e8ed4
- Parent:
- 0:52fba6f1554b
- Child:
- 2:9aacd567c70b
refait sur 8 bits;
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 | 1:3430643e8ed4 | 9 | char buffer[3]; |
LouBe4 | 1:3430643e8ed4 | 10 | |
LouBe4 | 1:3430643e8ed4 | 11 | int calculer_angle(char accX, char accY, char accZ) |
LouBe4 | 1:3430643e8ed4 | 12 | { |
LouBe4 | 1:3430643e8ed4 | 13 | pc.printf(&accX); |
LouBe4 | 1:3430643e8ed4 | 14 | pc.printf(&accY); |
LouBe4 | 1:3430643e8ed4 | 15 | pc.printf(&accZ); |
LouBe4 | 1:3430643e8ed4 | 16 | return 0; |
LouBe4 | 1:3430643e8ed4 | 17 | } |
LouBe4 | 0:52fba6f1554b | 18 | |
LouBe4 | 0:52fba6f1554b | 19 | int main() { |
LouBe4 | 0:52fba6f1554b | 20 | |
LouBe4 | 1:3430643e8ed4 | 21 | //Activer l'accéléromètre pour lecture 8 bits |
LouBe4 | 1:3430643e8ed4 | 22 | char activation[2] = {0x2A, 0x03}; |
LouBe4 | 1:3430643e8ed4 | 23 | i2c.write(addrChip, activation, 2, true); |
LouBe4 | 0:52fba6f1554b | 24 | |
LouBe4 | 0:52fba6f1554b | 25 | //Aller lire les valeurs d'accélération |
LouBe4 | 0:52fba6f1554b | 26 | buffer[0] = 0x01; |
LouBe4 | 0:52fba6f1554b | 27 | i2c.write(addrChip, buffer, 1, true); |
LouBe4 | 1:3430643e8ed4 | 28 | i2c.read(addrChip, buffer, 3); |
LouBe4 | 1:3430643e8ed4 | 29 | int angle = calculer_angle(buffer[0], buffer[1], buffer[2]); |
LouBe4 | 1:3430643e8ed4 | 30 | pc.printf("%02x\t", buffer[0]); |
LouBe4 | 1:3430643e8ed4 | 31 | pc.printf("%02x\t", buffer[1]); |
LouBe4 | 1:3430643e8ed4 | 32 | pc.printf("%02x\t", buffer[2]); |
LouBe4 | 1:3430643e8ed4 | 33 | pc.printf("\n"); |
LouBe4 | 0:52fba6f1554b | 34 | |
LouBe4 | 0:52fba6f1554b | 35 | |
LouBe4 | 0:52fba6f1554b | 36 | //----Base SPI---- |
LouBe4 | 0:52fba6f1554b | 37 | cs = 0; |
LouBe4 | 0:52fba6f1554b | 38 | spi.format(8,0); |
LouBe4 | 0:52fba6f1554b | 39 | spi.frequency(250000); |
LouBe4 | 1:3430643e8ed4 | 40 | wait(0.1); |
LouBe4 | 1:3430643e8ed4 | 41 | cs = 1; |
LouBe4 | 0:52fba6f1554b | 42 | } |