Hello Roberto,
- In order to clear SPIx_S[MODF] flag you need to write any value that you want to SPIx_C1 register, I would suggest to set the SPIx_C1[MSTR] bit due when MODF bit is set, SPI module is configured as slave and MSTR value is cleared, so you can enable this bit again:
if (SPI0->S & SPI_S_MODF_MASK)
{
uint8_t temp = SPI0->C1 | SPI_C1_MSTR_MASK;
SPI0->C1 = temp;
}
Or simply:
if (SPI0->S & SPI_S_MODF_MASK)
{
SPI0->C1 |= SPI_C1_MSTR_MASK;
}
Remember that in order to clear this flag, MODF condition must be removed (SS input should detect a high level voltage), otherwise, this MODF flag won't be cleared.
- In Kinetis Family, some flags need to be written by '1' in order to clear them, in this case, you need to modify the MKE02Zx.h file and add the _IO feature in the SPI_S register:

This way you will be able to write to this register and clear the flag:
if (SPI0->S & SPI_S_SPMF_MASK)
{
SPI0->S |= SPI_S_SPMF_MASK;
}
I hope this can help you!
Have a nice day!
Regards,
Isaac