SPI and I2C non blocking transfer

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

SPI and I2C non blocking transfer

4,426 Views
gn2303
Contributor I

Hi all,
I'm trying to execute and interrupt based I2C and SPI transfer on a kl27z MCU. Examples from the SDK points to the use of SPI/I2C_MasterTransferNonBlocking with a callback function to indicate transfer is finished. However I couldn't quite understand how TransferNonBlockin works and when the interrupt is triggered. Can anyone enlighten me? Also, I would like to know the correct way of setting up FIFO in SPI1 as it is not stated anywhere in the examples.

 

Thanks

Labels (1)
0 Kudos
Reply
4 Replies

3,078 Views
xiangjunrong
Contributor IV

Hi, Gabriel,

I am sorry for the delay.

Regarding your question, pls refer to the example in SDK2.0.

D:\Freescale\KSDK2.0_KL27\boards\frdmkl27z\driver_examples\spi

Regarding the driver of SDK, I think this is the software architecture. The SPI uses interrupt mechanism to transfer data, user calls the high level api function to transfer data via the large buffer instead of the direct module register, the SPI interrupt service routine writes the data from the buffer to SPI transmitter register, or read the SPI receiver register to buffer. user is required to call high level api function to write data to the buffer or read data from the buffer.

If you use RTOS, a semaphore is established, in the ISR, sem_post() is called. In the transfer function, sem_wait() is called, at the same time, the chip is blocked at the sem_wait() function.

If you do not use RTOS, you can call the SPI_MasterTransferNonBlocking(), "NonBlocking" means that the api function returns immediately after writting the transmitted data to the buffer. You can call the  SPI_MasterTransferBlocking(), "Blocking" means that the function has a while() loop, which polls if the predefined number of data has been been transferred, after all data have been transferred, the api function can return. In both SPI_MasterTransferNonBlocking() and SPI_MasterTransferBlocking(), callback function is supported, after the number of data has been transferred, the callbacl function is called automatically.

Hope it can help you.

BR

XiangJun Rong

3,078 Views
darnaiadam
Contributor III

Hi XiangJun!

I found this topic about SPI communication with nonblocking function, and I've got a question about it:

Is it necessary to make my own callback function? I tried to use the "DSPI_MasterTransferNonBlocking" function without it, and during the debug my program ran into a "Sigtrap" after the assert(g_dspiHandle[0]); line in the SPI0 IRQ Handler. I currently use SDK2.1 for Kinetis K65.

0 Kudos
Reply

3,078 Views
xiangjunrong
Contributor IV

Hi,

You can set the FIFOMODE bit in SPIx_C3 to enable FIFO, if you use FIFO mode, the KL27 can increase it's efficiency, for example, you can write 8 byte in  ISR instead of one as usual.

BR

Xiangjun Rong

0 Kudos
Reply

3,076 Views
gn2303
Contributor I

Bump!

Any help guys? I've been reviewing the example and the SDK manual and currently still confused...

0 Kudos
Reply