I2C Slave Mode

dkaufmann
Posts: 11
Joined: Mon Sep 26, 2016 10:02 pm

Re: I2C Slave Mode

Postby dkaufmann » Tue Nov 22, 2016 3:44 pm

Hi Rudi,

i am very interested in these ASM instruction to run the I2C faster. I'd like to run in high speed mode or at least >100kHz.

is this line to read the inputs? how exactly?
_l8ui a0, a11, GPIO_OFFSET_INPUT

"if i delete the debug prints i can go on to 400 KHz with 160 MHz CPU":
the interrupt delay or the GPIO read is too slow. even without debug prints. how do you read/set the GPIO in assembler? in your code I see you use the "normal" GPIO_INPUT_GET function. this is much too slow even with 160MHz. Do you agree? Can you show me how you do it faster?

Thank you

Dominik

User avatar
rudi
Posts: 196
Joined: Fri Oct 24, 2014 7:55 pm
Location: germany
Contact:

Re: I2C Slave Mode

Postby rudi » Sat Nov 26, 2016 5:31 am

dkaufmann wrote:Hi Rudi,

i am very interested in these ASM instruction to run the I2C faster. I'd like to run in high speed mode or at least >100kHz.

is this line to read the inputs? how exactly?
_l8ui a0, a11, GPIO_OFFSET_INPUT



hi dominik

ah you use the code from CNLohr :D
yes, asked you, do you know about this in prev postings..


the thing is not bad, but the 17 cycles is too much too.
CNLohr on esp8266.com wrote: I could respond to interrupt requests in .28 us!


then you know about my state to this too

rudi on esp8266.com wrote:with 80MHz it is 12.5 ns
with 160 MHz it is 6.5 ns ( had measuring on time this by 6.2 ns - see picture )

fastest:
instructions: 4

80 MHz : 12.5ns * 4 = 50 ns
160 MHz : 6.5 ns * 4 = 26 ns ( 6.25 * 4 = 25 ns )

optimated
instructions: 8

80 MHz : 12.5ns * 8 = 100 ns
160 MHz : 6.5 ns * 8 = 52 ns ( 6.25 * 8 = 50 ns )

and does a little be more better as your cool thing with .28 us ( 280 ns )

..

state to high speed usb:
-------------------------------

without DMA and Core 160MHz
without drops - tricks
and with asm blocks

custom Instructions: 6.25ns
bit flow for 1 bit data read:
---------------------------

ISR Fired:
fired 6.25
nop 6.25
clear 6.25
nop 6.25
attach 6.25
nop 6.25


Clock:
low 6.25
nop 6.25
high 6.25
nop 6.25



Data read:
get pin 6.25
nop 6.25
shift pin 6.25
nop 6.25

-----------------------------

14 * 6.5 87.5 ns ( full clock )

87.5 ns * 8 = 700 ns

8 Bit = 0.700 us

1 ms = 1000 * 8 / 0.700 = 11428 Bit / ms

1 s 11428 * 1000 = 11 428 000 Bit/s

11 428 000 Bit/s = 11.428 MBit/s






example:
you can work helped with
"for while (..)"

Code: Select all

static inline unsigned get_ccount(void)
{
        unsigned r;
        asm volatile ("rsr %0, ccount" : "=r"(r));
        return r;
}




backgrounds:

-> http://naberius.de/2015/05/14/esp8266-g ... rformance/
-> viewtopic.php?t=979

the interrupt delay or the GPIO read is too slow. even without debug prints. how do you read/set the GPIO in assembler? in your code I see you use the "normal" GPIO_INPUT_GET function. this is much too slow even with 160MHz. Do you agree?


Yes - there are to much instructions

Can you show me how you do it faster?


using DMA and ticks on 6.5 ns

a good example is done by CNLohr with Broadcast TV and driving WS2812

i am just in time on esp32 CAN theme
perhabs will come back again to this i2c slave theme..

best wishes
rudi ;-)

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

dkaufmann
Posts: 11
Joined: Mon Sep 26, 2016 10:02 pm

Re: I2C Slave Mode

Postby dkaufmann » Tue Nov 29, 2016 8:54 pm

Hi Rudi,

okay. I still have no idea how to enter the interrupt routine faster. If I enter the ISR() on falling edge SDA and measure the SCL line, SCL has already changed to the next state. It is just not a real "interrupt" for me if it takes that long. DMA is no option for a simple I2C slave.

best regards
Dominik

MikeFair

Re: I2C Slave Mode

Postby MikeFair » Wed Nov 30, 2016 7:54 pm

Dominik,

What I noticed about your code is you were using a full blown C function call to request the pin value instead of the ASM call that the examples were using; that "CALL" and "RTN" will add time.

I'm not sure it will help, but I've read that also using the IRAM_ATTR flag is typically considered good practice for fast/short ISRs.

dkaufmann
Posts: 11
Joined: Mon Sep 26, 2016 10:02 pm

Re: I2C Slave Mode

Postby dkaufmann » Thu Jan 05, 2017 4:36 pm

Hi Mike,

yes that's true. But this is depending on the used SDK if this IRAM_ATTR is necessary. As far as I know the IRAM_ATTR is the default for NONOS SDK. if you use RTOS SDK it must be added.

Who is online

Users browsing this forum: No registered users and 1 guest