FX3 SPI Communication

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ShPe_4630301
Level 2
Level 2
First like given

Hello there,

I'm using the FX3 Dev Board and I'd like to configure a Slave device over the SPI Interface. Simultaneously, the UART Interface is being used for Debug purposes. Following is a sample of the code:

CyU3PDebugPrint (2, "Address of Data: %X \r\n", &data);

CyU3PDebugPrint (2, "Data: %X\r\n", data);

CyU3PReturnStatus_t status =  CyU3PSpiTransferWords (&data,1,response,1);

CyU3PDebugPrint (2, "SPI MOSI Transmission status: %X\r\n", status);

so far, it's working well and data can be exchanged between SPI Master and Slave.

but once the CyU3PDebugPrint() calls are commented out(UART Block of FX3 is still configured and pins are still connected correctly.), the data can not be transferred to the slave any more. does anyone know why?

0 Likes
1 Solution

Hello,

Please try adding the API CyU3PThreadSleep(1000); before calling CyU3PSpiTransferWords() and let me know if you are seeing any difference.

If this does not help, please probe the SPI lines for the following cases and share it with me:

1. The debugprint API used.

2. The debugprint API is commented off and without using CyU3PThreadSleep(1000);.

3. The debugprint API is commented off and CyU3PThreadSleep(1000); is used.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

0 Likes
11 Replies
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

According to my understanding you are using Superspeed Explorer Kit (CYUSB3KIT-003). Please correct me if Iam wrong.

Also, please confirm that the issue that you are seeing is both UART and SPI cant work together but SPI alone works. If not, please elaborate the issue.

In addition to this, please let me know which firmware you are using. Is it an SDK example? If not, please share the firmware so that I can check the IO matrix configuration to debug the issue better.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

Hello Jayakrishna,

I'm using the CYUSB3KIT-003. The Issue is as follows:

  • SPI and UART work together well, SPI alone not.

Actually everything works as long as the Print Functions are there, once they are commented out, the code does not work any more.

As I described it above, the following snapshot of code works very well:

uint8_t spiSendDataToSlave(uint8_t data)

{

    uint8_t* response;

    CyU3PDebugPrint (2, "Address of Data to be sent: %X \r\n", &data);

    CyU3PDebugPrint (2, "Data to be sent: %X\r\n", data);

    CyU3PReturnStatus_t status =  CyU3PSpiTransferWords (&data,1,response,1);

    CyU3PDebugPrint (2, "SPI MOSI Transmission status: %X\r\n", status);

    return status;

}

but following code does not work:

uint8_t spiSendDataToSlave(uint8_t data)

{

     uint8_t* response;

     //CyU3PDebugPrint (2, "Address of Data to be sent: %X \r\n", &data);

     //CyU3PDebugPrint (2, "Data to be sent: %X\r\n", data);

     CyU3PReturnStatus_t status =  CyU3PSpiTransferWords (&data,1,response,1);

     //CyU3PDebugPrint (2, "SPI MOSI Transmission status: %X\r\n", status);

     return status;

}

As you see I don't change anything, just the Print functions have been commented out. The IO-Matrix remain unchanged as follows(from SlaveFifoSync example):

int main (void)

