-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
I2C Slave - onRequest called for all I2C slave addresses #5907
Labels
Comments
can you provide minimal code that shows how you setup the Slave? What device is the master? |
Sure. I was using a Total Phase Aardvark for my master. #include "Wire.h"
#include "pins_arduino.h"
#define I2C_DEV_ADDR 0x40
char regs[256] = "0";
int LED_BUILTIN = 2;
uint32_t i = 0;
char readVal = '0';
int dataReady = 0;
char counter = 0;
void onRequest()
{
char buffer[30];
if(dataReady == 1)
{
sprintf(buffer,"Sending %x",readVal);
Serial.println(buffer);
counter = counter + 1;
dataReady = 0;
}
else
{
sprintf(buffer,"Called but no data to send");
Serial.println(buffer);
}
}
void onReceive(int len)
{
char result[255];
int address;
char data;
Serial.printf("onReceive[%d]: ", len);
address = Wire.read();
// Read Register
if(len == 1)
{
sprintf(result,"Address 0x%x contains 0x%x",address,regs[address]);
Serial.write(result);
readVal = regs[address];
dataReady = 1;
Wire.write(readVal);
}
// Write Register
else if(len == 2)
{
data = Wire.read();
regs[address] = data;
sprintf(result,"Set Address 0x%x to 0x%x",address,data);
Serial.write(result);
}
// Length doesn't match expected
else
{
while(Wire.available())
{
Serial.println("Error with length! ");
sprintf(result," 0x%x",Wire.read());
Serial.write(result);
}
}
Serial.println();
}
void setup()
{
Serial.begin(115200);
Serial.setDebugOutput(true);
// Setup I2C request / recieve
Wire.onReceive(onReceive);
Wire.onRequest(onRequest);
// Start I2C
Wire.begin((uint8_t)I2C_DEV_ADDR);
// Configure LED
pinMode (LED_BUILTIN, OUTPUT);
}
void loop()
{
// Blink LED once a second for heartbeat
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
} |
Hello, can you please help with testing this on 2.0.3-rc1? |
VojtechBartoska
added
the
Resolution: Awaiting response
Waiting for response of author
label
Apr 8, 2022
me-no-dev
added a commit
that referenced
this issue
Apr 27, 2022
Repository owner
moved this from Todo
to Done
in Arduino ESP32 Core Project Roadmap
Apr 27, 2022
me-no-dev
added a commit
that referenced
this issue
Apr 27, 2022
VojtechBartoska
added
Status: Solved
and removed
Status: Test needed
Issue needs testing
Resolution: Awaiting response
Waiting for response of author
labels
Apr 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hardware:
Board: Teyleten Robot ESP32S ESP32 ESP-WROOM-32
Core Installation version: 2.0.1
IDE name: Arduino IDE
Flash Frequency: N/A
PSRAM enabled: N/A
Upload Speed: 115200
Computer OS: Windows 10
Description:
When an I2C master issues a read request from a slave onRequest gets called even if the device in question was not the target slave.
The text was updated successfully, but these errors were encountered: