This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI clock stretching

Hello, I am developing custom HAL driver for TWIM in NRF52 (PCA10040). The problem is that after the slave device stretches the clock signal, ninth period on SCL clock is too short (circa 1us instead of 5us). I provide a simple code of sending function below (polling):

i2c.ADDRESS = (deviceAddress >> 1);
i2c.TXD.PTR = reinterpret_cast<uint32_t>(&data);
i2c.TXD.MAXCNT = 1;
eventClear(Event::LASTTX);
eventClear(Event::ERROR);
taskTrigger(Task::STARTTX);
do{
	if(eventCheck(Event::LASTTX)){
		eventClear(Event::LASTTX);
		taskTrigger(Task::STOP);
	}

	if(eventCheck(Event::ERROR)){
		eventClear(Event::ERROR);
		taskTrigger(Task::STOP);
		return getError();
	}

	if(eventCheck(Event::STOPPED)){
		eventClear(Event::STOPPED);
		break;
	}
} while(1);
eventClear(Event::LASTTX);
taskTrigger(Task::STOP);

Is this a hardware dependent or could it be resolved using code workaround? The oscillogram below presents the situation (top SCL, bottom SDA). On SCL line a small step is visible when NRF pulls the line down to generate stop signal. During this time the slave device pulls SDA low. image description

Related