Lin Team
/
ADXL355
ADXL355
Revision 1:c7e291816833, committed 2020-08-06
- Comitter:
- peng103617
- Date:
- Thu Aug 06 06:53:20 2020 +0000
- Parent:
- 0:df16df7ba53f
- Commit message:
- ADXL355
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 06 19:25:43 2020 +0000 +++ b/main.cpp Thu Aug 06 06:53:20 2020 +0000 @@ -74,21 +74,31 @@ // Blinking rate in milliseconds #define SLEEP_TIME 500 // Setup the SPI peripheral to talk to the ADXL35x -SPI spi(D11, D12, D13); +//SPI spi(D11, D12, D13); +// initialize chip select +//DigitalOut cs(D10); + +SPI spi(PB_15, PB_14, PB_13); // initialize chip select -DigitalOut cs(D10); +DigitalOut cs(PB_1); + + + + // Initialise the digital pin LED1 as an output DigitalOut led1(LED1); // Initialise the serial object with TX and RX pins Serial pc(USBTX, USBRX); +Timer t; int id=0; - +int i=1; // main() runs in its own thread in the OS int main() { pc.printf("Hello World!"); + pc.baud (115200) ; spi.frequency(1000000); @@ -126,9 +136,11 @@ // Now dump the temp and accelerometer data to the port while (true) { + t.start(); + // Blink LED and wait 500 ms - led1 = !led1; - thread_sleep_for(SLEEP_TIME); + //led1 = !led1; + //thread_sleep_for(SLEEP_TIME); //the acceleration data is 20 bits and needs to come in via three register transactions cs=0; @@ -144,7 +156,7 @@ // This should output the ID register as 0x01 i32SensorX = ADXL355_Acceleration_Data_Conversion(ui32Result); //pc.printf("X acceleration formatted data = %d\n", i32SensorX); - pc.printf("X = %2.6f g, ", i32SensorX*LSB_scale_factor); + // pc.printf("%2.6f \n\r", i32SensorX*LSB_scale_factor); //the acceleration data is 20 bits and needs to come in via three register transactions cs=0; @@ -160,7 +172,9 @@ // This should output the ID register as 0x01 i32SensorY = ADXL355_Acceleration_Data_Conversion(ui32Result); //pc.printf("Y acceleration formatted data = %d\n", i32SensorY); - pc.printf("Y = %2.6f g, ", i32SensorY*LSB_scale_factor); + // pc.printf("%2.6f \n\r", i32SensorY*LSB_scale_factor); + + //the acceleration data is 20 bits and needs to come in via three register transactions @@ -172,14 +186,28 @@ cs=1; // Put it back together + + + + ui32Result = ((ui8SensorZ << 16) | (ui8SensorZ2 << 8) | ui8SensorZ3); /* Set read result*/ //pc.printf("Z acceleration data = 0x%X\n", ui32Result); // This should output the ID register as 0x01 i32SensorZ = ADXL355_Acceleration_Data_Conversion(ui32Result); //pc.printf("Z acceleration formatted data = %d \n", i32SensorZ); - pc.printf("Z = %2.6f g", i32SensorZ*LSB_scale_factor); + // pc.printf("%2.6f \n\r", i32SensorZ*LSB_scale_factor); + + + - pc.printf("\n"); + + t.stop(); + //pc.printf(" %d us\n\r", t.read_us()); wait1.5ms + + wait(0.01); //max0.0016 + + + } } int32_t ADXL355_Acceleration_Data_Conversion (uint32_t ui32SensorData)