Comments (7)
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...
from wiringop-zero.
@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)) ;
from wiringop-zero.
[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
from wiringop-zero.
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)) ;
from wiringop-zero.
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;
}
`
from wiringop-zero.
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...
from wiringop-zero.
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
from wiringop-zero.
Related Issues (17)
- Spi not working! HOT 6
- OPI zero 2 plus
- not 100% compatible with wirining PI
- Make Failed... HOT 3
- opi zero 2 plus H5 HOT 6
- error in build gpio.o: error adding symbols: Bad value (R_ARM_THM_MOVW_ABS_NC) HOT 4
- pinModeAlt not working (fixed) HOT 1
- Reading wrong value from ADC (wrong byte)
- Problem in interrupt function - wiringPiISR HOT 7
- Make Failed - ‘for’ loop initial declarations are only allowed in C99 or C11 mode HOT 3
- Requirements for Armbian Bionic Minimal
- build script: wrong shell interpreter
- Can I use it with C++?
- Build Fails HOT 1
- Incompatible pin mapping
- Failed to Create Static Library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wiringop-zero.