Kinetis DSPI on PE

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

Kinetis DSPI on PE

Jump to solution
1,620 Views
japex92
Contributor I
Hello,

I am writing to know exactly how the DSPI bean works on the PE for the kinetis family (k53 and K60 to be precise). I have

followed a tutorial from freescale (Freescale Technical Information Center) and got the TX working properly; but I still don't get how TX and RX are set independently if the protocol is achieved by shifting the registers involved in the communication. I did activate the events related to SPI  SM1_ReceiveBlock and SM1_SendBlock, but dont know how to syncronize both if I have to receive data while it's transmiting.

I have also tried this on other code:

#define READ_SPI_FLASH_DATA()                 (unsigned char)SPI2_POPR

#define WAIT_SPI_RECEPTION_END()           while (!(SPI2_SR & SPI_SR_RFDF)) {}

#define CLEAR_RECEPTION_FLAG()              SPI2_SR |= SPI_SR_RFDF

#define WRITE_SPI_CMD0_LAST(byte)           SPI2_PUSHR = (byte | SPI_PUSHR_EOQ  | ulChipSelectLine | SPI_PUSHR_CTAS_CTAR0) // write final byte to output FIFO - this will negate the CS line when complete

WRITE_SPI_CMD0(0xff);                                    // write dummy

while( SPI_SR_EOQF != (SPI2_SR & SPI_SR_EOQF));

SPI2_SR = SPI2_SR | SPI_SR_EOQF | SPI_SR_TCF ;

SPI2_MCR |= 0xC01; // halt = 1

WAIT_SPI_RECEPTION_END();                                        // wait until at least one byte is in the receive FIFO

(void)READ_SPI_FLASH_DATA();                                     // discard

CLEAR_RECEPTION_FLAG();                                          // clear the receive flag

Please advise me what to do and how to read the RX buffer when transfering data bytes

0 Kudos
1 Solution
450 Views
Petr_H
NXP Employee
NXP Employee

Hello,

Transmitting and receiving is synchronous, as there is only one clock. However, there might be some sync issues beacuse of hardware FIFO. If you'd like to keep synchronized reading and writing, I recommend to do both reading and writing for the whole communication, wait for end of reading and just discard chars that you don't need.

You can find some sample code at the 'Typical usage' pages in the help of  Processor Expert SPIMaster_LDD component. Use the 'Help on component' pop-up menu command of the component in your project or in the Components Library and select 'Typical usage' on the left of the page.

Generally, the basic code without using interrupts looks like this:

  ...

  MySPIPtr = SM1_Init(NULL);                               /* Initialization of SM1 component */

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE); /* Request data block reception */

  Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE);    /* Start transmission/reception */

  while (!SM1_GetBlockReceivedStatus(MySPIPtr)) {          /* Wait until data block is transmitted/received */

    SM1_Main(MySPIPtr);

  }

...

best regards

Petr Hradsky

Processor Expert Support and Servicepacks Team

View solution in original post

0 Kudos
2 Replies
451 Views
Petr_H
NXP Employee
NXP Employee

Hello,

Transmitting and receiving is synchronous, as there is only one clock. However, there might be some sync issues beacuse of hardware FIFO. If you'd like to keep synchronized reading and writing, I recommend to do both reading and writing for the whole communication, wait for end of reading and just discard chars that you don't need.

You can find some sample code at the 'Typical usage' pages in the help of  Processor Expert SPIMaster_LDD component. Use the 'Help on component' pop-up menu command of the component in your project or in the Components Library and select 'Typical usage' on the left of the page.

Generally, the basic code without using interrupts looks like this:

  ...

  MySPIPtr = SM1_Init(NULL);                               /* Initialization of SM1 component */

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE); /* Request data block reception */

  Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE);    /* Start transmission/reception */

  while (!SM1_GetBlockReceivedStatus(MySPIPtr)) {          /* Wait until data block is transmitted/received */

    SM1_Main(MySPIPtr);

  }

...

best regards

Petr Hradsky

Processor Expert Support and Servicepacks Team

0 Kudos
450 Views
matheuskotaki
Contributor I

How can I send binary data instead of characters?

0 Kudos