Hello,
The following is a picture of the waveform of the spi signal checked with an oscilloscope.
The left side is when only 1 byte is written during adc conversion.
The picture on the right shows the css when repeating 1-byte write and 16-byte data transfer.
When performing 1-byte write (conversion) and 16-byte data transfer, you can see that cs continues to be low before and after data transfer as shown in the picture on the right.
Can you tell me why this is?
Is it possible to make cs fall low only when transferring data normally?
The source code is attached.
spi_access.c (2.7 KB)
spi_adc.c (13.7 KB)
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;
}
//0xB8================================================================================
tx_buf[0] = 0xB8; //Conversoin for 8 Channel ADC
txrx_size = 1;
SpiAccTransferDev( pSpiCtrl, txrx_size, tx_buf, rx_buf);
// fprintf(stderr, "SPI Access tx_buf[0]=0x%02x, \n", tx_buf[0]);
// //Wait================================================================================
usleep(0);
//Read================================================================================
tx_buf[0] = 0x00; // Read FIFO 8 Channel
txrx_size = MAX11636_BUFF_MAX;
SpiAccTransferDev( pSpiCtrl, txrx_size, tx_buf, rx_buf);
// fprintf(stderr, "SPI Access rx_buf[0]=0x%02x, rx_buf[1]=0x%02x\n", rx_buf[0], rx_buf[1]);
Thank you.