Pages: [1]   Go Down
Author Topic: Does I2C send and receive in background ?  (Read 488 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
A little question : does someone know if the I2C write function only in the outgoing buffer and then the data is send in background while the program runs, or does the program stop until the data is send ?
I hope my question is clear...
Thank you smiley

PS : because I'm thinking about making a huge led matrix made of little 8*8 matrix driven by atmega8 modules. And I dont want the main µC to loose time sending data to atmega8. I found something to put I2C at 400kHz instead of 100kHz to make things go faster, too.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino is a single-threaded processor. There is no "background". I hope that answers your question.
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And you can only send 32 bytes every time you send data. if you have like 120 bytes to send, you'll have to send it in parts.
Logged


Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The hardware is sending one byte without disrupting the main code. The an interupt "asks" for the next byte. The library is responsible for buffering up to 32 bytes of data, which is then sent using this "mechanism".
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A little question : does someone know if the I2C write function only in the outgoing buffer and then the data is send in background while the program runs, or does the program stop until the data is send ?

If you are referring to Wire.endTransmission that blocks (waits) until the buffer is sent, if that answers your question.

Wire.send (now called Wire.write) doesn't wait, nor does it do any sending.

You could rewrite it to be non-blocking, someone may have done that already.

Quote
The Arduino is a single-threaded processor. There is no "background". I hope that answers your question.

But it can receive serial data asynchronously, because the USART has a buffer. I think the TwoWire interface must have at least a single-byte buffer, maybe more (hard to find that bit in the datasheet).

It can also send "in the background". According to the datasheet page 223:

Quote
Because the TWI is interrupt-based, the application software is free to carry on other operations during a TWI byte transfer.
Logged

Pages: [1]   Go Up
Jump to: