关于不清接收标志的情况下的SPI的发送

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

关于不清接收标志的情况下的SPI的发送

Jump to solution
755 Views
wxx
Contributor I

关于SPI发送数据

芯片: MC9S12XE-Family

连续发送字节的情况下, 若我在确认到SPTEF=1后就立即向SPIDR写下一个发送字节, 并且不处理SPIF(也就是不读SPIDR, 使SPIF保持为1), 

那么, 第二个发送字节会不会被第一个接收字节给覆盖掉呢? 

也就是说, 我向SPIDR写入的发送字节, 和移位寄存器中的接收字节, 二者之间是如何交换的呢? 

单字节写入函数: 

static uchar SPI2_PushTxData (uint *wp_data)
{
uint TimeNum = 0u;

/* 等待发送空闲, 超时则放弃本次发送 */
while(SPI2SR_SPTEF == 0u)
{
TimeNum++;
if(TimeNum >= SPI2_TIMEOUT_CNT)
{
return SPI_FAIL; /* 超时, 退出本次数据发送,发送失败 */
}
}

/* 发送空闲: 可以把数据写入SPI0DRL, 该数据会在当前发送任务结束后立即被发送 */
SPI2DR = *wp_data;

return SPI_SUCCESS;
}

Labels (1)
0 Kudos
1 Solution
575 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,
The SPIDR data register consists of two registers, one for the transmitter and one for the receiver.
So, the data you receive cannot rewrite the data you transmit, you only need to read the SPTEF flag before writing to SPIDR.
Also, the received data in SPIDR cannot be rewritten by subsequent data received in the receive shift register, because the data are moved from the shift register to SPIDR upon clearing of the SPIF flag, however, the data in the shift register will be rewritten by subsequent data if not moved to SPIDR, as it is described in Figure 21-9,10 in the S12XE RM.

Regards,
Daniel

View solution in original post

2 Replies
576 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,
The SPIDR data register consists of two registers, one for the transmitter and one for the receiver.
So, the data you receive cannot rewrite the data you transmit, you only need to read the SPTEF flag before writing to SPIDR.
Also, the received data in SPIDR cannot be rewritten by subsequent data received in the receive shift register, because the data are moved from the shift register to SPIDR upon clearing of the SPIF flag, however, the data in the shift register will be rewritten by subsequent data if not moved to SPIDR, as it is described in Figure 21-9,10 in the S12XE RM.

Regards,
Daniel

574 Views
wxx
Contributor I

Translate:

SPI of MC9S12XE-Family. 

When send many bytes, what happened if I ignore the receive flag SPIF? 

Will the 2nd send byte be coverd by 1st received byte?

byte send function: 

static uchar SPI2_PushTxData (uint *wp_data)
{
uint TimeNum = 0u;

/* 等待发送空闲, 超时则放弃本次发送 */
while(SPI2SR_SPTEF == 0u)
{ 
TimeNum++;
if(TimeNum >= SPI2_TIMEOUT_CNT)
{
return SPI_FAIL; /* 超时, 退出本次数据发送,发送失败 */
} 
}

/* 发送空闲: 可以把数据写入SPI0DRL, 该数据会在当前发送任务结束后立即被发送 */
SPI2DR = *wp_data;

return SPI_SUCCESS;
}

0 Kudos