Why is my script not working for getting data from ADcmXL3021?


I've been trying to configure my FX3 board (Cypress SuperSpeed Explorer Kit) up with my ADcmXL3021 accelerometer. This is the board (& kit)


I've had success in configuring up the UART debugger in the board (such that I can send my data over it) and SPI connection to the accelerometer, but I cannot seem to get the correct data. I'm using the most simple configuration of the RTS mode, just to try to get some raw data output from the device.

I've uploaded my script file, where the main focuses of the script lie in AppThread_entry on line 782 where I

  • Initialize a databuffer[200] variable to store all the data we get from the accerlerometer in one iteration, as seen by the data format

  • Initialize the debug interface (UART)
  • Initialize the SPI communication connection
  • Go into an infinite loop:
    • Call startSampling(), sleep for a minimum of 12 milliseconds, and then call readData(databuffer), that stores all the sampled data in the databuffer.
    • Loop through the data and print it out through the UART debugger (to a terminal).

The AppThread_entry function can be seen below:

The startSampling function opens the SPI connection, sends a data array of (0x3E, 0x08, 0x00) for the register address and start command (and a space allocater) respectively. We send this over the SPI connection, with 3 bytes specified. We close the connection afterwards.

The readData function opens the SPI connection, reads the buffer and stores it in the databuffer, and closes the SPI connection.

The two functions can be seen below

I somehow get the wrong output, as seen by the output terminal window below:

(I've converted it to the ASCII equivalent, as you could see from the AppThread_entry function)

Does anyone know what I'm doing wrong? Am I calling things wrong? The code can be found here:


I'm not used to working with microcontrollers and sensors, so this is all very new to me. Hope you can help me.