Skip to content

aliher1911/arduino-tasker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

arduino-tasker

AsyncWire

Replacement for Wire to allow async communication.

Init I2C in master mode, call once in setup to init library and underlying transport.

wire.init();

Sending data

To start communication operation:

wire.begin(address);

Then if using external buffer use:

wire.addSend(data, lenght);

If using preallocated internal buffer of 8 bytes:

wire.addSend(byte);

could be called multiple times to fill packet.

When packet is ready:

wire.doAsync();

intiate communication (will only succeed if no operation is in progress)

after that do

while(!wire.isReady()) {
    // wait for operation to complete
}

to check result of operation after wire is ready

wire.getStatus();

will return 0 if operation was successfull

Receiving data

To start communication operation:

wire.begin(address);

Then if using external buffer

wire.addReceive(buffer, length);

If using preallocated internal buffer of 8 bytes:

wire.addReceive(length);

Once parameters are set call

wire.doAsync();

to initiate communication. Follow send pattern after that.

To read received data byte by byte from buffer:

while(wire.available()) {
    wire.getNextByte();
}

Send and Receive data

Setup send and receive and then initiate communication. You only wire.begin() once.

Synchronous mode

If sync operation is needed, then method

wire.doSync();

will initiate communication and wait till it is complete (send, receive or both)

Shortcuts

Methods send and read with multiple flavours will setup communication according to arguments and perform synchronous op. Handy when short exchanges are needed with fixed 1-2 byte packets.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published