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

Armbian & Khadas are rewarding contributors

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines