SPI - Transmission complete flag?

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

SPI - Transmission complete flag?

1,282 Views
mwp_nxp
Contributor II

Hi all,

I need to manually set a pin low before a SPI master transmit begins, and the set it back high afterwards.

The micro is a KL03.

At the moment, im doing the following...

GPIO_PortClear(GPIOA, 1<<(PIN2));

SPI0->D = data & 0xFFU;
while ((SPI0->S & SPI_S_SPTEF_MASK) == 0) {}
GPIO_PortSet(GPIOA, 1<<(PIN2));

... but im finding the SPTEF is being set high before the transmission has actually been completed.

How can I reliably wait for the last bit to be sent, before setting that PA2 pin back to high?

Thanks in advance.

Labels (1)
Tags (3)
2 Replies

1,165 Views
mjbcswitzerland
Specialist V

Hi

For manual CS line control you need to use the Rx flag and not the Tx flag. Since the output is buffered the Tx flag shows when there is room for the next tx data byte to be written, which is before the byte in the output shift register has been completely shifted out. The Rx flag indicates when a complete data byte is available which is after all bits have been clocked in.
The rx flag must be cleared (by reading the data register) before the transmission starts for this to work.

After you have configured the SPI interface do the following:
(void)SPI0_S;
(void)SPI0_D;

once to ensure that the status is correct for the start of the operation.

Regards

Mark

(uTasker project developer for Kinetis and i.MX RT)

See the open source version on GITHUB for SPI Flash and SD card operation on KL03 SPI with manual control as reference.

0 Kudos

1,155 Views
bhenning
Contributor III

Please excuse the bump, but how about providing a link to that GITHUB example?  Thanks!

0 Kudos