SPI - Transmission complete flag?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SPI - Transmission complete flag?

1,559件の閲覧回数
mwp_nxp
Contributor III

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,442件の閲覧回数
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,432件の閲覧回数
bhenning
Contributor III

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

0 件の賞賛
返信