spi transfer returned EINVAL

This forum is for topics specific to the Raspberry Pi and Arch Linux ARM

spi transfer returned EINVAL

Postby oklitz » Wed Jan 28, 2015 5:19 pm

Hello

I'm using arch linux: 3.18.3-3-ARCH #1 PREEMPT with newest wiringpi-git 69.0a9fdeb-1 packet from the AUR.
spi is enabled in config.txt
module spi_bcm2708 is loaded and devices are in /dev/spidev0.0 and /dev/spidev0.1

$this->bbcode_second_pass_code('', '
fd = wiringPiSPISetup (0, 500000);
if (fd == -1)
errExit("wiringPiSPISetup");
')
--function call returns without errors

$this->bbcode_second_pass_code('', '
uint8_t buff = 0b11110000;
ret = wiringPiSPIDataRW (0, &buff, 1);
if (ret == -1)
errExit("wiringPiSPIDataRW");
buff = 0b00001111;
ret = wiringPiSPIDataRW (0, &buff, 1);
if (ret == -1)
errExit("wiringPiSPIDataRW");

')
the second function call returns -1 with [EINVAL Invalid argument]
the first byte is shifted out correctly (i have a logic analyser on the spi bus)


echo 123 > /dev/spidev0.0 works fine

This code worked with older kernels, but after the jump to 3.18 it doesn't.
But i can't say it exactly because i have used the libwiringPi the last time in last year.

Do i make a mistake ? Does something changed in the kernel ?
Is somebody able to reproduce the error ?

regards Marco Oklitz
oklitz
 
Posts: 10
Joined: Sun Jul 07, 2013 10:48 am

Re: spi transfer returned EINVAL

Postby oklitz » Thu Jan 29, 2015 12:11 am

Heres some code to reproduce:

Is there an error in my code ?

$this->bbcode_second_pass_code('', '
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>

int main () {
int fd,ret;
struct spi_ioc_transfer spi;
uint8_t spiMode = 0 ;
uint8_t spiBPW = 8 ;
uint16_t spiDelay = 0 ;
uint32_t spiSpeed = 500000;
uint8_t buffer = 0b11110000;

spi.tx_buf = (unsigned long)&buffer;
spi.rx_buf = (unsigned long)&buffer;
spi.len = 1;
spi.speed_hz = spiSpeed;;
spi.delay_usecs = spiDelay;
spi.bits_per_word = spiBPW;
spi.cs_change = 0;

fd = open("/dev/spidev0.0", O_RDWR);
if (fd < 0) printf("error open: %s\n",strerror(errno));

if (ioctl(fd, SPI_IOC_WR_MODE, &spiMode) < 0)
printf("SPI Mode Change failure: %s\n", strerror(errno));
if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
printf("SPI BPW Change failure: %s\n", strerror(errno));
if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &spiSpeed) < 0)
printf("SPI Speed Change failure: %s\n", strerror(errno));

ret = ioctl(fd, SPI_IOC_MESSAGE(1), &spi);
if (ret < 0) printf("ioctl error1: %s\n", strerror(errno));

buffer = 0b00110011;
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &spi);
if (ret < 0) printf("ioctl error2: %s\n", strerror(errno));

buffer = 0b11100111;
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &spi);
if (ret < 0) printf("ioctl error3: %s\n", strerror(errno));

close (fd);
return 0;
}
')

gcc -Wall main.c spitest
oklitz
 
Posts: 10
Joined: Sun Jul 07, 2013 10:48 am

Re: spi transfer returned EINVAL

Postby oklitz » Thu Jan 29, 2015 9:18 pm

oklitz
 
Posts: 10
Joined: Sun Jul 07, 2013 10:48 am


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 60 guests