Kinetis MK21 SPI slave issue

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

Kinetis MK21 SPI slave issue

Jump to solution
802 Views
pkaar
Contributor I

Dear all,

I am facing problems when transmitting data via SPI when the controller acts as SPI slave. I configured the SPI module to use RX and TX FIFO buffers and disabled all interrupt requests.

When transmitting data in polling mode the SPIx_SR[TFFF] bit will never be cleared, although I am writing more than 4 values to it. My idea is to write to the TX buffer as long as it is not full, and wait in a busy loop for free space.

Is this a known issue or am I just doing something wrong?

Best regards,

Philipp

Labels (1)
0 Kudos
1 Solution
583 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Philipp Kaar

Sorry for the late reply. According to the Reference manual for this MCU:

TFFF flag clears automatically when DMA is used to fill TX FIFO.

To clear TFFF when not using DMA, follow these steps for every PUSH performed using CPU to fill TX FIFO:

  1. Wait until TFFF = 1.

  2. Write data to PUSHR using CPU.

  3. Clear TFFF by writing a 1 to its location. If TX FIFO is not full, this flag will not clear.

I made some test and SPIx_SR[TFFF] is successfully clearing after 4 writes in the TX FIFO, so could you share how you write and check that this flag is not clearing to try to find your problem?

An important consideration to take with this flag is that TFFF take is cleared just when the buffer is filled, but if you have started transfers, every time you write to the SPIx_PUSHR register, the data will be shifted. Hence, it is important that meanwhile you write to the TX FIFO register you have stopped transfers. Here is part of my code of how I wirte to the register:

SPI0_MCR |= SPI_MCR_HALT_MASK;    //this just to be sure that is "Stop transfers".
char Master_TXval[4] = {0xB,0xC,0xD,0XE};
Master_send(Master_TXval); //master send value‍‍‍‍‍‍
SPI0_MCR &= ~SPI_MCR_HALT_MASK; //Start transfers.‍‍‍‍‍‍‍‍

Where

void Master_send(char * mstr_val)
{
char i=0;
    while((SPI0_SR & SPI_SR_TFFF_MASK))
    {
    SPI0_PUSHR = mstr_val[i++] | SPI_PUSHR_CTCNT_MASK | SPI_PUSHR_PCS(0x01);
    SPI0_SR     = SPI_SR_TFFF_MASK; //clear TFFF flag
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hope this information help you.
Have a great day,
Jorge Alcala

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

View solution in original post

0 Kudos
1 Reply
584 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Philipp Kaar

Sorry for the late reply. According to the Reference manual for this MCU:

TFFF flag clears automatically when DMA is used to fill TX FIFO.

To clear TFFF when not using DMA, follow these steps for every PUSH performed using CPU to fill TX FIFO:

  1. Wait until TFFF = 1.

  2. Write data to PUSHR using CPU.

  3. Clear TFFF by writing a 1 to its location. If TX FIFO is not full, this flag will not clear.

I made some test and SPIx_SR[TFFF] is successfully clearing after 4 writes in the TX FIFO, so could you share how you write and check that this flag is not clearing to try to find your problem?

An important consideration to take with this flag is that TFFF take is cleared just when the buffer is filled, but if you have started transfers, every time you write to the SPIx_PUSHR register, the data will be shifted. Hence, it is important that meanwhile you write to the TX FIFO register you have stopped transfers. Here is part of my code of how I wirte to the register:

SPI0_MCR |= SPI_MCR_HALT_MASK;    //this just to be sure that is "Stop transfers".
char Master_TXval[4] = {0xB,0xC,0xD,0XE};
Master_send(Master_TXval); //master send value‍‍‍‍‍‍
SPI0_MCR &= ~SPI_MCR_HALT_MASK; //Start transfers.‍‍‍‍‍‍‍‍

Where

void Master_send(char * mstr_val)
{
char i=0;
    while((SPI0_SR & SPI_SR_TFFF_MASK))
    {
    SPI0_PUSHR = mstr_val[i++] | SPI_PUSHR_CTCNT_MASK | SPI_PUSHR_PCS(0x01);
    SPI0_SR     = SPI_SR_TFFF_MASK; //clear TFFF flag
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hope this information help you.
Have a great day,
Jorge Alcala

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

0 Kudos