AnsweredAssumed Answered

SPI clock mode 0 polarity wrong (inverted)

Question asked by Simon Wyss on Apr 18, 2017
Latest reply on Apr 21, 2017 by Simon Wyss

While testing the SPI clock modes I measured the following graphs with my logic analyzer:


SPI clock mode 0:


SPI clock mode 1:

SPI clock mode 2:


SPI clock mode 3:


My SPI settings:
Master Mode
MSB first
Data Length: 8 Bit


I used no high level functions to start the transfer.


The code used is mainly from the periph_spi_sm_int example in the LPCopen lib.


#define LPC_SPIMASTERPORT                   LPC_SPI1

static void setupSPIMaster(void)
     SPI_CFGSETUP_T spiSetup;
     //SPIM_DELAY_CONFIG_T masterDelay;

     /* Initialize SPI controller */

     /* Call to initialize first SPI controller for mode0, master mode,
        MSB first */

     spiSetup.master = 1;
     spiSetup.lsbFirst = 0; //0=MSB first
     spiSetup.mode = SPI_CLOCK_MODE3;
     Chip_SPI_ConfigureSPI(LPC_SPIMASTERPORT, &spiSetup);

     /* Setup master controller SSEL0 for active low select */
     //Chip_SPI_SetCSPolLow(LPC_SPIMASTERPORT, 0);

     /* Setup master clock rate, slave clock doesn't need to be setup */

     //set SPI transmit length to 8 bit
     Chip_SPI_SetXferSize(LPC_SPIMASTERPORT, 8);


To write a byte out by SPI I used the following code:

//write single byte to SPI1
while(!(Chip_SPI_GetStatus(LPC_SPI1) & (SPI_STAT_TXRDY) ) ); //wait until ready to transmit
Chip_SPI_WriteTXData(LPC_SPI1, 0x02);  //write 0x02 to SPI1
//read single byte from SPI1
while((Chip_SPI_GetStatus(LPC_SPI1) & (SPI_STAT_RXRDY) ) ); //wait until one byte received
spiValue =  Chip_SPI_ReadRXData(LPC_SPI1);


In my opinion the SPI clock Mode 1 and 3 are correct working.

However the Mode 0 and 2 are not working correct.

In Mode 0 the clock should stay low in idle state and in Mode 2 it should stay high.


User manual UM10850 (LPC54102)



I set the slave select (chip select) by my selfe. I didn't want to use the slave select automatic. 


Did I configure something wrong?