# RTL8720DN I2C Slave Code

**URL:** <https://forum.amebaiot.com/t/rtl8720dn-i2c-slave-code/1266>\
**Category:** Peripherals\
**Tags:** evb-bw16, rtl872xd\
**Created:** [May 23, 2022, 2:55am UTC](https://forum.amebaiot.com/t/rtl8720dn-i2c-slave-code/1266 "2022-05-23T02:55:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaner3](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/shaner3/32/1064_2.png) [@Shaner3](https://forum.amebaiot.com/u/Shaner3)\
**Post date:** [May 23, 2022, 2:55am UTC](https://forum.amebaiot.com/t/rtl8720dn-i2c-slave-code/1266/1 "2022-05-23T02:55:31Z")

</div>

Hi

I am having the issue where the receiveEvent function is not being called. I have replaced the default Arduino i2c library files with the Amebad files. So I don’t understand why the code doesn’t facilitate I2C communication.

```auto
#include "Wire.h"                              

byte I2C_OnOff; //defining the variable that will be sent

void setup() 
{
  Serial.begin(115200);
  Wire.begin(0x3a); // Join I2C bus as the slave 
}

void loop() 
{
   Serial.println("Check if Received....");
   Wire.onReceive(receiveEvent);
   delay(1000);
}

void receiveEvent(int Press)
{
  Serial.println("Received!!");
  I2C_OnOff = Wire.read(); // Reads the data sent via I2C 
}

```

Thanks

---

<div class="post-metadata">

**Author:** ![xidameng](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/xidameng/32/18_2.png) [@xidameng](https://forum.amebaiot.com/u/xidameng)\
**Post date:** [May 23, 2022, 7:56am UTC](https://forum.amebaiot.com/t/rtl8720dn-i2c-slave-code/1266/2 "2022-05-23T07:56:14Z")

</div>

Hi which RTL8720DN board are you using? have you upgraded your arduino ameba package to the latest?

---

<div class="post-metadata">

**Author:** ![Shaner3](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/shaner3/32/1064_2.png) [@Shaner3](https://forum.amebaiot.com/u/Shaner3)\
**Post date:** [May 23, 2022, 8:28pm UTC](https://forum.amebaiot.com/t/rtl8720dn-i2c-slave-code/1266/3 "2022-05-23T20:28:26Z")

</div>

Hi,

I am using the BW16 board and I do have the latest arduino ameba package.

Thanks

---

<div class="post-metadata">

**Author:** ![xidameng](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/xidameng/32/18_2.png) [@xidameng](https://forum.amebaiot.com/u/xidameng)\
**Post date:** [May 25, 2022, 3:24am UTC](https://forum.amebaiot.com/t/rtl8720dn-i2c-slave-code/1266/4 "2022-05-25T03:24:21Z")

</div>

Hi @Shaner3

Both `onReceive` and `onRequest` functions are NOT implemented, thus they do not work as of yet.

Though I2C slave is supported on the selected pins, software functions are only meant for **Master mode** , thus I2C slave might not work at all.

You may consider submit an ISSUE under Github repo to request for such feature to be added later.

> **[Issues · ambiot/ambd\_arduino](https://github.com/ambiot/ambd_arduino/issues)**
>
> AmebaD Arduino third-party package SDK. Contribute to ambiot/ambd\_arduino development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![xidameng](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/xidameng/32/18_2.png) [@xidameng](https://forum.amebaiot.com/u/xidameng)\
**Post date:** [May 25, 2022, 3:45am UTC](https://forum.amebaiot.com/t/rtl8720dn-i2c-slave-code/1266/5 "2022-05-25T03:45:07Z")

</div>

Alternatively, you may try to use API directly from the BSP (more specifically the `i2c_api.h`) which give you full control of I2C peripheral, more detailes can be found in this thread

> [@RTL8720DN as I2C slave](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/2):
>
> hi Tim, afaik, arduino also only uses i2c in master mode do you mind elaborate?
