From 566ddfee471ae5debffdf95cdc17311be4f79115 Mon Sep 17 00:00:00 2001 From: Mk16kawai <1041324852hzq@sina.com> Date: Thu, 13 Jun 2024 10:37:25 +0800 Subject: [PATCH] update spi&adc example&docs, pinmap docs --- docs/doc/en/peripheral/adc.md | 6 +++--- docs/doc/en/peripheral/pinmap.md | 2 +- docs/doc/en/peripheral/spi.md | 21 ++++++++++----------- docs/doc/en/sidebar.yaml | 4 ++++ docs/doc/zh/peripheral/adc.md | 6 +++--- docs/doc/zh/peripheral/pinmap.md | 2 +- docs/doc/zh/peripheral/spi.md | 19 +++++++++---------- docs/doc/zh/sidebar.yaml | 4 ++++ examples/peripheral/adc/adc_read.py | 2 +- examples/peripheral/spi/maixcam-logo.jpg | Bin 5416 -> 0 bytes examples/peripheral/spi/spi_loopback.py | 5 ++--- examples/peripheral/spi/spi_st7789.py | 8 ++++---- 12 files changed, 42 insertions(+), 37 deletions(-) delete mode 100644 examples/peripheral/spi/maixcam-logo.jpg diff --git a/docs/doc/en/peripheral/adc.md b/docs/doc/en/peripheral/adc.md index 00922889..0428eb27 100644 --- a/docs/doc/en/peripheral/adc.md +++ b/docs/doc/en/peripheral/adc.md @@ -1,5 +1,5 @@ --- -title: MaixPy ADC Analog Signal-to-Digital Converter Usage Introduction +title: Using ADC in MaixPy update: - date: 2024-06-11 author: iawak9lkm @@ -28,7 +28,7 @@ Using ADC with MaixPy is easy: from maix.peripheral import adc from maix import time -a = adc.ADC(0, adc.RES_BIT_12, 5.0062) +a = adc.ADC(0, adc.RES_BIT_12) raw_data = a.read() print(f"ADC raw data:{raw_data}") @@ -55,7 +55,7 @@ MaixCAM's ADC peripheral has a sampling accuracy of 12 bits, which means that th The MaixCAM's ADC peripheral cannot scan at a frequency higher than 320K/s, which is the reason for the additional wait time between ADC samples in the previous example. -The MaixCAM's ADC peripheral has an internal reference voltage of 1.5V, which may vary slightly in actual use.Since the typical internal reference voltage is 1.5 V, the ADC range of Soc is 0 to 1.5 V. Since the ADC range of this range is small, MaixCAM has designed a voltage divider circuit for the ADC peripheral to increase the ADC range. The reference voltage Vin_max of this voltage divider circuit is about 4.6~5.0V, typical value 4.8V, due to the error of resistor resistance in the circuit, the impedance of ADC external device, and the deviation of internal reference voltage. +The MaixCAM's ADC peripheral has an internal reference voltage of 1.5V, which may vary slightly in actual use.Since the typical internal reference voltage is 1.5 V, the ADC range of Soc is 0 to 1.5 V. Since the ADC range of this range is small, MaixCAM has designed a voltage divider circuit for the ADC peripheral to increase the ADC range. The reference voltage Vin_max of this voltage divider circuit is about 4.6~5.0V, due to the error of resistor resistance in the circuit, the impedance of ADC external device, and the deviation of internal reference voltage. A higher precision default value has been chosen in the API, and there is generally no need to pass this parameter. ![](https://wiki.sipeed.com/hardware/zh/lichee/assets/RV_Nano/peripheral/adc.png) diff --git a/docs/doc/en/peripheral/pinmap.md b/docs/doc/en/peripheral/pinmap.md index c6714898..1ebc4e8f 100644 --- a/docs/doc/en/peripheral/pinmap.md +++ b/docs/doc/en/peripheral/pinmap.md @@ -1,5 +1,5 @@ --- -title: MaixPy Pinmap Introduction +title: Using PINMAP in MaixPy update: - date: 2024-06-11 author: iawak9lkm diff --git a/docs/doc/en/peripheral/spi.md b/docs/doc/en/peripheral/spi.md index 1dbccfb2..32d39ead 100644 --- a/docs/doc/en/peripheral/spi.md +++ b/docs/doc/en/peripheral/spi.md @@ -1,5 +1,5 @@ --- -title: MaixPy ues SPI +title: Using SPI in MaixPy update: - date: 2024-06-11 author: iawak9lkm @@ -38,12 +38,12 @@ In terms of communication protocols, SPI behavior is generally like this: Polarity and phase are combined to form the four modes of SPI: - | Mode | CPOL | CPHA | - | ---- | ---- | ---- | - | 0 | 0 | 0 | - | 1 | 0 | 1 | - | 2 | 1 | 0 | - | 3 | 1 | 1 | +| Mode | CPOL | CPHA | +| ---- | ---- | ---- | +| 0 | 0 | 0 | +| 1 | 0 | 1 | +| 2 | 1 | 0 | +| 3 | 1 | 1 | * SPI typically supports both full-duplex transmission and half-duplex transmission. @@ -57,7 +57,7 @@ This is the pinout of MaixCAM. You need to use `maix.peripheral.pinmap` to complete the pin mapping for SPI before use. -**Note: The MaixCAM's SPI can only be used as an SPI master device. MaixCAM's SPI does not support modifying the valid level of the hardware CS pins at this time. The valid level of SPI0-3 hardware CS is low, and the valid level of SPI4 hardware CS is high. If you need to use other CS active levels, configure the software CS pins and their active levels in the SPI API.** +**Note: The MaixCAM's SPI can only be used as an SPI master device. MaixCAM's SPI does not support modifying the valid level of the hardware CS pins at this time. The active level of all SPI hardware CS is high. If you need to use other CS active levels, configure the software CS pins and their active levels in the SPI API. SPI4 is the software simulated SPI, the measured maximum rate is 1.25MHz, and the usage is the same as hardware SPI.** Using SPI with MaixPy is easy: @@ -68,8 +68,7 @@ pin_function = { "A24": "SPI4_CS", "A23": "SPI4_MISO", "A25": "SPI4_MOSI", - "A22": "SPI4_SCK", - "A27": "GPIOA27" + "A22": "SPI4_SCK" } for pin, func in pin_function.items(): @@ -78,7 +77,7 @@ for pin, func in pin_function.items(): exit(-1) -spidev = spi.SPI(4, spi.Mode.MASTER, 400*1000, soft_cs=True, cs="A27", cs_enable=0) +spidev = spi.SPI(4, spi.Mode.MASTER, 1250000) b = bytes(range(0, 8)) diff --git a/docs/doc/en/sidebar.yaml b/docs/doc/en/sidebar.yaml index a671dbaf..cf31881b 100644 --- a/docs/doc/en/sidebar.yaml +++ b/docs/doc/en/sidebar.yaml @@ -103,6 +103,8 @@ items: - label: On-chip peripherals items: + - file: peripheral/pinmap.md + label: PINMAP - file: peripheral/gpio.md label: GPIO - file: peripheral/uart.md @@ -115,6 +117,8 @@ items: label: SPI - file: peripheral/wdt.md label: WDT watchdog + - file: peripheral/adc.md + label: ADC - label: Off-chip modules items: diff --git a/docs/doc/zh/peripheral/adc.md b/docs/doc/zh/peripheral/adc.md index 2ee667de..2729f7ec 100644 --- a/docs/doc/zh/peripheral/adc.md +++ b/docs/doc/zh/peripheral/adc.md @@ -1,5 +1,5 @@ --- -title: MaixPy ADC 模拟信号数字转换器使用介绍 +title: MaixPy ADC 使用介绍 update: - date: 2024-06-11 author: iawak9lkm @@ -26,7 +26,7 @@ ADC 外设一般有两个主要参数:分辨率和参考电压。 from maix.peripheral import adc from maix import time -a = adc.ADC(0, adc.RES_BIT_12, 5.0062) +a = adc.ADC(0, adc.RES_BIT_12) raw_data = a.read() print(f"ADC raw data:{raw_data}") @@ -53,7 +53,7 @@ MaixCAM ADC 外设采样精度为 12bit,也就是说采样输出范围为 0~40 MaixCAM ADC 外设的扫描频率不能高于 320K/s,也就是上述示例中增加延时的原因。 -MaixCAM ADC 外设内部参考电压Vref为 1.5V,实际使用时会有些许偏差。因为内部参考电压典型值为 1.5V,所以 Soc 的 ADC 量程为 0~1.5V。该量程的 ADC 应用范围较小,故 MaixCAM 额外为 ADC 外设设计了分压电路来增大 ADC 的应用范围,该分压电路如下图所示。由于电路中电阻阻值存在误差、ADC 外设有阻抗、内部参考电压有些许偏差,该分压电路的参考电压 Vin_max 约为 4.6~5.0V,典型值 4.8V。 +MaixCAM ADC 外设内部参考电压Vref为 1.5V,实际使用时会有些许偏差。因为内部参考电压典型值为 1.5V,所以 Soc 的 ADC 量程为 0~1.5V。该量程的 ADC 应用范围较小,故 MaixCAM 额外为 ADC 外设设计了分压电路来增大 ADC 的应用范围,该分压电路如下图所示。由于电路中电阻阻值存在误差、ADC 外设有阻抗、内部参考电压有些许偏差,该分压电路的参考电压 Vin_max 约为 4.6~5.0V。API 中已经选择一个精度较高的默认值,一般情况下无需传递该参数。 ![](https://wiki.sipeed.com/hardware/zh/lichee/assets/RV_Nano/peripheral/adc.png) diff --git a/docs/doc/zh/peripheral/pinmap.md b/docs/doc/zh/peripheral/pinmap.md index a89911fb..c46b218a 100644 --- a/docs/doc/zh/peripheral/pinmap.md +++ b/docs/doc/zh/peripheral/pinmap.md @@ -1,5 +1,5 @@ --- -title: MaixPy Pinmap 管脚映射使用介绍 +title: MaixPy Pinmap 使用介绍 update: - date: 2024-06-11 author: iawak9lkm diff --git a/docs/doc/zh/peripheral/spi.md b/docs/doc/zh/peripheral/spi.md index 98578308..771eaa6c 100644 --- a/docs/doc/zh/peripheral/spi.md +++ b/docs/doc/zh/peripheral/spi.md @@ -38,12 +38,12 @@ SPI 采用主从模式(Master—Slave)架构,支持一个或多个Slave设备 极性与相位组合成了 SPI 的四种模式: - | Mode | CPOL | CPHA | - | ---- | ---- | ---- | - | 0 | 0 | 0 | - | 1 | 0 | 1 | - | 2 | 1 | 0 | - | 3 | 1 | 1 | +| Mode | CPOL | CPHA | +| ---- | ---- | ---- | +| 0 | 0 | 0 | +| 1 | 0 | 1 | +| 2 | 1 | 0 | +| 3 | 1 | 1 | * SPI 通常支持全双工和半双工通信。 @@ -59,7 +59,7 @@ MaixCAM 的引脚分布如下: 使用前需要 `maix.peripheral.pinmap` 完成对 SPI 的管脚映射。 -**注意:MaixCAM 由于其 SPI 外设的限制,只能作为 SPI 主设备使用。MaixCAM 的 SPI 暂时不支持修改硬件 CS 引脚有效电平,其中 SPI0~3 硬件 CS 的有效电平为低电平,SPI4 硬件 CS 的有效电平为高电平。如需要使用其他的 CS 有效电平,请在 SPI API 中配置软件 CS 引脚及其有效电平。** +**注意:MaixCAM 由于其 SPI 外设的限制,只能作为 SPI 主设备使用。MaixCAM 的 SPI 暂时不支持修改硬件 CS 引脚有效电平,所有 SPI 硬件 CS 的有效电平为高电平。如需要使用其他的 CS 有效电平,请在 SPI API 中配置软件 CS 引脚及其有效电平。SPI4 为软件模拟的 SPI,实测最大速率为 1.25MHz,使用方法与硬件 SPI 无异。** 通过 MaixPy 使用 SPI 很简单: @@ -70,8 +70,7 @@ pin_function = { "A24": "SPI4_CS", "A23": "SPI4_MISO", "A25": "SPI4_MOSI", - "A22": "SPI4_SCK", - "A27": "GPIOA27" + "A22": "SPI4_SCK" } for pin, func in pin_function.items(): @@ -80,7 +79,7 @@ for pin, func in pin_function.items(): exit(-1) -spidev = spi.SPI(4, spi.Mode.MASTER, 400*1000, soft_cs=True, cs="A27", cs_enable=0) +spidev = spi.SPI(4, spi.Mode.MASTER, 1250000) b = bytes(range(0, 8)) diff --git a/docs/doc/zh/sidebar.yaml b/docs/doc/zh/sidebar.yaml index 1d754e38..614e9a4e 100644 --- a/docs/doc/zh/sidebar.yaml +++ b/docs/doc/zh/sidebar.yaml @@ -103,6 +103,8 @@ items: - label: 片上外设 items: + - file: peripheral/pinmap.md + label: PINMAP 使用 - file: peripheral/gpio.md label: GPIO 和 点灯 - file: peripheral/uart.md @@ -115,6 +117,8 @@ items: label: SPI 使用 - file: peripheral/wdt.md label: WDT 看门狗使用 + - file: peripheral/adc.md + label: ADC 使用 - label: 片外模块 items: diff --git a/examples/peripheral/adc/adc_read.py b/examples/peripheral/adc/adc_read.py index dd6f1946..c15d307e 100755 --- a/examples/peripheral/adc/adc_read.py +++ b/examples/peripheral/adc/adc_read.py @@ -1,7 +1,7 @@ from maix.peripheral import adc from maix import time -a = adc.ADC(0, adc.RES_BIT_12, 5.0062) +a = adc.ADC(0, adc.RES_BIT_12) while True: raw_data = a.read() diff --git a/examples/peripheral/spi/maixcam-logo.jpg b/examples/peripheral/spi/maixcam-logo.jpg deleted file mode 100644 index cdcede3bec66e213b9977724e56c338ea09189b3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5416 zcmb_g2Ut_vmOc<5^j@VzA%KN)MKq{D=v53LML_9NjDR3WP#_c`AR*}@rwRf}3Ia;e1QiY>kQd&4^WHb_o0;#;yjkb0Z>@9AF6-ZG@3r?j+z(tDAnj!5 zXb14|@d1gv3*gcLUt3IM7y!7q0J{MI5C#Mxe1ITN|+F07MWf1ch#~u!xw5u&}5w z6e=nqDk>(qA0Za&=CcrPl2a)09 z_5d)RrGmVX*cyz#5g$K9Kv0NhlBgK3K(jQ@ditMBPhFLuceTj zTM$$;R^BN6TBWd-Reh&|`ydm(FE}nkL{w2pS!J8Hj_%G~yN&lBK$sjnWNl+>XYb(X zbj-uk%lo*GZ%F8=u<(e;)92z7&L?7$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