K230 to ESP32 communication using I2c and SPI

Viewed 640

重现步骤

期待结果和实际结果

软硬件版本信息

错误日志

尝试解决过程

补充材料

2 Answers

Hello, K230 Have 3 x SPI, and 5 x I2C, and 2 x SDIO, so you can use it communicate with esp32, and you can also use supported sdio wifi module like RTL8189 and AP6212.

  1. We are trying to establish a connection between ESP32 and K230 using I2C and SPI.
    We set the CanMV K230 as the master and the ESP32 as the slave. The K230 should send messages to the ESP32 using I2C with the following pin configuration:
    SCL (K230 pin 34) to SCL (ESP32 pin 22)
    SDA (K230 pin 35) to SDA (ESP32 pin 21)
    Again, in our SPI setup, we encountered the issue of not observing data transfer. The pins for SPI communication are set to:
    CS (K230 IO14) to CS (ESP32 IO05)
    CLK (K230 IO15) to CLK (ESP32 IO18)
    D0 (K230 IO16) to MOSI (ESP32 IO23)
    D1 (K230 IO17) to MISO (ESP32 IO19)

On data pin in SPI, continous high voltage(2.1 V) is showing in SPI and data is not transmitting in both protocol. The software image is CanMV-K230_micropython_v0.7_sdk_v1.6_nncase_v2.8.3.img, with the CanMV-K230-v1.1 hardware module.
I2C: Pull-up registers on data and clock lines, tried using i2c channels as well as using compatible pins of FPIOA.
SPI: Full QSPI (4 data lines) is implemented on both sides, but that doesn't work either.
Refernce code for both protocol is from CanMV examples.

1.我们正在尝试使用 I2C 和 SPI 在 ESP32 和 K230 之间建立连接。

  1. I2C通讯:
    我们将 CanMV K230 设置为主机,将 ESP32 设置为从机。 K230 应该使用具有以下引脚配置的 I2C 向 ESP32 发送消息:
    SCL(K230 引脚 34)至 SCL(ESP32 引脚 22)
    SDA(K230 引脚 35)至 SDA(ESP32 引脚 21)

  2. SPI通讯:
    同样,在我们的 SPI 设置中,我们遇到了未观察到数据传输的问题。 SPI 通信的引脚设置为:
    CS (K230 IO14) 至 CS (ESP32 IO05)
    CLK(K230 IO15)至 CLK(ESP32 IO18)
    D0 (K230 IO16) 至 MOSI (ESP32 IO23)
    D1 (K230 IO17) 至 MISO (ESP32 IO19)

在 SPI 的数据引脚上,SPI 中显示持续高电压(2.1 V),并且两种协议中都没有数据传输。

软件镜像为CanMV-K230_micropython_v0.7_sdk_v1.6_nncase_v2.8.3.img,带有CanMV-K230-v1.1硬件模块。

I2C:
数据和时钟线上的上拉寄存器,已尝试使用 i2c 通道以及使用 FPIOA 的兼容引脚。

SPI:
两侧都实现了完整的 QSPI(4 数据线),但也不起作用。

这两个协议的参考代码均来自 CanMV 示例。

Micro Python

from machine import I2C, FPIOA
import time

# Initialize FPIOA for configuring GPIO pins
fpioa = FPIOA()

# Configure pins for I2C1 (Check your board specification for pin numbers)
# Assuming GPIO numbers 34 (SCL) and 35 (SDA) are available and set for IIC1
fpioa.set_function(34, fpioa.IIC1_SCL)  # SCL on pin 34
fpioa.set_function(35, fpioa.IIC1_SDA)  # SDA on pin 35

# Initialize I2C on port 1 with frequency setting
i2c = I2C(1, freq=400000)  # I2C port 1, 400 kHz

# I2C address of the ESP32 slave
ESP32_I2C_ADDRESS = 0x3B

def send_hello_message():
    message = 'Hello ESP32'
    data = bytearray(message.encode('utf-8'))  # Convert string to bytes
    try:
        i2c.writeto(ESP32_I2C_ADDRESS, data)
        print("Sent to ESP32:", message)
    except Exception as e:
        print("Failed to send:", e)

# Main loop to send "Hello ESP32" every 5 seconds
while True:
    send_hello_message()
    time.sleep(5)  # Wait for 5 seconds before sending the next message

Micro Python

from machine import SPI
from machine import FPIOA
import time

a = FPIOA()

a.help(14)
a.set_function(14,a.QSPI0_CS0)
a.help(14)

a.help(15)
a.set_function(15,a.QSPI0_CLK)
a.help(15)

a.help(16)
a.set_function(16,a.QSPI0_D0)
a.help(16)

a.help(17)
a.set_function(17,a.QSPI0_D1)
a.help(17)

spi=SPI(1,baudrate=5000000, polarity=0, phase=0, bits=8) # spi init clock 5MHz, polarity 0, phase 0, data bitwide 8bits

while 1:
    
    a=bytes([0x55]) # send buff
    b = 0x00
    spi.write(a) 
    spi.read(b)
    print(b)
    time.sleep(1)

Hello @xelll, Please help me in this SPI and I2C Communication Establish

Hello, please download the lastest image from https://github.com/kendryte/canmv_k230/releases/tag/PreRelease, the old image have bugs in spi and i2c.

Hello @xelll, I load lastest image (CanMV-K230_micropython_PreRelease_nncase_v2.9.0.img.gz, CanMV-K230-V3P0_micropython_PreRelease_nncase_v2.9.0.img.gz, CanMV-K230_01Studio_micropython_PreRelease_nncase_v2.9.0.img) and tried to connect with CanMV IDE, but my board is not connected with IDE. I'm Getting Board is not connected (USB Not Recognized). when load Image (CanMV-K230_micropython_v0.7_sdk_v1.6_nncase_v2.8.3.img) and connect board with CanMV IDE, it is connect properly. it has the issue of Connection of SPI and I2C Connection with ESP32 Board.