Am Sonntag, 5. Juni 2016 13:45:59 UTC+2 schrieb Michal Suchanek:

> There is a comment in the SPI driver regarding CS polarity which boils 
> down to 'changing CS polarity affects all CS lines'.
>

This may be the reason that I could see activities on both CS lines.
 

> done with an IOCTL. Even if you send a few bytes it might be 
> challenging to measure the level change unless you are using an 
> oscilloscope. 
>
 
I have checked this with an oscilloscope (a cheap logic analyser is ordered 
so that I could attach a better picture of the output of all pins hopefully 
next week). I have written a small test program (attached to this message) 
which sends repeatedly 4 bytes over the SPI bus using the ioctl.  But on my 
oscilloscope I could see only activities on the CS lines, but no change of 
the CLK and MOSI outputs.


-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>

int main(int argc, char *argv[]) {
	struct spi_ioc_transfer xfer[2];
	char buf[] = {0x11, 0x22, 0x44, 0x88};
	char rx_buf[32];
	int i;
	int mode = 0;
	__u32 speed=500;

	int file = open("/dev/spidev0.0", O_RDWR);
	if (file < 0)
	{
		perror("Failed to open the bus.");
		exit(1);
	}

	if (ioctl(file, SPI_IOC_WR_MODE, &mode)<0)	{
		perror("can't set spi mode");
		exit(1);
	}
	if (ioctl(file, SPI_IOC_RD_MODE, &mode) < 0)
	{
		perror("SPI rd_mode");
		exit(1);
	}

	if (ioctl(file, SPI_IOC_RD_MAX_SPEED_HZ, &speed) < 0) {
		perror("SPI max_speed_hz");
		exit(1);
	}

	for (i = 0; i < 500000; i++) {
		xfer[0].tx_buf = (unsigned long) buf;
		xfer[0].len = 4; /* Length of  command to write*/
		xfer[0].cs_change = 0; /* Keep CS activated */
		xfer[0].delay_usecs = 0, //delay in us
		xfer[0].speed_hz = speed, //speed
		xfer[0].bits_per_word = 8, // bites per word 8

		xfer[1].rx_buf = (unsigned long) rx_buf;
		xfer[1].len = 4; /* Length of Data to read */
		xfer[1].cs_change = 0; /* Keep CS activated */
		xfer[0].delay_usecs = 0;
		xfer[0].speed_hz = speed;
		xfer[0].bits_per_word = 8;

		if (ioctl(file, SPI_IOC_MESSAGE(1), xfer) < 0) {
			perror("SPI_IOC_MESSAGE");
			exit(1);
		}
		usleep(1);
	}
}

Reply via email to