920 views|4 replies

410

Posts

3

Resources
The OP
 

【BIGTREETECH PI development board】 SPI interface test [Copy link]

 

This article tests the data transmission and reception of the SPI interface.

1. The definition of the SPI interface on the development board uses ports PH6, PH7 and PH8.

2. View the SPI device node under the Linux system

3. Test equipment

3.1、Test some codes

int main(int argc, char *argv[])
{
	int ret = 0;
	int fd;

	parse_opts(argc, argv);

	fd = open(device, O_RDWR);
	if (fd < 0)
		pabort("can't open device");

	/*
	 * spi mode
	 */
	ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode);
	if (ret == -1)
		pabort("can't set spi mode");

	ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode);
	if (ret == -1)
		pabort("can't get spi mode");

	/*
	 * bits per word
	 */
	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't set bits per word");

	ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't get bits per word");

	/*
	 * max speed hz
	 */
	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't set max speed hz");

	ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't get max speed hz");

	printf("spi mode: 0x%x\n", mode);
	printf("bits per word: %d\n", bits);
	printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);

	if (input_tx && input_file)
		pabort("only one of -p and --input may be selected");

	if (input_tx)
		transfer_escaped_string(fd, input_tx);
	else if (input_file)
		transfer_file(fd, input_file);
	else if (transfer_size) {
		struct timespec last_stat;

		clock_gettime(CLOCK_MONOTONIC, &last_stat);

		while (iterations-- > 0) {
			struct timespec current;

			transfer_buf(fd, transfer_size);

			clock_gettime(CLOCK_MONOTONIC, ¤t);
			if (current.tv_sec - last_stat.tv_sec > interval) {
				show_transfer_rate();
				last_stat = current;
			}
		}
		printf("total: tx %.1fKB, rx %.1fKB\n",
		       _write_count/1024.0, _read_count/1024.0);
	} else
		transfer(fd, default_tx, default_rx, sizeof(default_tx));

	close(fd);

	return ret;
}

3.2、SPI transceiver test

Execute command: $ sudo ./spidev_test -v -D /dev/spidev1.1

If PH7 and PH8 on the board are not short-circuited, the spontaneous data cannot be received. After short-circuiting, the spontaneously transmitted and received data are consistent and the SPI communication is normal.

This post is from Domestic Chip Exchange

Latest reply

Is it possible to test it this way? This is the first time I heard of shorting the SPI transceiver. Does that mean I have to use the full-duplex function to self-test the transceiver?   Details Published on 2023-7-31 15:32
 
 

4764

Posts

12

Resources
2
 
Short circuit is enable
This post is from Domestic Chip Exchange

Comments

Short MOSI and MISO to test self-transmission and self-reception  Details Published on 2023-7-31 10:12
 
 
 

410

Posts

3

Resources
3
 
Azuma Simeng posted on 2023-7-31 06:57 Short circuit is enable, right?

Short MOSI and MISO to test self-transmission and self-reception

This post is from Domestic Chip Exchange
 
 
 

6748

Posts

2

Resources
4
 

Is it possible to test it this way? This is the first time I heard of shorting the SPI transceiver. Does that mean I have to use the full-duplex function to self-test the transceiver?

This post is from Domestic Chip Exchange

Comments

I had never tested this before, but when I saw the test routine, I gave it a try.  Details Published on 2023-7-31 17:05
 
 
 

410

Posts

3

Resources
5
 
wangerxian posted on 2023-7-31 15:32 Can it be tested this way? This is the first time I heard of short-circuiting the SPI transceiver. Does that mean that the full-duplex function must be used to self-test the transceiver?

I had never tested this way before, but when I saw the test routine, I gave it a try.

This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list