SPI - Transmission complete flag?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SPI - Transmission complete flag?

1,294 次查看
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.

标签 (1)
标记 (3)
2 回复数

1,177 次查看
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 项奖励

1,167 次查看
bhenning
Contributor III

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

0 项奖励