Created
December 13, 2012 00:58
-
-
Save beanieboi/4273126 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <fcntl.h> | |
#include <sys/ioctl.h> | |
#include <linux/spi/spidev.h> | |
#include <string.h> | |
static const char *device = "/dev/spidev0.0"; | |
static uint32_t speed = 100000; | |
int main(int argc, char *argv[]) | |
{ | |
int ret = 0; | |
int fd; | |
fd = open(device, O_WRONLY); | |
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); | |
if (ret == -1) | |
printf("ERRR SETTING SPEED %i\n", ret); | |
char bytes0[10]; | |
memset(bytes0, 0, 10); | |
char bytes1[10] = {0b11001111, 0b10110011, 0b11101101, 0b11011011, 0b1101110, 0b11011011, 0b10110101, 0b10101101, 0b01101011, 0b10101110}; | |
while(1) { | |
write(fd, bytes1, 10); | |
sleep(1); | |
write(fd, bytes0, 10); | |
sleep(1); | |
} | |
close(fd); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment