-
Notifications
You must be signed in to change notification settings - Fork 33
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
i2c slave tx now working, see #99 #100
Conversation
I've compared this to https://github.com/arduino/ArduinoCore-megaavr/tree/master/libraries/Wire/src and it looks more simliar now -- though some log in is It does feel a bit weird to be accessing sub-members of the |
I may be wrong but the " |
And i think i now have understood that the And filling the buffer also starts in
I do not think that another |
I think the flow is like this, given an I2C transaction looks like Considering only the case of a "slave transmitter" (I2C transaction from master with "READ" as intention, not WRITE): The address bits are sent by the master and determined by hardware to be the "our" (slave's) address. This fires the I'm taking that interpretation from the reference manual, see https://github.com/CommunityGD32Cores/gigadevice-firmware-and-docs/tree/main/GD32F1x0. So yeah, it looks fine to me that the TX buffer is reset in |
Great, could you look over the 2 review comments and fixup if needed? Then we can get this merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per comments
} | ||
obj_s->tx_count += length; | ||
if (obj_s->tx_count > obj->tx_rx_buffer_size) | ||
return I2C_DATA_TOO_LONG; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think incrementing tx_count
should only happen if we know that we can hold the data, otherwise we get into an inconstistent state if we increment + return error. I.e., first check if (obj_s->tx_count + length <= obj->tx_rx_buffer_size)
, then increment.
This is my first pull request. what 2 review comments ? |
They should be visible in the conversation flow here or in-line in the changed files. |
Oh shame on me. Of course there is not type Yes i tried to minimize the code and therefore added the |
i have updated the Yes, the hardware still works nicely with the update. |
No, if you update the file in the same branch as this PR is being source from now ( Please see review comment above for the final change. |
i am really stupid today. No longer focused :-( changed made to my fork
Sorry that you waste time with my stupid beginner mistakes |
Thanks for the changes! Merged in succesfully. |
My first PR, that makes me happy :-) |
@maxgerhardt and others :-)
From my issues/99:
Try to get a GD32F130C8 become an i2c slave (SimpleFOC..) but it hangs after several requestEvent()
...
The buffer pointer gets initialized in the TwoWire constructor Wire.cpp#L42
_i2c.tx_buffer_ptr = _tx_buffer.buffer;
but is never reset yet incremented when a byte is transmitted in twi.cpp#L650
...
As the i2c_slave_tx is done via interrupt in twi.cpp, i could not use the cyclic head/tail method of wire.cpp :-(
So i assume (maybe i am wrong) that while the TwoWire::onRequestService is processed, the I2C interrupt handler i2c_irq(..) of twi.cpp DOES NOT get called (which also uses inrements the tx_buffer_ptr to output the buffer).
Then i can use the tx_buffer_ptr during the onRequestService to fill the buffer, reset it at its end and let the i2c_irq reuse tx_buffer_ptr to output the buffer.
Then only two changes need to be done :-)
Maybe add this to Wire/examples/slave_sender/slave_sender.pde:
// The tx buffer is only 32 bytes long. To send bigger structs one must #define WIRE_BUFFER_LENGTH 128 before #include <Wire.h>
Greetings from Germany, Roland and :-)