Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spidev1.0 not working #8

Open
batmaca opened this issue Sep 7, 2017 · 7 comments
Open

spidev1.0 not working #8

batmaca opened this issue Sep 7, 2017 · 7 comments

Comments

@batmaca
Copy link

batmaca commented Sep 7, 2017

Hi,

I've been trying on a project. To do so, I needed this library and my orange pi zero's SPI1 pins. Unfortunately I haven't been succeeded. I thought that something was wrong about opi but afterwards I wired my SCLK pin to oscilloscope and watch the signals.

The problem is not about OPi zero, must be about this library. Dont know what yet, but hope gonna find out. Anyone can help me or got any idea how to fix this?

@ghost
Copy link

ghost commented Sep 22, 2017

I have the same problem... I solve it temporary by this way:
in wiringPiSPISetup function i changed string:

 if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0)
   return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;

for this:

if (channel == 0) {
   if ((fd = open (spiDev0, O_RDWR)) < 0)
     return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
 };

 if (channel == 1) {
   if ((fd = open (spiDev1, O_RDWR)) < 0)
     return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
 };

So /dev/spi1.0 is opened now. Looks like some problems with ?...:... consturction here...
Of course you need to rebuild library...

@jackkum
Copy link

jackkum commented Sep 22, 2017

@vr-mth Could you try like this:

 char *spiDev = (channel == 0 ? spiDev0 : spiDev1);
 if ((fd = open (spiDev, O_RDWR)) < 0)
   return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;

@ghost
Copy link

ghost commented Sep 22, 2017

[Compile] wiringPiSPI.c
wiringPiSPI.c: In function ‘wiringPiSPISetup’:
wiringPiSPI.c:101:17: warning: initialization discards ‘const’ qualifier from pointer target type
  char *spiDev = (channel == 0 ? spiDev0 : spiDev1);

But its compiled and working

@ghost
Copy link

ghost commented Sep 22, 2017

2jackkum - thanks for pretty solution. Helped this one:

  const char *spiDev = (channel == 0 ? spiDev0 : spiDev1);
  if ((fd = open (spiDev, O_RDWR)) < 0)
    return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;

@batmaca
Copy link
Author

batmaca commented Sep 22, 2017

I tried your solutions but, still got the same problem.

kanalka@orangepizero:~$ sudo gcc -o test test.c -lwiringPi -pthread kanalka@orangepizero:~$ sudo ./test Unable to open SPI device: No such file or directory

And here is the my test code. Where am i doing wrong?

`
#include <stdio.h>
#include <string.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>

#define LED_PIN 7
#define BERKE_SPI_PORT_INDEX 1
#define BERKE_BUF_LEN 50

extern char *spiDev1;
unsigned char bufferBerke[BERKE_BUF_LEN];

int main(void){

unsigned char iMain;
unsigned char pinValue = LOW;
wiringPiSetup();
wiringPiSPIGetFd(BERKE_SPI_PORT_INDEX);
wiringPiSPISetup(BERKE_SPI_PORT_INDEX,1000000);
pinMode(LED_PIN,OUTPUT);
for(iMain = 0; iMain < BERKE_BUF_LEN; iMain++){
	if(iMain%2)
		bufferBerke[iMain] = 0xFF;
	else
		bufferBerke[iMain] = 0x00;
}
for(;;){
	wiringPiSPIDataRW(BERKE_SPI_PORT_INDEX, bufferBerke, BERKE_BUF_LEN);
	if(pinValue == LOW){
		digitalWrite(LED_PIN, HIGH);
		pinValue = HIGH;
	}else {
		digitalWrite(LED_PIN, LOW);
		pinValue = LOW;
	}
	delay(500);
}
return 0;

}
`

@ghost
Copy link

ghost commented Sep 22, 2017

Wow... you have to recompile library. Also you should to check script.bin file in /boot for spi1 is enabled.

Also, in program you need only 2 functions to use:

  1. wiringPiSPISetup
  2. wiringPiSPIDataRW

All another (extern char *spiDev1;, getFd ena etc) - is not needed...

@rocksyne
Copy link

rocksyne commented Dec 9, 2017

To enable the auxiliary SPI device (three slave selects) add the line dtoverlay=spi1-3cs to /boot/config.txt. You will need to reboot to get everything working well.

To view the list do
ls /dev/spidev*

and you are bound to see something like this
/dev/spidev0.0 /dev/spidev0.1 /dev/spidev1.0 /dev/spidev1.1 /dev/spidev1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants