Jump to content

[SPI] Using Multiple Slaves


newbie

Recommended Posts

I can run spi with the code below. But I have to communicate with too many slaves on the same line. I will connect all the devices with the same MISO - MOSI - SCLK line.

 

static void transfer(int fd)
{

	//n.SLAVE CS LOW
	
	int ret;
	uint8_t tx[] = {
		0xAD, 0x03
	};
	uint8_t rx[2] = {0, };
	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = 2,
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");

	//n.SLAVE CS HIGH

	puts("");
}

 

Can I do like above?  So I will use software CS, not (Hardware )CS on the board.  The slave's CS line will be written in the comments lines.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines