LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 08-09-2019, 12:36 PM   #1
MALDATA
Member
 
Registered: Mar 2005
Posts: 157

Rep: Reputation: 19
SPI device doesn't open in one app but does in another


I'm trying to use a library that communicates with a SPI device. The system seems to be correctly configured for SPI, and uses the spidev kernel module. This seems to work fine, for example:

Code:
# spi-config -d /dev/spidev32766.1 -q
/dev/spidev32766.1: mode=0, lsb=0, bits=8, speed=40000000
I can also write a super-simple C program that checks if the SPI device can be opened:

Code:
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>

int main(int argc, char* argv[])
{
    int fd;
    fd = open("/dev/spidev32766.1", O_RDWR);

    if (fd < 0)
    {
        int error_value = errno;
        printf("Failed to open. Returned fd = %d and errno = %d\n", fd, error_value);
    }
    else
    {
        printf("Opened OK!\n");
        close(fd);
    }

    return 0;
}
This works perfectly fine. The device opens and closes without error.

Now, look at the code here, you will see that the code in this library does exactly that. All I did was change the SPI_DEV_PATH macro to "/dev/spidev32766.1" and compile it. I could then run the test program that came with the library, and that seemed to run fine also.

However, my actual application links to the lgw_spi_open() function, and while debugging, I'm finding that the open() returns a -1 (errno is 2). I don't understand how that could be the case. I know the device node exists, I know I can open and close it normally, I know the function gets called correctly from the test program, and yet in the "real" application, open() fails.

Can anyone help me figure out why that might be?
Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Need help with Device Tree for SPI Device T_Versicolor Linux - Embedded & Single-board computer 21 06-26-2019 02:13 AM
[SOLVED] CH341 (USB to SPI) adaptor driver doesn't work kaza Linux - Hardware 12 02-28-2018 03:23 PM
can't open a spi device in /dev georgewhr Linux - Software 0 11-28-2013 09:44 AM
How do I access SPI Drivers from a User Space App? Aglets Programming 0 09-29-2010 01:31 PM
sound from one app prevents sound from another app alex.flint Linux - Software 1 06-21-2007 09:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 01:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration