cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

CaHi_1120211
New Contributor II

I'm trying to use an SPI master interface on a project with a CYBLE-022001-00.  Using PSoC Creator 4.1, the only SPI block available is V4.0.

The example provided uses V2.5, which apparently has a completely different API.

Because of pinout issues, I have to use firmware-driven slave selects, and I need to determine when the transfer is complete so I can release the slave select.  I only need to send data out, no need for anything coming back.

The examples and all the discussions I can find here all refer to using SPI_ReadTxStatus(), but that's not available with the V4.0 API.

Basically, I need to do this (from other threads on this board):

    SS_Write(0);                //SS low --> Communication between Master and Slave starts

    SPI_WriteTxData(value);    /* Send data byte */

    while (!(SPI_ReadTxStatus() & SPI_STS_SPI_DONE));

    SS_Write(1);                // Transfer to slave is done

The problem is that SPIM_ReadTxStatus() no longer exists.

How do you check the transmit status with the V4.0 API?

I've tried using the

    SPI_SpiUartWriteTxData(value);

    while (!SPI_SpiIsBusBusy());  // wait for transfer to start

    while (SPI_SpiIsBusBusy());  // wait for transfer to end

    SS_Write(1);                // Transfer to slave is done

but it occasionally hangs on the first while - if the timer interrupt routine happens to fall while it's in that loop, then by the time it comes back from the ISR, the entire transfer is over so the SPI bus is not busy again - forever!

I don't want to disable interrupts for that period because it can be up to 2 SCLK clocks after you write data before the , according to the data sheet for the SCB:

"SPI Master does not assign slave select line immediately after the first word is written into TX FIFO. It takes up to 2 SCLK clocks to assign slave select. Until this happens the bus considered not busy."

Any insights would be greatly appreciated!

0 Likes
1 Solution
cadi_1014291
Valued Contributor

Hi (op) Carlos,

With SPI_SpiIsBusBusy being not available i meant you can't use it because you are not using the embedded /SS pin of the component, from the SPI SCB datasheet:

spi_state.png

So using the number of bytes on the Tx Buffer to determine when the transfer was completed seems the way to go. If you solve your issue let us know.

Regards,

Carlos.

View solution in original post

0 Likes
6 Replies