cancel
Showing results for 
Search instead for 
Did you mean: 

USB Superspeed Peripherals

user_4790841
New Contributor II

Hello,

I'm using the Cypress example code projects to try to get data from an accelerometer (ADcmXL3021). I'm using the UsbSpiDmaMode project, where I've merged GPIO functionality into it.

When I'm trying to communicate with the accerlerometer, I'm using SPI communication. The UsbSpiDmaMode already has functions set up for this; CyFxSpiTransfer (programmer application), which uses the two functions CyU3PSpiTransmitWords and CyU3PSpiReceiveWords.

Currently, I've tried making my own functions to write and read data over the SPI interface. They look as follows:

pastedImage_2.png

with startSampling() and readData().

As you can see I pass in 0x3E, 0x08, 0x00 as my input, which you can also read in the datasheet for the accelerometer are the registers that start recording data. The datasheet can be found here:

https://www.analog.com/media/en/technical-documentation/data-sheets/ADcmXL3021.pdf#page=42&zoom=100,...

(where 0x3E is the address for GLOB_CMD and 0x08 (0x0800) is the address to start recording).

My output gives the same values, which implies that I'm using the functions incorrectly. Below, my data value (200 entries) are seen from the UART debugger:

pastedImage_4.png

It would obviously be best if I could use the given function, CyFxSpiTransfer, but I get stuck in the CyFxSpiWaitForStatus() function when I try using it with the call: CyFxSpiTransfer(0x003E, 0x0800, 4, CyFalse)

(I'm unsure what the 3rd parameter means (*buffer).

I've seen you're employee, juchong, has made a GitHub FX3 API which includes this accelerometer, but I can't seem to understand it and how it works (I'm new to this world). It's found here:

GitHub - analogdevicesinc/iSensor-FX3-API: A .NET API and firmware for the Cypress FX3 USB interface...

Moreover, can I use the CyU3PSpiTransferWords function to combine the two (transmit and recieve) into one? If so, that would be much better of course.

If you could tell me where I go wrong, in the calls of the given functions, it would help me out very much! I hope it's a simple fix. All I want to do is invoke the RTS mode (later the MFFT mode) of the ADcmXL3021 accelerometer, and get a single reading of the mode for each iteration call from the main function of my program (located in the AppThread_entry function). The AppThread_entry function looks like below:

pastedImage_13.png

Hope I've provided enough information, other please tell me if you need more information. I've also attached the C-file to this message.

Sincerely,

Søren

0 Likes
1 Solution
Rashi_Vatsa
Moderator
Moderator

Hello Søren,

I have modified the file shared by you, please try using this and let me know if it works.

The following modifications are done:

- The startsampling() and readdata() are combined into readdata() API. Please refer to readdata API for more details

- The vendor command 0xC3 (CY_FX_RQT_SPI_FLASH_READ) is used to get the read data. You can read the data on the control center itself by passing the 0xC3 vendor command (Direction: IN)

Please replace this file in the your firmware and let me know if it helps

Regards,

Rashi

Regards,
Rashi

View solution in original post

0 Likes
9 Replies