cancel
Showing results for 
Search instead for 
Did you mean: 

USB Superspeed Peripherals

New Contributor

Hello,

I want to use the sample code provided by Cypress for using SPI Interface to read from and write to the SPI Slave but after falshing the image to the FX3 Dev Board and Capturing the signals(MOSI, SSN, SCK) can be seen, that the interface sends too much data over MOSI pin which could not be related to the data that I wanted to send to the slave(see the attached screenshot).

laspi.PNG

laspi1.jpg

I Think I do a failure somewhere but I'm not sure!! would someone explane me in which order should I call the following methods, Because I could not find any documentation about the methods and regarding the parameters passing to the methods:

CyU3PReturnStatus_t CyFxSpiTransfer (uint16_t  pageAddress, uint16_t  byteCount, uint8_t  *buffer, CyBool_t  isRead);

CyU3PReturnStatus_t CyFxSpiWaitForStatus (void);

static CyU3PReturnStatus_t CyFxSpiEraseSector (CyBool_t  isErase, uint8_t   sector, uint8_t  *wip);

And should I modify the code as well !?

Kind Regards

0 Likes
Reply
1 Solution
Moderator
Moderator

Hello,

For writing a piece of data into the SPI slave, you should follow the following sequence:

1. Erase the required sector by calling the function CyFxSpiEraseSector(). This function has 3 parameters and the definition is shown below:

static CyU3PReturnStatus_t

CyFxSpiEraseSector (

     CyBool_t  isErase,

     uint8_t   sector,

     uint8_t  *wip)

For erasing a sector, isErase should be set to CyTrue, sector should be the required sector where erase should be done and wip can be NULL.

So, the call can be as follows:

CyFxSpiEraseSector(CyTrue, 0, NULL);

2. Now, wait for the erase to be complete. For this, call the function CyFxSpiEraseSector() again with the parameters isErase as CyFalse, sector same as that used in step 1 and wip being a pointer which contains information that indicates whether the erase was complete or not.

So, the call can be as follows:

CyFxSpiEraseSector(CyFalse, 0, ptr);

Note that ptr should be a pointer that can hold 1 byte of data. After calling this function, if the value of ptr is 0, then the erase is complete.

3. Now, call the function CyFxSpiTransfer() to write to the slave device. This function has 4 parameters and the definition is shown below:

CyU3PReturnStatus_t

CyFxSpiTransfer (

        uint16_t  pageAddress,

        uint16_t  byteCount,

        uint8_t  *buffer,

        CyBool_t  isRead)

pageAddress is the SPI flash page address. byteCount is the number of bytes that are to be written, *buffer is a pointer to the buffer that contains the data which is to be written into the flash and isRead parameter indicates whether read or write from Flash is to be done.

So, the call can be as follows:

CyFxSpiTransfer(0x0000, 2, ptr, CyFalse);

4. Now, wait for the write to be completed. This can be done by calling the function CyFxSpiEraseSector() again with the same parameters as mentioned in step 2 until it returns 0.

5. When it returns 0, the write to flash is successful. Now, you can read the data from the flash by using the function CyFxSpiTransfer() with the last parameter set to CyTrue and all others same as that in step 3.

For detailed understanding, please refer to the readme.txt that comes along with the example project spiregmode. The same can be found in the following location:

C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\serialif_examples\cyfxusbspiregmode

Note: This path depends on the installation directory of FX3 SDK.

Please try this and let me know if you have any questions on this.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

0 Likes
Reply
1 Reply
Moderator
Moderator

Hello,

For writing a piece of data into the SPI slave, you should follow the following sequence:

1. Erase the required sector by calling the function CyFxSpiEraseSector(). This function has 3 parameters and the definition is shown below:

static CyU3PReturnStatus_t

CyFxSpiEraseSector (

     CyBool_t  isErase,

     uint8_t   sector,

     uint8_t  *wip)

For erasing a sector, isErase should be set to CyTrue, sector should be the required sector where erase should be done and wip can be NULL.

So, the call can be as follows:

CyFxSpiEraseSector(CyTrue, 0, NULL);

2. Now, wait for the erase to be complete. For this, call the function CyFxSpiEraseSector() again with the parameters isErase as CyFalse, sector same as that used in step 1 and wip being a pointer which contains information that indicates whether the erase was complete or not.

So, the call can be as follows:

CyFxSpiEraseSector(CyFalse, 0, ptr);

Note that ptr should be a pointer that can hold 1 byte of data. After calling this function, if the value of ptr is 0, then the erase is complete.

3. Now, call the function CyFxSpiTransfer() to write to the slave device. This function has 4 parameters and the definition is shown below:

CyU3PReturnStatus_t

CyFxSpiTransfer (

        uint16_t  pageAddress,

        uint16_t  byteCount,

        uint8_t  *buffer,

        CyBool_t  isRead)

pageAddress is the SPI flash page address. byteCount is the number of bytes that are to be written, *buffer is a pointer to the buffer that contains the data which is to be written into the flash and isRead parameter indicates whether read or write from Flash is to be done.

So, the call can be as follows:

CyFxSpiTransfer(0x0000, 2, ptr, CyFalse);

4. Now, wait for the write to be completed. This can be done by calling the function CyFxSpiEraseSector() again with the same parameters as mentioned in step 2 until it returns 0.

5. When it returns 0, the write to flash is successful. Now, you can read the data from the flash by using the function CyFxSpiTransfer() with the last parameter set to CyTrue and all others same as that in step 3.

For detailed understanding, please refer to the readme.txt that comes along with the example project spiregmode. The same can be found in the following location:

C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\serialif_examples\cyfxusbspiregmode

Note: This path depends on the installation directory of FX3 SDK.

Please try this and let me know if you have any questions on this.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

0 Likes
Reply