{

CyU3PIoMatrixConfig_t io_cfg;

    CyU3PReturnStatus_t status = CY_U3P_SUCCESS;

    CyU3PSysClockConfig_t clkCfg;

        /* setSysClk400 clock configurations */

        clkCfg.setSysClk400 = CyTrue;   /* FX3 device's master clock is set to a frequency > 400 MHz */

        clkCfg.cpuClkDiv = 2;           /* CPU clock divider */

        clkCfg.dmaClkDiv = 2;           /* DMA clock divider */

        clkCfg.mmioClkDiv = 2;          /* MMIO clock divider */

        clkCfg.useStandbyClk = CyFalse; /* device has no 32KHz clock supplied */

        clkCfg.clkSrc = CY_U3P_SYS_CLK; /* Clock source for a peripheral block  */

    /* Initialize the device */

    status = CyU3PDeviceInit (&clkCfg);

    if (status != CY_U3P_SUCCESS)

    {

        goto handle_fatal_error;

    }

    status = CyU3PDeviceCacheControl (CyTrue, CyFalse, CyFalse);

    if (status != CY_U3P_SUCCESS)

    {

        goto handle_fatal_error;

    }

    io_cfg.useUart   = CyTrue;

    io_cfg.useI2C    = CyFalse;

    io_cfg.useI2S    = CyFalse;

    io_cfg.useSpi    = CyTrue;

    io_cfg.s0Mode = CY_U3P_SPORT_INACTIVE;

    io_cfg.s1Mode = CY_U3P_SPORT_INACTIVE;

    io_cfg.isDQ32Bit = CyFalse;

    io_cfg.lppMode   = CY_U3P_IO_MATRIX_LPP_DEFAULT;

    io_cfg.gpioSimpleEn[0]  = 0;

    //io_cfg.gpioSimpleEn[1]  = 0;

    io_cfg.gpioSimpleEn[1]  = 0;

    io_cfg.gpioComplexEn[0] = 0;

    io_cfg.gpioComplexEn[1] = 0;

    status = CyU3PDeviceConfigureIOMatrix (&io_cfg);

    if (status != CY_U3P_SUCCESS)

    {

        goto handle_fatal_error;

    }

    /* This is a non returnable call for initializing the RTOS kernel */

    CyU3PKernelEntry ();

    /* Dummy return to make the compiler happy */

    return 0;

handle_fatal_error:

    /* Cannot recover from this error. */

    while (1);

}

I'm using SDK 1.3.

Kind Regards

Shervin

0 Likes

​EDITTED

Hello,

Please try using SDK 1.3.4 if you are not using this version of SDK. This is the latest version of FX3 SDK. The link to the same is given below:

https://www.cypress.com/documentation/software-and-drivers/ez-usb-fx3-software-development-kit

If this does not work, please share the following details:

1. The .c file of the project so that I can understand it better.

2. Have you used an external UART controller on IO(46:49) to get the debug logs? If not, then how are you getting the debug logs?

3. Please let me know the return value of CyU3PSpiTransferWords() when it fails.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
lock attach
Attachments are accessible only for community members.

Hi Jayakrishna,

I attached the c file to this thread. I'm Using the pins 46-49 to get the debug logs.

Kind regards

Shervin

0 Likes

Hello,

Please let us know the following:

1. Have you connected an external UART controller to IO (46:49) for getting the UART logs?

2. What is the error code when CyU3PSpiTransferWords() fails?

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

Hello,

I'm using an FTDI TTL-232RG to get the debug logs. As I mentioned, the DEV-Board suspends and the LED2 (LED2 as shows in following image) goes blue, in this case it is not possible to capture the status code because there is no return after calling CyU3PSpiTransferWords function.

1.jpg

Kind regards

Shervin

0 Likes

Hello,

Please confirm that the only difference between the working and failing case is that the debug print APIs inside the function SPIWriteDataToSlave() have been commented out. If not, please let me know what are the other differences.

Please share the complete project so that I can debug the issue.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

Hello,

This is only the failing case, as the debug prints are commented out, it fails. For some reasons related to my company, I have no possibility to provide the hole project. but I can assure you that the Problem raised from the issue, I pointed.

Kind regards

Shervin

0 Likes

Hello,

Please do the following modifications and let me know the result:

1. In the main() set the parameter ClkCfg.setSysClk400 to CyFalse.

2. Disable the UART in the IO_MATRIX and comment out all the UART related functions and the debugprints from the code.

3. Please remove the UART controller from the board.

After trying out the above suggestions, please check if you are seeing the issue again.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

Hi Jayakrishna,

I did everything you had mentioned but it caused the same Failure. No Success.

Kind Regrads

Shervin

0 Likes

Hello,

Please try adding the API CyU3PThreadSleep(1000); before calling CyU3PSpiTransferWords() and let me know if you are seeing any difference.

If this does not help, please probe the SPI lines for the following cases and share it with me:

1. The debugprint API used.

2. The debugprint API is commented off and without using CyU3PThreadSleep(1000);.

3. The debugprint API is commented off and CyU3PThreadSleep(1000); is used.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes