使用 RT1176 进行 SPI
通信,我们确实看到了奇怪的时钟行为:每 8 个时钟信号都非常短。我在下面附上了两张图片,显示每个时钟都会发生这种情况,放大版本显示时钟信号有多短。值得注意的是,数据正确地跟随时钟,所以第 8 位的信号也被缩短了. 在测量中,时钟显示为黄色,SDO 显示为蓝色。
请注意,该线路上的噪声与我们进行测量的位置有关。与 RT1176 的 SPI 通信的其他实例显示相同的行为,即使信号噪声较小。
三字节 SPI 传输。时钟:黄色,SDO:蓝色。用红色箭头标记的缩短信号
放大一个字节传输。第 8 个缩短的时钟标有红色箭头。时钟:黄色。SDO:蓝色
RT1176 SPI 接口设置为主机,参数如下:
{
uint32_t clock_freq;
lpspi_master_config_t sdk_spi_config;
edma_config_t sdk_dma_config;
uint8_t dma_mux_channel_rx, dma_mux_channel_tx;
LPSPI_Type* instance;
//Init SPI
LPSPI_MasterGetDefaultConfig(&sdk_spi_config);
instance = LPSPI5;
clock_freq = CLOCK_GetRootClockFreq(kCLOCK_Root_Lpspi5);
sdk_spi_config.baudRate = 1000000/2;
sdk_spi_config.bitsPerFrame = 8;
sdk_spi_config.cpha = kLPSPI_ClockPhaseFirstEdge;
sdk_spi_config.cpol = kLPSPI_ClockPolarityAc
tiveLow;
sdk_spi_config.direction = kLPSPI_MsbFirst;
sdk_spi_config.pcsToSckDelayInNanoSec = 100;
sdk_spi_config.lastSckToPcsDelayInNanoSec = 100;
sdk_spi_config.betweenTransferDelayInNanoSec = 10;
sdk_spi_config.whichPcs = kLPSPI_Pcs0;
sdk_spi_config.pcsActiveHighOrLow = kLPSPI_PcsActiveLow;
sdk_spi_config.pinCfg = kLPSPI_SdiInSdoOut;
sdk_spi_config.dataOutConfig = kLpspiDataOutTristate;
instance->CR |= LPSPI_CR_DBGEN_MASK; //enable LPSPI in debug mode
LPSPI_MasterInit(instance, &sdk_spi_config, clock_freq);
//Data transfer
uint8_t buf_tx[9] = {0};
uint8_t buf_rx[9] = {0};
lpspi_transfer_t transfer;
txBuffer[0] = 0x24 | (1 << 7);
transfer.txData = buf_tx;
transfer.rxData = buf_rx;
transfer.dataSize = 9;
transfer.configFlags = kLPSPI_MasterPcs0 | kLPSPI_MasterPcsContinuous;
if((retval = LPSPI_MasterTransferBlocking(instance, &transfer)) != kStatus_Success)
{
printf("Transfer failed!
");
if(retval == kStatus_LPSPI_Busy) printf("kStatus_LPSPI_Busy
");
if(retval == kStatus_InvalidArgument) printf("kStatus_InvalidArgument
");
if(retval == kStatus_LPSPI_Timeout) printf("kStatus_LPSPI_Timeout
");
return false;
}
return true;
}
传输成功,
kStatusSuccess由
LPSPI_MasterTransferBlocking()返回。我们正在使用最新的 SDK。
0