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

This implementation conflicts with SMBus specification #139

Open
tamebits opened this issue Aug 22, 2024 · 1 comment
Open

This implementation conflicts with SMBus specification #139

tamebits opened this issue Aug 22, 2024 · 1 comment

Comments

@tamebits
Copy link

Today I ran into an issue while implementing a PMBus interface on an Arduino every.
PMBus derrives from SMBus which uses I2C and ultimately TWI.

From System Management Bus Specification Version 3.3:

image

This requires a 0 byte read or write transaction where the read is currently not possible with this implementation as the write bit is implicitly set in both cases.

Both cases result in a call to

uint8_t TWI_MasterWriteRead(uint8_t slave_address,
                         uint8_t *write_data,
                         uint8_t bytes_to_write,
                         uint8_t bytes_to_read,
						 uint8_t send_stop)

with bytes_to_write and bytes_to_read both being 0.

In this case the function always sets the write bit:

else if (master_bytesToWrite == 0 && master_bytesToRead == 0) {
			twi_mode = TWI_MODE_MASTER_TRANSMIT;
			uint8_t writeAddress = ADD_WRITE_BIT(master_slaveAddress);
			TWI0.MADDR = writeAddress;
		}

Am I missing something here? Or did somebody want to save a few lines, not having this special case in mind?

else if (master_bytesToWrite == 0 && master_bytesToRead == 0) {

@facchinm
Copy link
Member

Hi @tamebits ,
that piece of code is tackling one shortcomings of Wire APIs, that the only way to scan the bus is the pattern

Wire.beginTransmission(address);
if (Wire.endTransmission() == 0) //device found

A solution would be to keep track of the user intention and just set the write bit in this particular use case.
If you want to provide a PR I'll be glad to review it!

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