-
Notifications
You must be signed in to change notification settings - Fork 7
i2c_request
gicking edited this page Feb 10, 2018
·
5 revisions
back to Command Reference / I2C
Request data from an I2C slave via pins SCL
and SDA
. Before the request, a start condition must
be generated by i2c_start(). The transmission is terminated by a stop condition, which
is generated via i2c_stop().
- defined in
i2c.h
-
not loaded by
main_general.h
- for custom I2C interrupts set set
#define USE_I2C_ISR
inconfig.h
. The corresponding interrupt function name isI2C_ISR
Warning: test with Arduino example "Wire/slave sender" failed. Likely this routine is buggy!
i2c_request(addr,num,buf)
-
input:
- addr: I2C address of slave to get data from (uint8_t)
- num: number of bytes to receive (uint8_t)
-
output:
- buf: buffer for received data (uint8_t array)
- 0: acknowledge received, 1: timeout occurred
The below function periodically reads data from an Arduino configured as I2C slave using example "Wire/slave sender".
#include "i2c.h"
#define ADDR_I2C 8
#define NUM_I2C 6
setup() {
...
i2c_init();
...
}
loop() {
uint8_t buf[NUM_I2C]
...
i2c_start();
i2c_request(ADDR_I2C,NUM_I2C,buf);
i2c_stop();
...
}
To avoid damage
- do not expose I/Os to voltages outside [-0.3V; Vdd+0.3V], else limit injection currents to the specificied limits
- for
OUTPUT
pins assert that sink and source currents are below the specificied limits - do not directly connect two
OUTPUT
pins. If e.g. half-duplex is required, use a pull-up andOUTPUT_OPENDRAIN
, instead
-
Getting Started
-
- General Commands
- Libraries
- LCD BTHQ21605V
- poti AD5280
- poti AD5282
- freemodbus
- PetitFS SD-card (min)
- FatFS: SD card (full)
- Board Specific
-
- Universal
- Board Specific