HI,
我使用的simpelink 4.20.1.3 sdk, spislave的例程,程序如图, master每秒发送3个字节的数据,如图:,发现slave(CC1310)每次SPI_transfer只能接收到第一个字节的数据,后两个字节丢失了,这是为什么?
谢谢!
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
HI,
我使用的simpelink 4.20.1.3 sdk, spislave的例程,程序如图, master每秒发送3个字节的数据,如图:,发现slave(CC1310)每次SPI_transfer只能接收到第一个字节的数据,后两个字节丢失了,这是为什么?
谢谢!
您好,
我们也不清楚发生了什么当未看到任何关于主代码或从代码其余部分的内容时。
但是,我们已经修改了 SDK 中的主和从 spi 示例,以使用阻塞模式每 2 秒传输一次 3 字节长的数据包。未使用握手。
代码按预期工作,每次迭代时,从机都会收到所有 3 个字节。
代码如下:
Master:
#define SPI_MSG_LENGTH (3)
#define MASTER_MSG ("ABC")
unsigned char masterRxBuffer[SPI_MSG_LENGTH];
unsigned char masterTxBuffer[SPI_MSG_LENGTH];
void *masterThread(void *arg0)
{
SPI_Handle masterSpi;
SPI_Params spiParams;
SPI_Transaction transaction;
// Open SPI as master (default)
SPI_Params_init(&spiParams);
spiParams.frameFormat = SPI_POL0_PHA0;
spiParams.bitRate = 1000000;
spiParams.transferMode = SPI_MODE_BLOCKING;
masterSpi = SPI_open(Board_SPI_MASTER, &spiParams);
if (masterSpi == NULL)
{
while (1);
}
// Copy message to transmit buffer
strncpy((char *) masterTxBuffer, MASTER_MSG, SPI_MSG_LENGTH);
transaction.count = SPI_MSG_LENGTH;
transaction.txBuf = (void *) masterTxBuffer;
transaction.rxBuf = (void *) masterRxBuffer;
while (1)
{
SPI_transfer(masterSpi, &transaction);
sleep(2);
}
}
Slave:
#define SPI_MSG_LENGTH (3)
#define SLAVE_MSG ("DEF")
unsigned char slaveRxBuffer[SPI_MSG_LENGTH];
unsigned char slaveTxBuffer[SPI_MSG_LENGTH];
void *slaveThread(void *arg0)
{
SPI_Handle slaveSpi;
SPI_Params spiParams;
SPI_Transaction transaction;
SPI_Params_init(&spiParams);
spiParams.frameFormat = SPI_POL0_PHA0;
spiParams.mode = SPI_SLAVE;
spiParams.bitRate = 1000000;
spiParams.transferMode = SPI_MODE_BLOCKING;
slaveSpi = SPI_open(Board_SPI_SLAVE, &spiParams);
if (slaveSpi == NULL)
{
while (1);
}
// Copy message to transmit buffer
strncpy((char *) slaveTxBuffer, SLAVE_MSG, SPI_MSG_LENGTH);
transaction.count = SPI_MSG_LENGTH;
transaction.txBuf = (void *) slaveTxBuffer;
transaction.rxBuf = (void *) slaveRxBuffer;
while(1)
{
SPI_transfer(slaveSpi, &transaction);
}
}