diff --git a/IMX6ULL/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.md b/IMX6ULL/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.md new file mode 100644 index 0000000..ddba67d --- /dev/null +++ b/IMX6ULL/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.md @@ -0,0 +1,109 @@ +# 使用spidev操作SPI_DAC模块 # + +参考资料: + +* 内核驱动:`drivers\spi\spidev.c` + +* 内核提供的测试程序:`tools\spi\spidev_fdx.c` + +* 内核文档:`Documentation\spi\spidev` + +* DAC芯片手册:`TLC5615.pdf` + + + +## 1. 硬件 + +### 1.1 原理图 + +IMX6ULL: + +![image-20220309150927785](pic/33_imx6ull_dac.png) + +STM32MP157: + +![image-20220309151025637](pic/34_stm32mp157_dac.png) + + + +原理图: + +![image-20220309151636533](pic/35_dac_sch.png) + + + +### 1.2 连接 + +#### 1.2.1 IMX6ULL + +DAC模块接到IMX6ULL扩展板的SPI_A插座上: + +![image-20220309164031109](pic/40_dac_on_imx6ull.png) + + + +#### 1.2.2 STM32MP157 + + + + + +## 2. DAC操作原理 + +### 2.1 内部框图 + +![image-20220309155625021](pic/36_dac_block.png) + +操作过程为: + +* CS为低 +* 在SCLK的上升沿,从DIN采集16位数据,存入上图中的`16-Bit Shift Register` +* 在CS的上升沿,把`16-Bit Shift Register`中的10位数据传入`10-Bit DAC Register`,作为模拟量在OUT引脚输出 + +**注意**: + +* 传输的16位数据中,高4位是无意义的 +* 中间10位才被转换为模拟量 +* 最低2位必须是0 + + + +### 2.2 时序图 + +![image-20220309160306094](pic/37_dac_timing_diagram.png) + +使用SPI传输的细节: + +* SCLK初始电平为低 +* 使用16个SCLK周期来传输16位数据 +* 在SCLK上升沿读取DIN电平 +* 在SCLK上升沿发出DOUT信号 +* DOUT数据来自`16-Bit Shift Register` + * 第1个数据是上次数据遗留下的LSB位 + * 其余15个数据来自`16-Bit Shift Register`的高15位 + * `16-Bit Shift Register`的LSB在下一个周期的第1个时钟传输 + * LSB必定是0,所以当前的周期里读出`16-Bit Shift Register`的15位数据也足够了 + +### 2.3 DAC公式 + +![image-20220309162256125](pic/38_dac_value.png) + + + +```shell +输出电压 = 2 * VREFIN * n / 1024 = 2 * 2.048 * n / 1024 +其中: n为10位数值 +``` + + + +## 3. 编写APP + +源码在GIT仓库里,这2个位置里的源码是一样的: + +![image-20220310120532411](pic/41_dac_app_use_spidev.png) + + + +![image-20220310120646206](pic/42_dac_app_use_spidev.png) + diff --git a/IMX6ULL/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.tif b/IMX6ULL/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.tif new file mode 100644 index 0000000..e0f05fc Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.tif differ diff --git a/IMX6ULL/doc_pic/11_SPI/07_DAC模块上机实验.md b/IMX6ULL/doc_pic/11_SPI/07_DAC模块上机实验.md new file mode 100644 index 0000000..0df054a --- /dev/null +++ b/IMX6ULL/doc_pic/11_SPI/07_DAC模块上机实验.md @@ -0,0 +1,144 @@ +# 使用spidev操作SPI_DAC模块 # + +参考资料: + +* 内核驱动:`drivers\spi\spidev.c` + +* 内核提供的测试程序:`tools\spi\spidev_fdx.c` + +* 内核文档:`Documentation\spi\spidev` + +* DAC芯片手册:`TLC5615.pdf` + + + +## 1. 硬件 + +### 1.1 原理图 + +IMX6ULL: + +![image-20220309150927785](pic/33_imx6ull_dac.png) + +STM32MP157: + +![image-20220309151025637](pic/34_stm32mp157_dac.png) + + + +原理图: + +![image-20220309151636533](pic/35_dac_sch.png) + + + +### 1.2 连接 + +#### 1.2.1 IMX6ULL + +DAC模块接到IMX6ULL扩展板的SPI_A插座上: + +![image-20220309164031109](pic/40_dac_on_imx6ull.png) + + + +#### 1.2.2 STM32MP157 + + + + + +## 2. DAC操作原理 + +### 2.1 内部框图 + +![image-20220309155625021](pic/36_dac_block.png) + +操作过程为: + +* CS为低 +* 在SCLK的上升沿,从DIN采集16位数据,存入上图中的`16-Bit Shift Register` +* 在CS的上升沿,把`16-Bit Shift Register`中的10位数据传入`10-Bit DAC Register`,作为模拟量在OUT引脚输出 + +**注意**: + +* 传输的16位数据中,高4位是无意义的 +* 中间10位才被转换为模拟量 +* 最低2位必须是0 + + + +### 2.2 时序图 + +![image-20220309160306094](pic/37_dac_timing_diagram.png) + +使用SPI传输的细节: + +* SCLK初始电平为低 +* 使用16个SCLK周期来传输16位数据 +* 在SCLK上升沿读取DIN电平 +* 在SCLK上升沿发出DOUT信号 +* DOUT数据来自`16-Bit Shift Register` + * 第1个数据是上次数据遗留下的LSB位 + * 其余15个数据来自`16-Bit Shift Register`的高15位 + * `16-Bit Shift Register`的LSB在下一个周期的第1个时钟传输 + * LSB必定是0,所以当前的周期里读出`16-Bit Shift Register`的15位数据也足够了 + +### 2.3 DAC公式 + +![image-20220309162256125](pic/38_dac_value.png) + + + +```shell +输出电压 = 2 * VREFIN * n / 1024 = 2 * 2.048 * n / 1024 +其中: n为10位数值 +``` + + + +## 3. 编写设备树 + +确认SPI时钟最大频率: + +![image-20220309163435541](pic/39_dac_time_param.png) + +```shell +T = 25 + 25 = 50ns +F = 20000000 = 20MHz +``` + + + +设备树如下: + +```shell + dac: dac { + compatible = "spidev"; + reg = <0>; + spi-max-frequency = <20000000>; + }; +``` + + + +### 3.1 IMX6ULL + + + +### 3.2 STM32MP157 + + + + + +## 3. 编写APP + +源码在GIT仓库里,这2个位置里的源码是一样的: + +![image-20220310120532411](pic/41_dac_app_use_spidev.png) + + + +![image-20220310120646206](pic/42_dac_app_use_spidev.png) + diff --git a/IMX6ULL/doc_pic/11_SPI/TLC5615.pdf b/IMX6ULL/doc_pic/11_SPI/TLC5615.pdf new file mode 100644 index 0000000..15b6e26 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/TLC5615.pdf differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/33_imx6ull_dac.png b/IMX6ULL/doc_pic/11_SPI/pic/33_imx6ull_dac.png new file mode 100644 index 0000000..02b215a Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/33_imx6ull_dac.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/34_stm32mp157_dac.png b/IMX6ULL/doc_pic/11_SPI/pic/34_stm32mp157_dac.png new file mode 100644 index 0000000..5c18583 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/34_stm32mp157_dac.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/35_dac_sch.png b/IMX6ULL/doc_pic/11_SPI/pic/35_dac_sch.png new file mode 100644 index 0000000..effdbb3 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/35_dac_sch.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/36_dac_block.png b/IMX6ULL/doc_pic/11_SPI/pic/36_dac_block.png new file mode 100644 index 0000000..1197452 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/36_dac_block.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/37_dac_timing_diagram.png b/IMX6ULL/doc_pic/11_SPI/pic/37_dac_timing_diagram.png new file mode 100644 index 0000000..c437bff Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/37_dac_timing_diagram.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/38_dac_value.png b/IMX6ULL/doc_pic/11_SPI/pic/38_dac_value.png new file mode 100644 index 0000000..b93b585 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/38_dac_value.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/39_dac_time_param.png b/IMX6ULL/doc_pic/11_SPI/pic/39_dac_time_param.png new file mode 100644 index 0000000..874b98b Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/39_dac_time_param.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/40_dac_on_imx6ull.png b/IMX6ULL/doc_pic/11_SPI/pic/40_dac_on_imx6ull.png new file mode 100644 index 0000000..34e8163 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/40_dac_on_imx6ull.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/41_dac_app_use_spidev.png b/IMX6ULL/doc_pic/11_SPI/pic/41_dac_app_use_spidev.png new file mode 100644 index 0000000..6c84e5e Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/41_dac_app_use_spidev.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/42_dac_app_use_spidev.png b/IMX6ULL/doc_pic/11_SPI/pic/42_dac_app_use_spidev.png new file mode 100644 index 0000000..263dd77 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/42_dac_app_use_spidev.png differ diff --git a/IMX6ULL/source/11_SPI/02_dac_use_spidev/dac_test.c b/IMX6ULL/source/11_SPI/02_dac_use_spidev/dac_test.c new file mode 100644 index 0000000..b613bda --- /dev/null +++ b/IMX6ULL/source/11_SPI/02_dac_use_spidev/dac_test.c @@ -0,0 +1,70 @@ + + +/* 参考: tools\spi\spidev_fdx.c */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +/* dac_test /dev/spidevB.D */ + +int main(int argc, char **argv) +{ + int fd; + unsigned int val; + struct spi_ioc_transfer xfer[1]; + int status; + + unsigned char tx_buf[2]; + unsigned char rx_buf[2]; + + if (argc != 3) + { + printf("Usage: %s /dev/spidevB.D \n", argv[0]); + return 0; + } + + fd = open(argv[1], O_RDWR); + if (fd < 0) { + printf("can not open %s\n", argv[1]); + return 1; + } + + val = strtoul(argv[2], NULL, 0); + val <<= 2; /* bit0,bit1 = 0b00 */ + val &= 0xFFC; /* 只保留10bit */ + + tx_buf[1] = val & 0xff; + tx_buf[0] = (val>>8) & 0xff; + + memset(xfer, 0, sizeof xfer); + + + xfer[0].tx_buf = tx_buf; + xfer[0].rx_buf = rx_buf; + xfer[0].len = 2; + + status = ioctl(fd, SPI_IOC_MESSAGE(1), xfer); + if (status < 0) { + printf("SPI_IOC_MESSAGE\n"); + return -1; + } + + /* 打印 */ + val = (rx_buf[0] << 8) | (rx_buf[1]); + val >>= 1; + printf("Pre val = %d\n", val); + + + return 0; +} + diff --git a/README.md b/README.md index f628aac..b5425ce 100644 --- a/README.md +++ b/README.md @@ -510,6 +510,12 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git 05_spidev的使用(SPI用户态API) ``` +* 2021.03.10 发布"SPI子系统": + + ```shell + 06_使用spidev操作SPI_DAC模块 + ``` + ## 6. 联系方式 diff --git a/STM32MP157/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.md b/STM32MP157/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.md new file mode 100644 index 0000000..ddba67d --- /dev/null +++ b/STM32MP157/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.md @@ -0,0 +1,109 @@ +# 使用spidev操作SPI_DAC模块 # + +参考资料: + +* 内核驱动:`drivers\spi\spidev.c` + +* 内核提供的测试程序:`tools\spi\spidev_fdx.c` + +* 内核文档:`Documentation\spi\spidev` + +* DAC芯片手册:`TLC5615.pdf` + + + +## 1. 硬件 + +### 1.1 原理图 + +IMX6ULL: + +![image-20220309150927785](pic/33_imx6ull_dac.png) + +STM32MP157: + +![image-20220309151025637](pic/34_stm32mp157_dac.png) + + + +原理图: + +![image-20220309151636533](pic/35_dac_sch.png) + + + +### 1.2 连接 + +#### 1.2.1 IMX6ULL + +DAC模块接到IMX6ULL扩展板的SPI_A插座上: + +![image-20220309164031109](pic/40_dac_on_imx6ull.png) + + + +#### 1.2.2 STM32MP157 + + + + + +## 2. DAC操作原理 + +### 2.1 内部框图 + +![image-20220309155625021](pic/36_dac_block.png) + +操作过程为: + +* CS为低 +* 在SCLK的上升沿,从DIN采集16位数据,存入上图中的`16-Bit Shift Register` +* 在CS的上升沿,把`16-Bit Shift Register`中的10位数据传入`10-Bit DAC Register`,作为模拟量在OUT引脚输出 + +**注意**: + +* 传输的16位数据中,高4位是无意义的 +* 中间10位才被转换为模拟量 +* 最低2位必须是0 + + + +### 2.2 时序图 + +![image-20220309160306094](pic/37_dac_timing_diagram.png) + +使用SPI传输的细节: + +* SCLK初始电平为低 +* 使用16个SCLK周期来传输16位数据 +* 在SCLK上升沿读取DIN电平 +* 在SCLK上升沿发出DOUT信号 +* DOUT数据来自`16-Bit Shift Register` + * 第1个数据是上次数据遗留下的LSB位 + * 其余15个数据来自`16-Bit Shift Register`的高15位 + * `16-Bit Shift Register`的LSB在下一个周期的第1个时钟传输 + * LSB必定是0,所以当前的周期里读出`16-Bit Shift Register`的15位数据也足够了 + +### 2.3 DAC公式 + +![image-20220309162256125](pic/38_dac_value.png) + + + +```shell +输出电压 = 2 * VREFIN * n / 1024 = 2 * 2.048 * n / 1024 +其中: n为10位数值 +``` + + + +## 3. 编写APP + +源码在GIT仓库里,这2个位置里的源码是一样的: + +![image-20220310120532411](pic/41_dac_app_use_spidev.png) + + + +![image-20220310120646206](pic/42_dac_app_use_spidev.png) + diff --git a/STM32MP157/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.tif b/STM32MP157/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.tif new file mode 100644 index 0000000..e0f05fc Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/06_使用spidev操作SPI_DAC模块.tif differ diff --git a/STM32MP157/doc_pic/11_SPI/07_DAC模块上机实验.md b/STM32MP157/doc_pic/11_SPI/07_DAC模块上机实验.md new file mode 100644 index 0000000..0df054a --- /dev/null +++ b/STM32MP157/doc_pic/11_SPI/07_DAC模块上机实验.md @@ -0,0 +1,144 @@ +# 使用spidev操作SPI_DAC模块 # + +参考资料: + +* 内核驱动:`drivers\spi\spidev.c` + +* 内核提供的测试程序:`tools\spi\spidev_fdx.c` + +* 内核文档:`Documentation\spi\spidev` + +* DAC芯片手册:`TLC5615.pdf` + + + +## 1. 硬件 + +### 1.1 原理图 + +IMX6ULL: + +![image-20220309150927785](pic/33_imx6ull_dac.png) + +STM32MP157: + +![image-20220309151025637](pic/34_stm32mp157_dac.png) + + + +原理图: + +![image-20220309151636533](pic/35_dac_sch.png) + + + +### 1.2 连接 + +#### 1.2.1 IMX6ULL + +DAC模块接到IMX6ULL扩展板的SPI_A插座上: + +![image-20220309164031109](pic/40_dac_on_imx6ull.png) + + + +#### 1.2.2 STM32MP157 + + + + + +## 2. DAC操作原理 + +### 2.1 内部框图 + +![image-20220309155625021](pic/36_dac_block.png) + +操作过程为: + +* CS为低 +* 在SCLK的上升沿,从DIN采集16位数据,存入上图中的`16-Bit Shift Register` +* 在CS的上升沿,把`16-Bit Shift Register`中的10位数据传入`10-Bit DAC Register`,作为模拟量在OUT引脚输出 + +**注意**: + +* 传输的16位数据中,高4位是无意义的 +* 中间10位才被转换为模拟量 +* 最低2位必须是0 + + + +### 2.2 时序图 + +![image-20220309160306094](pic/37_dac_timing_diagram.png) + +使用SPI传输的细节: + +* SCLK初始电平为低 +* 使用16个SCLK周期来传输16位数据 +* 在SCLK上升沿读取DIN电平 +* 在SCLK上升沿发出DOUT信号 +* DOUT数据来自`16-Bit Shift Register` + * 第1个数据是上次数据遗留下的LSB位 + * 其余15个数据来自`16-Bit Shift Register`的高15位 + * `16-Bit Shift Register`的LSB在下一个周期的第1个时钟传输 + * LSB必定是0,所以当前的周期里读出`16-Bit Shift Register`的15位数据也足够了 + +### 2.3 DAC公式 + +![image-20220309162256125](pic/38_dac_value.png) + + + +```shell +输出电压 = 2 * VREFIN * n / 1024 = 2 * 2.048 * n / 1024 +其中: n为10位数值 +``` + + + +## 3. 编写设备树 + +确认SPI时钟最大频率: + +![image-20220309163435541](pic/39_dac_time_param.png) + +```shell +T = 25 + 25 = 50ns +F = 20000000 = 20MHz +``` + + + +设备树如下: + +```shell + dac: dac { + compatible = "spidev"; + reg = <0>; + spi-max-frequency = <20000000>; + }; +``` + + + +### 3.1 IMX6ULL + + + +### 3.2 STM32MP157 + + + + + +## 3. 编写APP + +源码在GIT仓库里,这2个位置里的源码是一样的: + +![image-20220310120532411](pic/41_dac_app_use_spidev.png) + + + +![image-20220310120646206](pic/42_dac_app_use_spidev.png) + diff --git a/STM32MP157/doc_pic/11_SPI/TLC5615.pdf b/STM32MP157/doc_pic/11_SPI/TLC5615.pdf new file mode 100644 index 0000000..15b6e26 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/TLC5615.pdf differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/33_imx6ull_dac.png b/STM32MP157/doc_pic/11_SPI/pic/33_imx6ull_dac.png new file mode 100644 index 0000000..02b215a Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/33_imx6ull_dac.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/34_stm32mp157_dac.png b/STM32MP157/doc_pic/11_SPI/pic/34_stm32mp157_dac.png new file mode 100644 index 0000000..5c18583 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/34_stm32mp157_dac.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/35_dac_sch.png b/STM32MP157/doc_pic/11_SPI/pic/35_dac_sch.png new file mode 100644 index 0000000..effdbb3 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/35_dac_sch.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/36_dac_block.png b/STM32MP157/doc_pic/11_SPI/pic/36_dac_block.png new file mode 100644 index 0000000..1197452 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/36_dac_block.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/37_dac_timing_diagram.png b/STM32MP157/doc_pic/11_SPI/pic/37_dac_timing_diagram.png new file mode 100644 index 0000000..c437bff Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/37_dac_timing_diagram.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/38_dac_value.png b/STM32MP157/doc_pic/11_SPI/pic/38_dac_value.png new file mode 100644 index 0000000..b93b585 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/38_dac_value.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/39_dac_time_param.png b/STM32MP157/doc_pic/11_SPI/pic/39_dac_time_param.png new file mode 100644 index 0000000..874b98b Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/39_dac_time_param.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/40_dac_on_imx6ull.png b/STM32MP157/doc_pic/11_SPI/pic/40_dac_on_imx6ull.png new file mode 100644 index 0000000..34e8163 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/40_dac_on_imx6ull.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/41_dac_app_use_spidev.png b/STM32MP157/doc_pic/11_SPI/pic/41_dac_app_use_spidev.png new file mode 100644 index 0000000..6c84e5e Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/41_dac_app_use_spidev.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/42_dac_app_use_spidev.png b/STM32MP157/doc_pic/11_SPI/pic/42_dac_app_use_spidev.png new file mode 100644 index 0000000..263dd77 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/42_dac_app_use_spidev.png differ diff --git a/STM32MP157/source/A7/11_SPI/02_dac_use_spidev/dac_test.c b/STM32MP157/source/A7/11_SPI/02_dac_use_spidev/dac_test.c new file mode 100644 index 0000000..b613bda --- /dev/null +++ b/STM32MP157/source/A7/11_SPI/02_dac_use_spidev/dac_test.c @@ -0,0 +1,70 @@ + + +/* 参考: tools\spi\spidev_fdx.c */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +/* dac_test /dev/spidevB.D */ + +int main(int argc, char **argv) +{ + int fd; + unsigned int val; + struct spi_ioc_transfer xfer[1]; + int status; + + unsigned char tx_buf[2]; + unsigned char rx_buf[2]; + + if (argc != 3) + { + printf("Usage: %s /dev/spidevB.D \n", argv[0]); + return 0; + } + + fd = open(argv[1], O_RDWR); + if (fd < 0) { + printf("can not open %s\n", argv[1]); + return 1; + } + + val = strtoul(argv[2], NULL, 0); + val <<= 2; /* bit0,bit1 = 0b00 */ + val &= 0xFFC; /* 只保留10bit */ + + tx_buf[1] = val & 0xff; + tx_buf[0] = (val>>8) & 0xff; + + memset(xfer, 0, sizeof xfer); + + + xfer[0].tx_buf = tx_buf; + xfer[0].rx_buf = rx_buf; + xfer[0].len = 2; + + status = ioctl(fd, SPI_IOC_MESSAGE(1), xfer); + if (status < 0) { + printf("SPI_IOC_MESSAGE\n"); + return -1; + } + + /* 打印 */ + val = (rx_buf[0] << 8) | (rx_buf[1]); + val >>= 1; + printf("Pre val = %d\n", val); + + + return 0; +} + diff --git a/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/TLC5615.pdf b/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/TLC5615.pdf new file mode 100644 index 0000000..15b6e26 Binary files /dev/null and b/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/TLC5615.pdf differ diff --git a/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/dac.png b/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/dac.png new file mode 100644 index 0000000..965dcf0 Binary files /dev/null and b/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/dac.png differ diff --git a/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/spi_dac_module_v1.0.pdf b/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/spi_dac_module_v1.0.pdf new file mode 100644 index 0000000..cd4b756 Binary files /dev/null and b/STM32MP157/开发板配套资料/原理图/04_Extend_modules(外设模块)/dac/spi_dac_module_v1.0.pdf differ