Hello,
The spi access delay is jagged, and sometimes it is measured as 50us or more, 70us or more or more as follows.
The target time is less than 35us.
To satisfy 16-byte spi access more than 20,000 times per second, delay must be stably less than 35us.
The spi transfer function and how to use it are as follows.
int SpiAccTransferDev(pJETSON_SPI_CTRL pSpiCtrl, int size, unsigned char* tx_buf, unsigned char* rx_buf)
{
int ret;
struct spi_ioc_transfer tr;
int ntransfers = 1;
// fprintf(stderr,"vvvv%s(%d)[0x%02x,%d]\n", __FUNCTION__, __LINE__, *tx_buf, size);
memset(&tr, 0, sizeof(struct spi_ioc_transfer));
tr.tx_buf = (unsigned long)tx_buf;
tr.rx_buf = (unsigned long)rx_buf;
tr.len = size; // The size mean byte count for tx_buf and rx_buf
tr.delay_usecs = pSpiCtrl->spi_delay;
tr.speed_hz = pSpiCtrl->spi_speed;
tr.bits_per_word = pSpiCtrl->spi_bits;
tr.cs_change = 1;
tr.pad = 0;
ret = ioctl(pSpiCtrl->spi_device, SPI_IOC_MESSAGE(1), &tr);
if (ret < 0){
fprintf(stderr, "Error : It can't send spi message with (%s)\n", JETSON_SPI_DEVICE_PATH);
return -1;
}
return ret;
}
gSpiLoopRun = 1;
while(gSpiLoopRun)
{
//Read================================================================================
tx_buf[0] = 0x00; // Read FIFO 8 Channel
txrx_size = MAX11636_BUFF_MAX;
SpiAccTransferDev( pSpiCtrl, txrx_size, tx_buf, rx_buf);
}
Thank you.