Can an ODROID be a slave in I2C?

Post Reply
alone1224
Posts: 9
Joined: Wed Jul 15, 2015 8:50 pm
languages_spoken: Korean
ODROIDs: C4
Has thanked: 1 time
Been thanked: 0
Contact:

Can an ODROID be a slave in I2C?

Post by alone1224 »

Hello.

I'm writing code for an Odroid and an Arduino Nano Every to communicate I2C.

In my case, data flows from the Arduino to the Odroid, and more importantly, the Arduino decides when to send data.
So it seems like it would be efficient to have the Arduino act as the master and the Odroid as the slave.

I've Googled around and found a few examples of I2C communication using Wiring pi or the Python smbus module, but all the examples I've found have the Odroid acting as the master.

Is it possible for the Odroid to act as a slave in I2C communication?
If it is possible, I would appreciate if you could share some references.

(I also found a workaround that uses interrupts to tell the Odroid when to request data, but that doesn't seem to be suitable since the Arduino is already handling multiple hardware interrupts.)

User avatar
mctom
Posts: 3236
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: OGA, XU4, M1, H3+, SP3, Vu8M, N2L
Location: Gdansk, Poland
Has thanked: 436 times
Been thanked: 590 times
Contact:

Re: Can an ODROID be a slave in I2C?

Post by mctom »

Hi,

Let me begin with an unfounded declaration that yes, it may be done, somehow.
I cannot tell if hardware I2C in your ODROID (I assume XU3?) can be a slave, but I2C slave is generally a relatively easy thing to implement directly on GPIO, without using special I2C peripheral.
Don't get me wrong, it may cost you another 10-100h, depending on your skills.

Assigning which device is Master and which is Slave rarely depends on your criterion of who is to initiate the transfer. Instead, the real question is who should be in charge if you add another I2C device to your system in the future.
If you still think ODROID board should be a slave, the next question is: Does it even have to be I2C in the first place? I would use UART in this scenario. It is faster and bidirectional, does not have master or slave, but is not a bus (meaning you won't be able to add more devices to it in the future). Then either device can talk whenever it feels like talking.

Your "workaround" is in fact a recognized, proper way of dealing with your situation. HID over I2C, a standard for connecting computer peripherals like keyboard or mouse via I2C, specifies exactly "HID device" as a bus slave, and an extra GPIO line for letting the Master know it has something to say.
This extra line does not need to be handled by interrupt on Arduino side, it's just a simple GPIO that sets itself to 1 when Arduino want to send data, and back to "0" when Arduino does not want to send data anymore. It's as simple as that and certainly possible if your Arduino has one digital pin to spare.
On ODROID side, this line can be polled (repeatedly checked every 100ms or so), or you could handle an actual interrupt, but I don't think it's worth a hassle.

To wrap this up, the knowledge of turning ODROID (or any other SBC) into I2C Slave isn't widespread because there are extremely few cases when anyone needs it.
These users thanked the author mctom for the post:
alone1224 (Mon Sep 18, 2023 12:11 am)
Punk ain't no religious cult, punk means thinking for yourself!
OpenUPS
PiStackMon

alone1224
Posts: 9
Joined: Wed Jul 15, 2015 8:50 pm
languages_spoken: Korean
ODROIDs: C4
Has thanked: 1 time
Been thanked: 0
Contact:

Re: Can an ODROID be a slave in I2C?

Post by alone1224 »

Dear mctom,

I appreciate your extensive advice.

I'm just a so-so application developer, and there's a lot I don't know in this world.
(I even knew the Arduino's UART communication rate was also limited to 115200 bps).

You've made me rethink my current overall scheme,
and I've also learned that the Odroid can act as a slave if absolutely necessary.
(Although it will take tons of hours for me.)

I am deeply grateful for your kindness.

User avatar
mctom
Posts: 3236
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: OGA, XU4, M1, H3+, SP3, Vu8M, N2L
Location: Gdansk, Poland
Has thanked: 436 times
Been thanked: 590 times
Contact:

Re: Can an ODROID be a slave in I2C?

Post by mctom »

Don't mention it, I'm quite passionate about sharing my humble knowledge.

115200 kbps is faster than Standard Mode I2C anyway, and ATmega surely can work with higher baud rates than that, such as 1MHz.
However I'm not sure how Arduino handles that. I see Arduino as a completely unnecessary layer of abstraction that limits features of the underlying microcontroller.

Just out of curiosity, what is the nature of data you wish to exchange between these two boards?
Punk ain't no religious cult, punk means thinking for yourself!
OpenUPS
PiStackMon

Sebas_Ledesma
Posts: 276
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 54 times
Been thanked: 24 times
Contact:

Re: Can an ODROID be a slave in I2C?

Post by Sebas_Ledesma »

Around 7 years ago we needed I2c working as SLAVE on Odroid C2. We maked some studies and did some modifications to the drivers but finally we opted to put a microchip as bridge I2c-RS232 (and the Odroid now communicates using RS232 to the I2c Master).
By that time there was announced the implementation of I2c slave for Linux ( https://elinux.org/images/f/f6/ELCE15-W ... mework.pdf ) but the kernel included in C2 was 3.1x and that functions were available in newer kernel.
Even in the upcoming product (wich uses Odroid c4) we keep the bridge as that solution allowed to save development time.

User avatar
odroid
Site Admin
Posts: 41542
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 3321 times
Been thanked: 1836 times
Contact:

Re: Can an ODROID be a slave in I2C?

Post by odroid »

Sebas_Ledesma wrote:
Wed Sep 27, 2023 6:38 am
By that time there was announced the implementation of I2c slave for Linux ( https://elinux.org/images/f/f6/ELCE15-W ... mework.pdf ) but the kernel included in C2 was 3.1x and that functions were available in newer kernel.
Very interesting. Thank you for sharing the document.

I've searched about the slave driver implementation little bit in tobetter's C4 Kernel 6.1 source tree.
There seem to be 2 layers of drivers: backend-driver and bus-driver to implement the slave mode.
One backend-driver example i2c-slave-eeprom.c which emulates an EEPROM.
But the bus-driver seems to require that the SoC I2C controller must support a slave mode natively.
Unfortunately, Amlogic SoC I2C controller doesn't support a slave mode as far as I searched S905X3 datasheet as well as meson-i2c driver source code.
Perhaps, if we use a GPIO bit-bang software I2C, there can be chance to use the slave mode. But I am not sure if it is worth to try or not.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 1 guest