Issue where cs does not work properly when using adc of spi interface

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.

Could you apply below patch to try.

1 Like

Hello, @ShaneCCC

Nothings changed after applying patch you said.

[16 byte write repeatition]

[16 byte write repeatition enclosed]

[8bit write repeatition]

[8bit write repeatition enclosed]

[mixed]

What am I supposed to do?

Thank you.

Hello, @ShaneCCC

Can you tell me how to resolve above issue?

Thank you.

Hello, @ShaneCCC

If necessary, the test program source code or test program can also be provided.

Thank you.

I am checking with designer. Will update to you once get any comment.

Thanks

1 Like

Hello, @ShaneCCC

Is there any progress?

I found the following article on the forum, maybe this will help you?

Thank you.

Have you tried with the patches shared in the above thread which you mentioned?

1 Like

Hello, @va11

no. Haven’t tried it yet.
Does the above patch solve the problem?

no. Haven’t tried it yet.
Does the above patch solve the problem?

If possible, can you explain a little more about how to apply the above patch?

Thank you.

@Hodu
Please download the patch file from the topic and modify the driver manually to apply it.

Thanks

1 Like

Hello,

By referring to the diff in the two attached patch files,

Can I build and apply dtb by removing the - part from the kernel source and including the + part?

Thank you.

Yes, that is how the patch file for.

1 Like

hello, @ShaneCCC

I’m using the 4.6.1 source
It seems that the contents of the patch mentioned above have already been applied to the spi-tegra114.c file.

I am attaching the file for cross check. Please confirm.

If the contents of the file are the same as you can see, the patch mentioned above has already been applied.

If so, how can we solve this problem?
spi-tegra114.c (59.2 KB)

file path :
/media/jetsonhostpc/841a9ca5-d24b-49de-8e73-d245a962e433/home/nanohostpc/nn_flashing/nn_kernel_jp461/Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/spi/spi-tegra114.c

Thank you.

Hello, @ShaneCCC

As mentioned above, the patch contents have already been applied.

Anything more to do?

Thank you.

Sorry to later reply.
I am checking with developer will update once get any comment.

Thanks

1 Like

Can you enable the debug log while running the test using the below commands
echo -n “file drivers/spi/spi-tegra114.c +p” > /sys/kernel/debug/dynamic_debug/control
echo 8 > /proc/sys/kernel/printk
Please share the results I will analyze the results and get back.

1 Like

Hello, @va11

like this?

I get permission denied.
It’s the same if I run it with sudo, is there another way?

Thank you.

Hello, @va11

The debug log obtained using the above command is attached here.
Please let me know if I made a mistake while getting the log.

printk (10 Bytes)
control (661.6 KB)

Thank you.

Hello, @va11

How is the progress?
Need more information?

Thank you.

Run the “sudo su” command then enter below command. After that collect the kernel message after doing SPI transfer.

echo -n “file drivers/spi/spi-tegra114.c +p” > /sys/kernel/debug/dynamic_debug/control
echo 8 > /proc/sys/kernel/printk
1 Like