[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

I2C ACK/NACK



In the I2C driver, there is a i2c_sendack(), but there is no i2c_sendnack().

I2C devices I've seen so far all require the master to NACK the last byte in a 
register read command.

However, the i2c_readreg() function does ACK the last received byte.
I've grepped for this function, to see who uses it, and it turns out only 
pcf8563.c is using it at the moment.

And in the pcf8564 datasheet, it says that a NACK is required after the last 
byte read, just before the stop condition.

So I've added the following function to i2c.c:

void
i2c_sendnack(void)
{
	/*
	 * enable output
	 */
	i2c_delay(CLOCK_LOW_TIME);
	i2c_dir_out();

	/*
	 * generate clock pulse
	 */
	i2c_delay(CLOCK_HIGH_TIME/6);
	i2c_clk(I2C_CLOCK_HIGH);
	i2c_delay(CLOCK_HIGH_TIME);
	i2c_clk(I2C_CLOCK_LOW);

	i2c_delay(CLOCK_LOW_TIME);

	i2c_dir_in();
}

And changed i2c_readreg's last 'i2c_sendack()' into a 'i2c_sendnack()'


Best regards,

Pieter