atmel-software-package
atmel-software-package copied to clipboard
TWID bug
I find that when sending a single byte write followed by a multi byte read, that it is failing.
static struct _twi_desc tw = { .addr = FLEXTWI2, .freq = 100000, .slave_addr = CLOCK_BUS_ADDR >> 1, .transfer_mode = BUS_TRANSFER_MODE_POLLING, .timeout = 0}; twid_configure(&tw); struct _buffer buf[] = { { .data = (unsigned char*) "\0\0", .size = 1, .attr = (int) BUS_BUF_ATTR_TX | BUS_I2C_BUF_ATTR_START}, { .data = (unsigned char*) &static_clock_data, .size = sizeof(RTCC), .attr = (int) BUS_BUF_ATTR_RX | BUS_I2C_BUF_ATTR_START | BUS_I2C_BUF_ATTR_STOP } }; twid_transfer(&tw, buf, 2, NULL);
The problem is that the byte sent must be finished before sending the restart. To fix, it appears that in _twid_poll_write it should be
if (size == (buffer->size - 1)) { if (_check_tx_timeout(desc)) return -ETIMEDOUT; twi_write_byte(desc->addr, buffer->data[i]); while(!twi_is_byte_sent(desc->addr));//<<--- Add this line or suggest better }
Hello, Thank you for your report, and thank you for the suggested patch as well. It has been applied as commit 9d1cc85 which is part of the latest Release, v2.15.
Alternatively, one may renew the call to _check_tx_timeout():
if (size == (buffer->size - 1)) {
if (_check_tx_timeout(desc))
return -ETIMEDOUT;
twi_write_byte(desc->addr, buffer->data[i]);
if (_check_tx_timeout(desc))
return -ETIMEDOUT;
}