I2C as slave problem (CH32V003F4P6)

Hi,

I’m currently testing I2C on a CH32V003F4P6.
The I2C connection is made between the CH32V003F4P6 and an Arduino Nano. When the CH32V003F4P6 is configured as master and the Nano as slave, I2C communication works.
If the CH32V003F4P6 is configured as slave, the I2C no longer works.
Do you have any idea on how to resolve this issue?

THANKS.

What code are you running on the CH32V003? I2C slave is definitely possible as demonstrated with ch32v003fun.

Hi,

I use the arduino Wire library.

Wire.begin(8);
Wire.onReceive(receiveEvent); 
Wire.onRequest(requestEvent); 

for the slave (CH32) and

Wire.begin();
Wire.beginTransmission(8);
Wire.write("Test");
Wire.endTransmission();

for the master (Nano)

Can you post both firmwares in its entirety?

How do you do deal with

  1. Voltage compatibility: Running CH32 on 3.3V or 5V and Nano on 5V?
  2. I2C pullups? Do you think they’re integrated or did you put external ones?

1 - Running both CH32 and Nano on 5V
2 - With or without a pull-up resistor, the I2C operates (in master mode for the CH32) : due to the line capacitance, the addition of pull-up resistors still improves the quality of the signals).

Code that works → CH32 as master / Nano as slave

Master : CH32

#include <Arduino.h>
#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(115200);
  delay(1000);
}

void loop() {
  Wire.beginTransmission(8);
  Wire.write("T");
  Wire.endTransmission();
  delay(1000);
}

Slave : Nano

#include <Arduino.h>
#include <Wire.h>

bool zeroFlag = false;
void receiveEvent(int howMany) 
{
  while (0 < Wire.available()) 
  {
    char c = Wire.read();      
    Serial.print(c);          
  }
  Serial.println();             
}
void requestEvent() 
{
  Wire.write("R");  
}

void setup() 
{
    Wire.begin(8);
    Wire.onReceive(receiveEvent); 
    Wire.onRequest(requestEvent); 
    Serial.begin(115200);
    delay(500);
 }

void loop() {         
}

If I swap the code (Master code on Nano and slave code on CH32 ) it doesn’t work.

I just saw that there is an issue (I2C Slave Support #51) on openwch.

The slave mode is probably not implemented …

Yep, not implemented, that will be it. The code is deceiving, in lots of places there seem to be provisions for slave mode, but it does not seem to be completed. Unless you want to get into the knitty-gritty of adding the missing code, I’d recommend using the ch32v003 project for the I2C slave. This is a much lower level abstraction though, so sometimes you’ll have to get dirty with register writes.

Thank you Max for your time on this topic.I hope an update to the Arduino implementation soon …