Giter Club home page Giter Club logo

Comments (7)

 avatar commented on July 29, 2024 1

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.

jackkum avatar jackkum commented on July 29, 2024

@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.

 avatar commented on July 29, 2024
[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.

 avatar commented on July 29, 2024

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.

batmaca avatar batmaca commented on July 29, 2024

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.

 avatar commented on July 29, 2024

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...

from wiringop-zero.

rocksyne avatar rocksyne commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.