How to setup KEA128 SPI0 at PTE0~3?

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

How to setup KEA128 SPI0 at PTE0~3?

929 Views
younghwanbae
Contributor II

I added below code for changing pin to PTE0~3,

SIM_PINSEL0 |= SIM_PINSEL_SPI0PS_MASK;// set PTE0~3 as SPI0

I'm using below functions.

void SPI_Write(SPI_MemMapPtr base, uint8 u8Write)

{

  while (!SPISR_SPTEF(base));   /* sending finish? */

  SPI_D_REG(base) = u8Write;

}

uint8 SPI_Read(SPI_MemMapPtr base)

{

  while(!SPISR_SPRF(base)); /* read finish? */

  return SPI_D_REG(base);

}

I tested simple code like below,

CS0_LOW();

SPI_Write();               // 1 byte write

SPI_Read();               // 1 byte read

CS0_HIGH();

But, problem is write function looks like normal, but read function doesn't work.

when CS goes LOW, only 8 clocks out.

Looks like "SPISR_SPRF(base)", is already set.

How can I solve this problem?

Labels (1)
0 Kudos
Reply
3 Replies

715 Views
derek_lau
Contributor III

SPI is a bi-directional communication with write and read at the same time.

What you need is:

SPI_WRITE

SPI_DUMMY_READ          // clear SPRF

SPI_DUMY_WRITE           // write any data

SPI_READ

0 Kudos
Reply

715 Views
younghwanbae
Contributor II

Actually I connected SPI0 port with SPI_Flash memory.

It's time should be like below.

CS       ---_______________________________________----

MOSI   ---<cmd><data><data><data>-----------------------------

MISO   --- ----------------------------------<data><data><data>---

But, KEA128' output is

SS        ---_____--____--____--____--_____--____--____----

In this case I cannot use SS pin as CS, can I?

I should program SPI slave mode also work like above.

How can I make slave mode of KEA128's SPI like this?

Regards,

Younghwan

0 Kudos
Reply

715 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

When you want to use KEA128 PTE0~3 pins as SPI0 module related pin, it need to set SIM_PINSEL0[SPI0PS] bit.

After that, for you want to use KEA128 SPI0 as master to read data from external SPI Flash, it need to enable SPI0_C1[MSTR] bit to set SPI0 module works as master.

Wish it helps.


Have a great day,
Ma Hui

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

0 Kudos
Reply