#include #include #include #include #include #include #include #define SPI_DEVICE "/dev/spidev1.0" int main() { int spi_fd; uint8_t buffer[1] = {0x10}; // Open SPI device spi_fd = open(SPI_DEVICE, O_RDWR); if (spi_fd < 0) { perror("Error opening SPI device"); return EXIT_FAILURE; } uint8_t mode = SPI_MODE_0; uint8_t bits_per_word = 8; uint32_t speed_hz = 1000000; // Configure SPI parameters if (ioctl(spi_fd, SPI_IOC_WR_MODE, &mode) < 0 || ioctl(spi_fd, SPI_IOC_WR_BITS_PER_WORD, &bits_per_word) < 0 || ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz) < 0) { perror("Error configuring SPI"); close(spi_fd); return EXIT_FAILURE; } while (1) { // Write data to SPI if (write(spi_fd, buffer, sizeof(buffer)) != sizeof(buffer)) { perror("Error writing to SPI"); close(spi_fd); return EXIT_FAILURE; } else { printf("Transmitted: 0x%02X\n", buffer[0]); } // Add delay if needed usleep(1000000); // Delay for 1 second } // Close SPI device (not reached in this example) close(spi_fd); return EXIT_SUCCESS; }