SPI Mode on KEA128

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI Mode on KEA128

Jump to solution
1,909 Views
testbed
Contributor III

Hello Everyone,

I am using the KEA128 controller in one of my projects which requires communication over the SPI bus with CPOL=1 and CPHA=1. I've configured the SPI like shown below. However, i am not sure about the CPHA setting for SPI MODE3

   /* initialize SPI0 as master    */
    sSPIConfig.u32BitRate = SPI_BIT_RATE;  //1000000 - 1 MHz
    sSPIConfig.u32BusClkHz = BUS_CLK_HZ;  // 20000000 - Internal Clk Oscillator - 20.97 MHz
    sSPIConfig.sSettings.bModuleEn             = 1;
    sSPIConfig.sSettings.bMasterMode           = 1;
    sSPIConfig.sSettings.bClkPhase1            = 1;
    sSPIConfig.sSettings.bClkPolarityLow       = 1;
    sSPIConfig.sSettings.bMasterAutoDriveSS    = 0;

My SPI read write functions are as below. I am using the SPI library provided in the KEA quickstart package.

I would like to know if the above settings and below operations would work in SPI MODE3 or not, as i am observing

that even though there is data on MISO, the SPI read operation returns 0xff. The read operation is shown below. The MISO line is pulled up on the SPI device side since its a open drain line.

READ_OP.png

void spi_write_array(uint8_t len, // Option: Number of bytes to be written on the SPI port
                     uint8_t data[] )
{
    volatile uint8_t dummy_read = 0;
    
  for (uint8_t i = 0; i < len; i++)
  {
        /* spi_write((int8_t)data[i]); */
        while(!SPI_IsSPTEF(SPI0)){ dummy_read++; };  // empty while loop warning workaround
        SPI_WriteDataReg(SPI0, data[i]);        
        
        while(!SPI_IsSPRF(SPI0));
        dummy_read = SPI_ReadDataReg(SPI0);

 }

}

void spi_write_read(uint8_t tx_Data[],//array of data to be written on SPI port
                    uint8_t tx_len, //length of the tx data arry
                    uint8_t *rx_data,//Input: array that will store the data read by the SPI port
                    uint8_t rx_len //Option: number of bytes to be read from the SPI port
                   )
{
    volatile uint8_t dummy_read;
    
  for (uint8_t i = 0; i < tx_len; i++)
  {
    /* spi_write(tx_Data[i]); */
        
        while(!SPI_IsSPTEF(SPI0)){ dummy_read++; };
        SPI_WriteDataReg(SPI0, tx_Data[i]);
        
      while(!SPI_IsSPRF(SPI0));
        dummy_read = SPI_ReadDataReg(SPI0); // discard
    
  }
    
  for (uint8_t i = 0; i < rx_len; i++)
  {
    /* rx_data[i] = (uint8_t)spi_read(0xFF); */
        while(!SPI_IsSPTEF(SPI0)){ dummy_read++; };
        SPI_WriteDataReg(SPI0, 0xFF);
        
        while(!SPI_IsSPRF(SPI0));
        rx_data[i] = SPI_ReadDataReg(SPI0);
        
  }

}

Thanks.

0 Kudos
1 Solution
1,172 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi testbed,

    You can disable the NMI, but please note, when you power off the board , and power it again, you should make sure this NMI pin which is connect to other device is high.

   Otherwise, if it is low when your board is powered on, it will cause your board can't startup, this is really very important.

    So, normally, in the pratical usage, we don't recommend the customer to use the NMI as the other function in the KE, KEA series.

 

Wish it helps you!

If your problem is solved, please help to mark the correct answer to close this post.

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
---------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
4 Replies
1,173 Views
testbed
Contributor III

So i figured the problem out. Apparently for this controller SPI0 MISO is also the NMI pin which needs to be switched to SPI MISO in the SOPT0 register...

SIM->SOPT0 &= ~SIM_SOPT0_NMIE_MASK

Problem solved...

1,173 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi testbed,

    You can disable the NMI, but please note, when you power off the board , and power it again, you should make sure this NMI pin which is connect to other device is high.

   Otherwise, if it is low when your board is powered on, it will cause your board can't startup, this is really very important.

    So, normally, in the pratical usage, we don't recommend the customer to use the NMI as the other function in the KE, KEA series.

 

Wish it helps you!

If your problem is solved, please help to mark the correct answer to close this post.

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
---------------------------------------------------------------------------------------------------------------------

0 Kudos
1,173 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi testbed,

    SPI0_MISO also can assigned in PTE2, you don't need to assign it to the NMI pin.

   Please set SIM_PINSEL0[SPI0PS]=1, then

SPI0_SCK, SPI0_MOSI, SPI0_MISO, and SPI0_PCS are mapped on PTE0, PTE1, PTE2, and PTE3.

Wish it helps you!

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
---------------------------------------------------------------------------------------------------------------------

1,173 Views
testbed
Contributor III

Hello Kerry,

Thank You for the info. However, the board i designed has SPI0_MISO connected to PTB port pins. So no choice there, unless i revise the board design....

0 Kudos