# RTL8720DN as I2C slave

**URL:** <https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407>\
**Category:** Peripherals\
**Tags:** evb-bw16, rtl872xd\
**Created:** [March 30, 2021, 8:00am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407 "2021-03-30T08:00:04Z")\
**Posts on this page:** 13\
**Page:** 2

<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 18, 2022, 6:02am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/21 "2022-05-18T06:02:15Z")

</div>

Thanks for your contribution, we will review the PR and merge it once review is completed

---

<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:** [June 15, 2022, 10:24am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/22 "2022-06-15T10:24:50Z")

</div>

Hi @xsutter

Can I check if you are still using the Arduino Wire lib (ameba edition) for the slave tx and rx or have switch completely to using the APIs available in `i2c_api.c` and `rtl8721d_i2c.c` ?

Thanks!  
Simon

---

<div class="post-metadata">

**Author:** ![xsutter](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/xsutter/32/565_2.png) [@xsutter](https://forum.amebaiot.com/u/xsutter)\
**Post date:** [June 15, 2022, 3:12pm UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/23 "2022-06-15T15:12:14Z")

</div>

Hi Simon,  
Nice to read you !

I do not use the Arduino Wire lib at all, since the `Wire.onReceive` and `Wire.onRequest` callbacks never get called. I do not even `#include "Wire.h"` . I just `#include "i2c_api.h"` and use the Mbed and raw APIs, to my complete satisfaction.

As you already know, the current release of the Arduino SDK still contains a buggy `I2C_SlaveWrite()`. I [filed an issue on this](https://github.com/ambiot/ambd_arduino/issues/81). In the meantime I am using a private, corrected version of `I2C_SlaveWrite()` which now resides permanently in my code.

Cheers,  
Xavier

---

<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:** [June 16, 2022, 1:56am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/24 "2022-06-16T01:56:57Z")

</div>

> [@xsutter](#):
>
> I do not use the Arduino Wire lib at all, since the `Wire.onReceive` and `Wire.onRequest` callbacks never get called. I do not even `#include "Wire.h"` . I just `#include "i2c_api.h"` and use the Mbed and raw APIs, to my complete satisfaction.

Nice to hear you back and good to know that the I2C works fine in your setting.

The reason why I asked is because we are planning to support the

> [@xsutter](#):
>
> `Wire.onReceive` and `Wire.onRequest` callbacks

in the `Wire` libraries since it has been requested many times and I am wondering if you would like to test it once it’s done so we can confirm that I2C slave works in the interrupt mode under user’s code?

---

<div class="post-metadata">

**Author:** ![xsutter](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/xsutter/32/565_2.png) [@xsutter](https://forum.amebaiot.com/u/xsutter)\
**Post date:** [June 16, 2022, 2:16pm UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/25 "2022-06-16T14:16:30Z")

</div>

Yes, I can adapt my application to serve as a test support, this should not take too much time. Tell me when the new Wire is ready!

However unless we observe a definite performance advantage in using the Wire library, we will likely stick with the underlying Mbed API in our final product. This is in the hope that a VSCode Ameba SDK will eventually emerge, which would allow us to unify our development environment and get rid of the uncomfortable Arduino toolset completely.

---

<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:** [June 17, 2022, 2:15am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/26 "2022-06-17T02:15:24Z")

</div>

> [@xsutter](#):
>
> Tell me when the new Wire is ready!

Thanks! it shoud not take long~

> [@xsutter](#):
>
> This is in the hope that a VSCode Ameba SDK will eventually emerge,

So your dev env has been with VSCode? As far as I know, Ameba SDK usually stick to either GCC-Make/CMake env (which can be embedded into any IDE actually) or IAR env.

If VSCode is what you prefer, maybe a simple extension that integrate some core make command is all it takes.

---

<div class="post-metadata">

**Author:** ![xsutter](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/xsutter/32/565_2.png) [@xsutter](https://forum.amebaiot.com/u/xsutter)\
**Post date:** [June 17, 2022, 1:57pm UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/27 "2022-06-17T13:57:33Z")

</div>

Actually our project is built around 2 processors: ESP32 for the main application, plus RTL8720 BW16 as a 5GHz wifi peripheral. We use SPI + I2C to link both.

We use VSCode + PlatformIO + esp-idf for our our main development on ESP32, which is extremely comfortable. We wish we could do the same for RTL8720, but unfortunately at the time being we have no choice but use the Arduino environment, which is prehistoric in comparison. We do not have the resource to attempt porting the Ameba SDK to PlatformIO, nor to adapt PIO’s upload tool to the BW16. We just hope someone will do that some day…

---

<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:** [June 20, 2022, 1:39am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/28 "2022-06-20T01:39:53Z")

</div>

PlatformIO has been requested many times too and it has been discussed internally and externally with the PlatformIO team. However, the PlatformIO team seem reluctant to help porting the Ameba SDK to their build system so this has to be put on pending for now.

---

<div class="post-metadata">

**Author:** ![luke](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@luke](https://forum.amebaiot.com/u/luke)\
**Post date:** [September 27, 2022, 1:23am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/29 "2022-09-27T01:23:52Z")

</div>

Hello, @xidameng .

> [@xidameng](#):
>
> Thanks! it shoud not take long~

I was wondering on the status of this development? I noticed the latest commit for `ambd_arduino/Arduino_package/hardware/libraries/Wire/examples/SlaveWriter/SlaveWriter.ino` was Jul 28 which leads me to believe this is the updated version. However, using this example has not provided the expected function when using the corresponding Master program.

Best,

Luke

---

<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:** [September 27, 2022, 2:49am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/30 "2022-09-27T02:49:44Z")

</div>

Hi @luke I2C Slave has been implemented and added to Arduino SDK since last release [[Release] Ameba Arduino SDK Official Release](https://forum.amebaiot.com/t/release-ameba-arduino-sdk-official-release/630) about 8 days ago.

If you run the I2C slave example provided with another I2C master, you should see I2C slave device sending/receiving data

---

<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:** [September 27, 2022, 3:03am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/31 "2022-09-27T03:03:34Z")

</div>

> [@luke](#):
>
> using this example has not provided the expected function when using the corresponding Master program.

could you elaborate on your settings?

You can refer to this [example guide](https://www.amebaiot.com/en/amebad-arduino-i2c-5/) for detailed steps and demo

---

<div class="post-metadata">

**Author:** ![luke](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@luke](https://forum.amebaiot.com/u/luke)\
**Post date:** [September 27, 2022, 3:13am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/32 "2022-09-27T03:13:08Z")

</div>

Apologies for resurrecting the thread, it was as simple as updating through Arduino’s Board Manager. I was still working under version 3.1.3 and now using 3.1.4 and it works fine.

Thank you for your timely response. I appreciate you and this communication medium setup between users and developers.

---

<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:** [September 27, 2022, 6:33am UTC](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407/33 "2022-09-27T06:33:54Z")

</div>

No problem luke, happy coding~ 😄

[Previous page](https://forum.amebaiot.com/t/rtl8720dn-as-i2c-slave/407.md?page=1)
