request

xod/i2c/request

Requests N bytes from a given slave I²C device. Possible errors: — Invalid I2C address
request
@/request
Requests N bytes from a given slave I²C device. Possible errors: — Invalid I2C address
I2C@/i2c
I2C interface object
ADDRbyte
Slave device I²C address to request from
Nnumber
Number of bytes to request
SENDpulse
Sends the request
request
I2C
ADDR
N
SEND
DONE
DONEpulse
Pulses when the request is successfully send. Send it to a `read-byte`.

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_SEND
#pragma XOD error_raise enable

node {
    void evaluate(Context ctx) {
        if (!isInputDirty<input_SEND>(ctx))
            return;

        auto wire = getValue<input_I2C>(ctx);
        auto addr = (uint8_t)getValue<input_ADDR>(ctx);
        auto nBytes = (uint8_t)getValue<input_N>(ctx);

        if (addr > 127) {
            raiseError(ctx); // Invalid I2C address
            return;
        }

        wire->requestFrom(addr, nBytes);
        emitValue<output_DONE>(ctx, 1);
    }
}