Skip to content

Commit

Permalink
Merge pull request #17 from MK16kawai/dev
Browse files Browse the repository at this point in the history
update spi&adc example&docs, pinmap docs
  • Loading branch information
Neutree authored Jun 13, 2024
2 parents 8fcf7df + 566ddfe commit e4efe52
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 37 deletions.
6 changes: 3 additions & 3 deletions docs/doc/en/peripheral/adc.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/doc/en/peripheral/pinmap.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: MaixPy Pinmap Introduction
title: Using PINMAP in MaixPy
update:
- date: 2024-06-11
author: iawak9lkm
Expand Down
21 changes: 10 additions & 11 deletions docs/doc/en/peripheral/spi.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: MaixPy ues SPI
title: Using SPI in MaixPy
update:
- date: 2024-06-11
author: iawak9lkm
Expand Down Expand Up @@ -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.

Expand All @@ -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:

Expand All @@ -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():
Expand All @@ -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))

Expand Down
4 changes: 4 additions & 0 deletions docs/doc/en/sidebar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ items:

- label: On-chip peripherals
items:
- file: peripheral/pinmap.md
label: PINMAP
- file: peripheral/gpio.md
label: GPIO
- file: peripheral/uart.md
Expand All @@ -119,6 +121,8 @@ items:
label: SPI
- file: peripheral/wdt.md
label: WDT watchdog
- file: peripheral/adc.md
label: ADC

- label: Off-chip modules
items:
Expand Down
6 changes: 3 additions & 3 deletions docs/doc/zh/peripheral/adc.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: MaixPy ADC 模拟信号数字转换器使用介绍
title: MaixPy ADC 使用介绍
update:
- date: 2024-06-11
author: iawak9lkm
Expand All @@ -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}")
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/doc/zh/peripheral/pinmap.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: MaixPy Pinmap 管脚映射使用介绍
title: MaixPy Pinmap 使用介绍
update:
- date: 2024-06-11
author: iawak9lkm
Expand Down
19 changes: 9 additions & 10 deletions docs/doc/zh/peripheral/spi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 通常支持全双工和半双工通信。

Expand All @@ -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 很简单:

Expand All @@ -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():
Expand All @@ -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))

Expand Down
4 changes: 4 additions & 0 deletions docs/doc/zh/sidebar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ items:

- label: 片上外设
items:
- file: peripheral/pinmap.md
label: PINMAP 使用
- file: peripheral/gpio.md
label: GPIO 和 点灯
- file: peripheral/uart.md
Expand All @@ -119,6 +121,8 @@ items:
label: SPI 使用
- file: peripheral/wdt.md
label: WDT 看门狗使用
- file: peripheral/adc.md
label: ADC 使用

- label: 片外模块
items:
Expand Down
2 changes: 1 addition & 1 deletion examples/peripheral/adc/adc_read.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Binary file removed examples/peripheral/spi/maixcam-logo.jpg
Binary file not shown.
5 changes: 2 additions & 3 deletions examples/peripheral/spi/spi_loopback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"A24": "SPI4_CS",
"A23": "SPI4_MISO",
"A25": "SPI4_MOSI",
"A22": "SPI4_SCK",
"A27": "GPIOA27"
"A22": "SPI4_SCK"
}

for pin, func in pin_function.items():
Expand All @@ -14,7 +13,7 @@
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))

Expand Down
8 changes: 4 additions & 4 deletions examples/peripheral/spi/spi_st7789.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
|5|SDA |A25 |
|6|SCL |A22 |
|7|VCC |3V3 |
|8|CS |A27 |
|8|CS |A24 |
"""

import sys
Expand All @@ -19,16 +19,16 @@
import st7789
from maix import time

image_file = "maixcam-logo.jpg"
### Select a picture.
image_file = "xxx"

disp = st7789.ST7789(
height=135,
rotation=0,
port=4,
dc="A14",
soft_cs="A27",
backlight=None,
spi_speed_hz=80000000,
spi_speed_hz=1250000,
offset_left=40,
offset_top=53
)
Expand Down

0 comments on commit e4efe52

Please sign in to comment.