Skip to content

Commit 13bfd09

Browse files
committed
fix: bytewise read unoq
1 parent d95134f commit 13bfd09

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

examples/unoq/test_i2c/test_i2c.ino

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ void setup() {
141141
// ==================== MAIN LOOP ====================
142142
void loop() {
143143
// Check for incoming I2C data
144-
receiveI2CData();
145144

146145
// Check for serial commands
147146
if (Serial.available()) {
148147
char cmd = Serial.read();
149148
handleCommand(cmd);
149+
receiveI2CData(8);
150150
}
151151

152152
delay(10);
@@ -169,7 +169,7 @@ bool scanForAlvik() {
169169
bool sendI2CData(const uint8_t* data, uint8_t length) {
170170
Wire1.beginTransmission(ALVIK_I2C_ADDRESS);
171171
Wire1.write(data, length);
172-
uint8_t error = Wire1.endTransmission();
172+
uint8_t error = Wire1.endTransmission(false);
173173

174174
if (error == 0) {
175175
stats.packetsSent++;
@@ -189,30 +189,27 @@ bool sendI2CData(const uint8_t* data, uint8_t length) {
189189
/**
190190
* Receive data from Alvik via I2C
191191
*/
192-
void receiveI2CData() {
193-
uint8_t available = Wire1.requestFrom(ALVIK_I2C_ADDRESS, (uint8_t)32);
192+
void receiveI2CData(int size) {
194193

195-
if (available > 0) {
196-
Serial.print("📥 Received ");
197-
Serial.print(available);
198-
Serial.print(" bytes: ");
194+
for (int i = 0; i < size; i++) {
195+
Wire1.requestFrom(ALVIK_I2C_ADDRESS, 1);
196+
197+
if (Wire1.available()) {
198+
Serial.print("📥 Received ");
199199

200-
while (Wire1.available()) {
200+
//while (Wire1.available()) {
201201
uint8_t b = Wire1.read();
202-
rxBuffer[rxIndex++] = b;
203202
Serial.print("0x");
204-
if (b < 16) Serial.print("0");
205203
Serial.print(b, HEX);
206204
Serial.print(" ");
207-
}
208-
Serial.println();
209205

210-
// Try to parse complete packets
211-
parseReceivedData();
206+
Serial.println();
212207

213-
stats.packetsReceived++;
214-
stats.lastResponseTime = millis();
208+
stats.packetsReceived++;
209+
stats.lastResponseTime = millis();
210+
}
215211
}
212+
216213
}
217214

218215
/**

0 commit comments

Comments
 (0)