linux_device_access icon indicating copy to clipboard operation
linux_device_access copied to clipboard

SPI Example

Open Fredovsky opened this issue 4 years ago • 1 comments

Hi,

Trying to make an SPI transfer on a Raspberry Pi Zero.

Using your code and library :

#include "spi.h"

/* Initialize SPI 8 bits, 1Mhz, Mode 0, no semaphore locks */
SPI_HANDLE spi = SpiOpenPort(0, 8, 1000000, SPI_MODE_0, false);

int  main(){
        if (spi)
        {
              uint8_t buf[3] = { 0x01, 0x02, 0xAA };  // Data to send
              SpiWriteAndRead(spi, &buf[0], &buf[0], 3, false);   // Transfer buffer data to SPI
              SpiClosePort(spi);
        }
return 0;
}

Then on the pi :

g++ spi-test.c -o spitest

Gives the following error :

/usr/bin/ld: /tmp/ccMiUj6A.o: in function `__static_initialization_and_destruction_0(int, int)':
spi-test.c:(.text+0x9c): undefined reference to `SpiOpenPort'
collect2: error: ld returned 1 exit status

Please let me know if you spot an error, for now I'm stuck. Probably something obvious as I'm not an expert.

Thanks

Fredovsky avatar Apr 10 '21 14:04 Fredovsky

The compile isn't including in spi.c

The compiler knows what the function looks like because of spi.h but the linker can't find the code body.

Did you use my makefile or do one yourself?

Hi,

Trying to make an SPI transfer on a Raspberry Pi Zero.

Using your code and library :

#include "spi.h"

/* Initialize SPI 8 bits, 1Mhz, Mode 0, no semaphore locks */
SPI_HANDLE spi = SpiOpenPort(0, 8, 1000000, SPI_MODE_0, false);

int  main(){
        if (spi)
        {
              uint8_t buf[3] = { 0x01, 0x02, 0xAA };  // Data to send
              SpiWriteAndRead(spi, &buf[0], &buf[0], 3, false);   //
Transfer buffer data to SPI
              SpiClosePort(spi);
        }
return 0;
}

Then on the pi :

g++ spi-test.c -o spitest

Gives the following error :

/usr/bin/ld: /tmp/ccMiUj6A.o: in function
`__static_initialization_and_destruction_0(int, int)':
spi-test.c:(.text+0x9c): undefined reference to `SpiOpenPort'
collect2: error: ld returned 1 exit status

Please let me know if you spot an error, for now I'm stuck. Probably something obvious as I'm not an expert.

Thanks

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/LdB-ECM/linux_device_access/issues/3

LdB-ECM avatar Apr 12 '21 06:04 LdB-ECM