天嵌二次封装库使用手册  V2.1.2
lib_spi.h
浏览该文件的文档.
1 
7 #ifndef LINUX_LIBV2_SOURCE_SPI_LIB_SPI_H_
8 #define LINUX_LIBV2_SOURCE_SPI_LIB_SPI_H_
9 
10 // Copyright 2024
11 
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <fcntl.h>
15 #include <string.h>
16 #include <linux/spi/spidev.h>
17 #include <sys/ioctl.h>
18 
19 static unsigned int mode = 0x0;
20 static unsigned char bits = 8; //8位
21 static unsigned int speed = 500000; //500kHz
22 
23 #ifdef __cplusplus
24 #define SPI_API extern "C"
25 #else
26 #define SPI_API
27 #endif
28 
34  SPI_API int set_spi_mode(int fd, unsigned short mode);
41  SPI_API int set_spi_bits_per_word(int fd, unsigned short bits);
48  SPI_API int set_spi_max_transfer_speed(int fd, unsigned int speed);
59  SPI_API int spi_message_transfer(int fd, unsigned char *sendBuf, int send_len, unsigned char *recvBuf, int recv_len);
68  SPI_API int spi_message_send(int fd, unsigned char *sendBuf, int len);
69 
70 #endif
SPI_API int set_spi_mode(int fd, unsigned short mode)
设置SPI模式
SPI_API int set_spi_bits_per_word(int fd, unsigned short bits)
设置SPI通讯时每个字是多少位
SPI_API int set_spi_max_transfer_speed(int fd, unsigned int speed)
设置SPI通讯时最大波特率
SPI_API int spi_message_transfer(int fd, unsigned char *sendBuf, int send_len, unsigned char *recvBuf, int recv_len)
全双工SPI通讯函数,能同时收发
#define SPI_API
Definition: lib_spi.h:26
SPI_API int spi_message_send(int fd, unsigned char *sendBuf, int len)
SPI通讯发送函数