WiringOP-Zero
WiringOP-Zero copied to clipboard
spidev1.0 not working
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?
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...
@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)) ;
[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
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)) ;
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;
} `
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:
- wiringPiSPISetup
- wiringPiSPIDataRW
All another (extern char *spiDev1;, getFd ena etc) - is not needed...
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