-
Notifications
You must be signed in to change notification settings - Fork 7.6k
I2C Slave Request Interrupt triggered before Receive interrupt #8545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
van you please also provide a basic master side of code? |
Hi,
With the data in the buffer being read out to be forwarded over serial like so:
|
Please go through this issue. I think you have to send stop before request as of now, |
Hi AAJAYS, Thanks for your reply, however it does not solve anything because of two things:
Therefore as things stand there is nothing else we can do? |
Try to implement ESP-IDF I2C slave device. I think this might be helpful
|
Hi AAJAYS, I have copied and pasted your code and compile on PlatformIO using ESP-IDF 5.1.0. First off I had to replace your line:
with
Otherwise the ESP32 is stuck rebooting because the buffer size is too small. Following that correction I sent out a Write followed Read request with a RESTART condition in the middle. However the same issue happens: |
This is the error text I get when driver install is called with buffer sizes equal to zero:
|
|
This code is also valid. Because on master code ArduinoUno= I2C master. |
Hi AAJAY, Unfortunately I can only have access to the MASTER on the test bench - but on the field the master is completely beyond my control. Therefore the slave MUST work well without any intervention on the master. On the other hand I do not understand what I need to do with the above code. Thanks and regards, |
You can give try with this slave code. Where #include <Arduino.h>
#include <Wire.h>
#include "driver/i2c.h"
void i2c_slave_task(void *param) {
i2c_config_t conf;
conf.mode = I2C_MODE_SLAVE;
conf.sda_io_num = SDA; // Replace with the GPIO pin number for SDA
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_io_num = SCL; // Replace with the GPIO pin number for SCL
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.slave.addr_10bit_en = 0;
conf.slave.slave_addr = 0x55;
i2c_param_config(I2C_NUM_0, &conf);
i2c_driver_install(I2C_NUM_0, conf.mode,
128, 128, 0);
uint8_t counter = 0;
uint8_t recv_buff[128];
while (1) {
int len = i2c_slave_read_buffer(I2C_NUM_0, recv_buff, 1, portMAX_DELAY);
if (len) {
// This is your onRecive();
// Load data you want to send onRequest()
i2c_slave_write_buffer(I2C_NUM_0, &counter, 1, portMAX_DELAY);
counter++;
Serial.printf("Recv Len: %u\r\n Data:\r\n", len);
for (int i = 0; i < len; i++) {
Serial.printf("%02X ", recv_buff[i]);
if ((i + 1) % 8 == 0) Serial.println();
}
}
}
vTaskDelete(NULL);
}
void setup() {
Serial.begin(115200);
xTaskCreate(i2c_slave_task, "i2c_slave_task", 2048, NULL, 0, NULL);
}
void loop() {
}``` |
@AndreCilia Were you able to get the I2C slave working? |
Simple answer is no. |
This issue is still pending with no end in sight for an official solution. However there is a temporary solution available which works on the ESP-IDF platform. You can access it here: |
Hello, Due to the overwhelming volume of issues currently being addressed, we have decided to close the previously received tickets. If you still require assistance or if the issue persists, please don't hesitate to reopen the ticket. Thanks. |
Board
ESP32-S3
Device Description
I have a custom ESP32-S3 board based on the ESP32-S3-DevKitC-1 development board that I am programming using PlatformIO with the Arduino framework.
The Arduino Framework has version 2.0.11, the ESP-IDF has version 4.5.0.
The ESP32-S3 is connected to an SMBus Master which can be any SMBus compatible device but in testing stage I am using a custom programmed Arduino board.
Hardware Configuration
SDA - GPIO 1
SCL - GPIO 2
Application is running BLE, Wire1 as an I2C master, a couple of LED's driven by separate transistors
Version
v2.0.11
IDE Name
VS Code
Operating System
Windows 10
Flash frequency
40MHz
PSRAM enabled
no
Upload speed
115200
Description
I need an I2C slave function to act as an SMBus slave.
Howevern when I am sending a Write followed by a RESTART condition and a Read request, the Request interrupt is triggered BEFORE the Receive interrupt, thus not giving me time to process which data is being requested and buffering it.
Following is the code setting up the I2C slave:
Wire.begin(0xb, SLAVE_SDA, SLAVE_SCL, 100000UL); Wire.onReceive(_onReceive); Wire.onRequest(_onRequest);
with the interrupts being handled as follows:
`void _onRequest()
{
Serial.println("Request Rx");
}
void _onReceive(int len)
{
Serial.print("Receive: ");
Serial.print(len);
Serial.println("bytes");
}`
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: