Arm Mbed OS support forum

I2Cslave functions are buggy [5.15.5] [FRDM-KL82Z]

Hi there,

following issues when running Mbed OS 5.15.5 on a FRDM-KL82Z and an Aardvark as the Master. also takes the slave address and stores it.
I.E. *)Hashed_Data, 10);
Hashed_Data[0] holds the slave address instead of the first data byte, which can be seen on Master side when using
slave.write((char *)Hashed_Data, 100);

Also requesting a write to Master, every other transfer fails.

#include "MKL82Z7.h"
#include "PinNames.h"
#include "mbed.h"

volatile int g_I2C_operation, g_I2C_status;
unsigned char Hashed_Data[100] = {0};

const char message[] = "Slave!";
I2CSlave slave(I2C_SDA, I2C_SCL);

int main() {
printf("Start \n\r");
while (1) {

g_I2C_operation = slave.receive();

switch (g_I2C_operation) {
case I2CSlave::WriteAddressed:
  g_I2C_status = *)Hashed_Data, 10);
  printf("%d", g_I2C_status);
case I2CSlave::ReadAddressed:
  g_I2C_status = slave.write((char *)Hashed_Data, 100);
  printf("%d", g_I2C_status);

this is just an example, the actual project is using Hashed_Data[65000] but I don’t see this working properly anytime soon.

after talking with some colleagues, it seems reading address is common for some IPs, I wasn’t used to that yet.
In terms of every other Master-Read transfer hanging, there’s a low-level issue regarding error handling, i.e. when the Master requests more bytes than the Slave expects to writ, slave I2C starts to hang, eventually leading to a hardfault.
The top level workaround was easy (simple statemachine on master and slave side), but I believe someone should look into that nonetheless.

Next issue, why is there a 11.2ms clock-stretch after finished slave.write() regardless of message length?
I have tried this with several Master devices now, and don’t see a workaround.

Excuse me, but this is madness.