![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pre commentaire
Fork of Code_APP3_R by
Diff: main.cpp
- Revision:
- 0:52fba6f1554b
- Child:
- 1:3430643e8ed4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jan 14 21:12:38 2017 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); +SPI spi(p11, p12, p13); +DigitalOut cs(p14); +I2C i2c(p28, p27); +PwmOut led1(LED1); +int addrChip = 0x3A; +char buffer[6]; +int resultat[3]; + +int main() { + + //Activer l'accéléromètre + char addrIdle[2] = {0x2A, 0x01}; + i2c.write(addrChip, addrIdle, 2, true); + + //Aller lire les valeurs d'accélération + buffer[0] = 0x01; + i2c.write(addrChip, buffer, 1, true); + i2c.read(addrChip, buffer, 6); + pc.printf("%03x\t", buffer[2]); + pc.printf("%03x\t", buffer[3]); + char temp[1]; + temp[0] = ("%02x"+"%02x", buffer[2], buffer[3]); + pc.printf("%02x\n", temp[0]); + //resultat[0] = buffer[0]+buffer[1] + + + /*pc.printf("%02x\n", buffer[0]); + pc.printf("%02x\n", buffer[1]); + pc.printf("%02x\n", buffer[2]); + pc.printf("%02x\n", buffer[3]); + pc.printf("%02x\n", buffer[4]); + pc.printf("%02x\n", buffer[5]);*/ + + //----Base SPI---- + cs = 0; + spi.format(8,0); + spi.frequency(250000); + spi.write(buffer[0]); + spi.write(buffer[1]); + spi.write(buffer[2]); + spi.write(buffer[3]); + +}