I need faster communication between the ESP and the ADC, so I found this https://github.com/pasko-zh/brzo_i2c.
Original wire Example
#include "Wire.h"
#define PCF8591 0x48
byte a0;
void setup() {
Wire.begin(13, 14);
Serial.begin(115200);
}
void loop() {
Wire.beginTransmission(PCF8591);
Wire.write(0x04);
Wire.endTransmission();
Wire.requestFrom(PCF8591, 5);
a0 = Wire.read();
a0 = Wire.read();
Serial.println(a0);
delay(1000);
}
Brzo I2C example
#include "brzo_i2c.h"
uint8_t buffer[10];
uint8_t error = 0;
float temp = 0.0;
uint8_t ICACHE_RAM_ATTR get_temp(float *t) {
uint8_t bcode = 0;
brzo_i2c_start_transaction(0x48, 400);
buffer[0] = 0x04;
brzo_i2c_write(buffer, 1, false);
brzo_i2c_read(buffer, 2, false);
bcode = brzo_i2c_end_transaction();
*t = ((buffer[0] << 8) | buffer[1]);
return bcode;
}
void setup() {
delay(500);
Serial.begin(115200);
brzo_i2c_setup(13, 14, 2000);
}
void loop() {
error = get_temp(&temp);
if (error == 0) {
Serial.print("Temp = ");
Serial.println(temp, 8);
} else {
Serial.print("Brzo error : ");
Serial.println(error);
}
delay(500);
}
But I get always the same error.
1 : Bus not free
I rewrote it in different ways, changing the frequency, pins and doing multiple transactions. The main reason I don't get it to work is the difference in the API.
There is no Wire.requestFrom();
in the brzo_i2c lib. So I need to read the value with brzo_i2c_read(buffer,2,false);
.