Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
orange pi / arm board and linking libraries for SPI and other devices
#1
Greetings, 

I hate asking, but I burned up a wild amount of time already so hoping for some direction. 
I have QB64PE running on orange pi zero 3 with ubuntu desktop orange pi release. 

I'm trying to communicate over SPI using qb64 (and other connections eventually) 
I spent a ton of time looking online but theres always a ddead end it seems. 
A friend suggested AI, so here's an SPI program AI designed :

Code: (Select All)
DECLARE DYNAMIC LIBRARY "C"
    FUNCTION open (path AS STRING, flags AS LONG) AS LONG
    FUNCTION ioctl (fd AS LONG, request AS LONG, argp AS _OFFSET) AS LONG
    FUNCTION write (fd AS LONG, buffer AS _OFFSET, count AS LONG) AS LONG
    FUNCTION read (fd AS LONG, buffer AS _OFFSET, count AS LONG) AS LONG
    FUNCTION close (fd AS LONG) AS LONG
END DECLARE

CONST O_RDWR = &H2
CONST SPI_IOC_MAGIC = &H6B
CONST SPI_IOC_RD_MODE = (SPI_IOC_MAGIC << 8) + 1
CONST SPI_IOC_WR_MODE = (SPI_IOC_MAGIC << 8) + 1

DIM fd AS LONG
DIM spi_mode AS _BYTE
DIM tx_buffer(0 TO 2) AS _BYTE
DIM rx_buffer(0 TO 2) AS _BYTE

' Open the SPI device
fd = open("/dev/spidev1.0", O_RDWR)
IF fd < 0 THEN
    PRINT "Failed to open SPI device."
    END
ELSE
    PRINT "SPI device opened successfully."
END IF

' Set SPI mode (0, 1, 2, or 3)
spi_mode = 0
IF ioctl(fd, SPI_IOC_WR_MODE, _OFFSET(spi_mode)) < 0 THEN
    PRINT "Failed to set SPI mode."
    CALL close(fd)
    END
ELSE
    PRINT "SPI mode set successfully."
END IF

' Prepare data to send
tx_buffer(0) = &H9F  ' Example command

' Send and receive data
IF write(fd, _OFFSET(tx_buffer(0)), 1) <> 1 THEN
    PRINT "Failed to write to SPI device."
    CALL close(fd)
    END
ELSE
    PRINT "Data written to SPI device."
END IF

IF read(fd, _OFFSET(rx_buffer(0)), 3) <> 3 THEN
    PRINT "Failed to read from SPI device."
    CALL close(fd)
    END
ELSE
    PRINT "Data read from SPI device: ";
    FOR i = 0 TO 2
        PRINT HEX$(rx_buffer(i)); " ";
    NEXT
    PRINT
END IF

' Close the SPI device
CALL close(fd)
PRINT "SPI device closed."

END
So far there are a few errors, including DYNAMIC LIBRARY NOT FOUND. 

I've honestly never linked a file or anything else to any QB before. 

Does the program look plausible though? 

I really need to make this work somehow, I love QB64 and too old to learn anything else lol. 
And I really need to make this project work...
Reply


Messages In This Thread
orange pi / arm board and linking libraries for SPI and other devices - by Parkland - 08-08-2024, 05:21 AM



Users browsing this thread: 2 Guest(s)