AnsweredAssumed Answered

SPI PCS0 control

Question asked by Robert Gilmore on Feb 15, 2017
Latest reply on Feb 21, 2017 by Mark Butcher

TWR-K60D100M Platform.

I am using the SPI sample code, spi_demo, for SPI2, which includes hal_spi.c. I am trying to set PCS0 to ‘1’ at the start of transmitting a number of bytes and to ‘0’ at the completion.

My interpretation of the code in hal_spi_transfer_one_byte(u8 v, Bool end) suggests this should already be achieved in this code, but the output remains at ‘0’. I’ve also tried specifically configuring PCS0 as a output after selecting the port as a GPIO in init_io, but to no avail.


u8 hal_spi_transfer_one_byte(u8 v, bool end)




                                    SPI_PUSHR_EOQ_MASK  |                   // sets bit 31 to ‘0’ to negate selected PCS after last byte

                                                                                                      //  transmitted, EOQ - Last byte

                                   SPI_PUSHR_PCS(1<<0) |                       // select PCS0



        SPI2_PUSHR = SPI_PUSHR_CONT_MASK |                // Maintain PCS output

                                   SPI_PUSHR_PCS(1<<0) |                     // select PCS0



    while((SPI2_SR & SPI_SR_TCF_MASK)==0)                       // Wait until transfer complete



    return SPI2_POPR&0xff;



The actual SPI transmission works fine.


Any help to determine what I am doing wrong and why I cannot control PCS0 would be appreciated.