-
Notifications
You must be signed in to change notification settings - Fork 231
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
TWI Accidentally bit left shift after byte transmission #339
Comments
Hey Andreas! I will have a closer look a this. I have tested several IC2 devices on real hardware using the the interactive demo_twi program and I thought the module was doing fine 😅 Some questions regarding your setup:
neorv32_twi_mack_enable();
Yes and no. neorv32/rtl/core/neorv32_twi.vhd Line 154 in af12cde
|
Hi Stephan,
If i disable this, same result //neorv32_twi_mack_enable(); |
This is the MI2C Inventra Macro This is a I2C macro which can work as slave as well as master |
This signal does not look good... Seems like there is a problem with the clock stretching? Can you check the Anyway, maybe there is a synchronization problem when the module initiates a new operation (START, STOP, transmission). I'll check that. |
Oh okay, so it's just a configuration problem?! |
There are two views:
The effect comes of the mismatch of both set-upped frequencies |
What do you think are the changes to add a fine graned post divider into the TWI to match better the I2C standard frequencies? |
Could you zoom into a situation where ´twi_clk_halt´ is set and
I do not know your TWI device module, but when just looking at the I2C specs there should be no problem if the master is running on a slower clock than the actual device..?! |
Sure, this would be possible by modifying the TWI's clock generator. Right now, we have the standard clock prescalers available: enum NEORV32_CLOCK_PRSC_enum {
CLK_PRSC_2 = 0, /**< CPU_CLK (from clk_i top signal) / 2 */
CLK_PRSC_4 = 1, /**< CPU_CLK (from clk_i top signal) / 4 */
CLK_PRSC_8 = 2, /**< CPU_CLK (from clk_i top signal) / 8 */
CLK_PRSC_64 = 3, /**< CPU_CLK (from clk_i top signal) / 64 */
CLK_PRSC_128 = 4, /**< CPU_CLK (from clk_i top signal) / 128 */
CLK_PRSC_1024 = 5, /**< CPU_CLK (from clk_i top signal) / 1024 */
CLK_PRSC_2048 = 6, /**< CPU_CLK (from clk_i top signal) / 2048 */
CLK_PRSC_4096 = 7 /**< CPU_CLK (from clk_i top signal) / 4096 */
}; Internally, the TWI module adds another How much more "precision" / fine-grained divider options do you thing might be suitable? |
Let my think a while about it. In the mean time i think we can close this issue. Sorry for the "wrong alarm" The topic with the divider we can add as disccusion. |
Right, but unpretty nevertheless 😉
No problem! I found a problem with synchronization due to this issue! Fortunately, this has not occurred so far. |
Oh nice :) |
Hmm, strange... This should halt the whole sampling logic... |
Currently I am doing a complete rework of the TWI module - with special focus on the clock generator and the bus sampling logic (timing). I will do a PR when I'm done. Then we can discuss how to implement a more fine-grained clock configuration. |
I checked with #340, now is in the read byte case the ACK of the byte read by the master missing: |
What do you mean by "missing"? The TWI module samples the ACK/NACK in the 9th clock cycle. In your waveform the accessed device does not pull SDA low in that cycle so this is interpreted as NACK. |
In the Waveform, I do an byte read from an Slave (Direction: Slave -> Master) There i had expected that the Master confirms the Byte Receive with an ACK. Anyways, i need to check the I2C spec. |
The NEORV32 TWI module will never do the ACK (actively setting SDA low in the 9th clock cycle) unless explicitly enabled ("master-ACK") by neorv32_twi_mack_enable(); |
This gives a nice overview of ACK/NACK: https://www.ti.com/lit/pdf/slva704 Note that some I²C peripherals require the master to send an ACK during transmission (e.g. when reading data from the device). |
I think I'm done with reworking the TWI module. 🤔 The bus interaction now looks way better and it even ensures the bus staying claimed until a STOP condition is generated. |
Hi Stephan,
at the moment i try to read some bytes from an I2C slave. Therefore i use an properitary I2C macro and the TWI. My belonging testcode looks following:
In my example has the first read byte the value 0xF9 (i2c_slave_d -> I2C_DATA).
When the processor reads the value is the SFR shifted one possition and i recieve 0xF2:
In my opinion is this caused by:
neorv32/rtl/core/neorv32_twi.vhd
Line 259 in af12cde
Whats your opinion?
Thanks for the support.
BR,
Andreas
The text was updated successfully, but these errors were encountered: