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.

TMS320C6678: 使用C6678的SPI读取ADIS16505 MEMS IMU数据

Part Number: TMS320C6678

我使用创龙例程中spi.cc66x_spi_xfer函数测试cs1能够实现自闭环收发,但读取IMU数据却老是读不出来。SPI时钟为1MHz,时钟极性和相位都按IMU手册设置了。我考虑到这个函数是连续读写的,而IMU数据burst模式下写0x6800指令到读出数据可能需要一个延迟,我想或许要分离这里的spi写函数和读函数,试了直接把函数读写部分分开,但执行到读函数时会卡在while判定Rx非空这一步上,对SPI底层逻辑不是很了解,不知道如何修改为好,还请各位指教!感谢!

uint32_t c66x_spi_xfer(uint32_t nbytes, uint8_t *data_out, \
uint8_t *data_in, Bool terminate)
{
uint32_t i, buf_reg;
uint8_t *tx_ptr;
uint8_t *rx_ptr;

tx_ptr = (uint8_t *)data_out;
rx_ptr = (uint8_t *)data_in;

/* Clear out any pending read data */
spiRegs->SPIBUF;

for(i = 0; i < nbytes; i++) {
/* Wait untill TX buffer is not full */
while(spiRegs->SPIBUF & CSL_SPI_SPIBUF_TXFULL_MASK);

/* Set the TX data to SPIDAT1 */
data1_reg_val &= ~0xFFFF;
if(tx_ptr) {
data1_reg_val |= *tx_ptr & 0xFF;
tx_ptr++;
}

/* Write to SPIDAT1 */
if((i == (nbytes -1)) && (terminate)) {
/* Release the CS at the end of the transfer when terminate flag is TRUE */
spiRegs->SPIDAT1 = data1_reg_val & ~(CSL_SPI_SPIDAT1_CSHOLD_ENABLE << \
CSL_SPI_SPIDAT1_CSHOLD_SHIFT);
} else {
spiRegs->SPIDAT1 = data1_reg_val;
}

/* Read SPIBUF, wait untill the RX buffer is not empty */
while(spiRegs->SPIBUF & (CSL_SPI_SPIBUF_RXEMPTY_MASK));

/* Read one byte data */
buf_reg = spiRegs->SPIBUF;
if(rx_ptr) {
*rx_ptr = buf_reg & 0xFF;
rx_ptr++;
}
}

return 0;
}

x 出现错误。请重试或与管理员联系。