Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TWID bug #72

Open
friesendrywall opened this issue Jan 29, 2019 · 1 comment
Open

TWID bug #72

friesendrywall opened this issue Jan 29, 2019 · 1 comment

Comments

@friesendrywall
Copy link

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 }

@nirvann
Copy link
Contributor

nirvann commented Feb 4, 2019

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants