Skip to content

Strange behavior in TwoWire in Slave Mode #2937

Closed

Description

@camelator

Describe the bug
it looks like not possible to directly use TwoWire in slave mode. in this case the rxbuffer is never fill.
There is a différence in having an empty user receive handler and not having a receive handler. In the first case rxbuffer is fill correctly in the second case it is not fill.

Having:
TwoWire myI2C(PB7, PB6);
setup:
myI2C.begin(0x18) ;
in this case myI2C.available() is never > 0.

to have myI2C.available() > 0 when a message is received you must have implemented:
myI2C.onReceive(onReceiveHandler);

onReceiveHandler may be an empty code {}

in this situation TwoWire works correctly.

To Reproduce
TwoWire myI2C(PB7, PB6);
setup:
myI2C.begin(0x18) ;
loop:

if (myI2C.available()>0)
{
...
}

to make the program works:

setup:

myI2C.begin(0x18) ;
myI2C.onReceive(onReceiveHandler);


void onReceiveHandler(int howMany) {
  }

Activity

  1. fpistm commented on Mar 23, 2026

    @fpistm
    Member

    Hi @camelator
    I don't see the issue you have to provide the receive handler/event function.
    https://docs.arduino.cc/language-reference/en/functions/communication/wire/onReceive/

    You can also see the example:

    Wire.onReceive(receiveEvent); // register event

  2. locked and limited conversation to collaborators on Mar 25, 2026
  3. converted this issue into a discussion #2944 on Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions