Replies: 4 comments
-
Discussion related to my comment:
=> Based on my understanding (may be wrong), my opinion (may be wrong too): twi.c is a bad word in this situation. Twi is a protocol very close to I2C protocol. word was defined for copyright reasons. But here the architecture of this file is not related to a dedicated protocol. To me, a better name should be hal_wire_bridge or something like that. For simplicity reasons Twi should work in the same mode (non blocking) for both slave and master:
To me, the current situation (a mix between non blocking mode for slave, blocking mode for master in file twi) is driving complexity to maintain the code. delay management in twi may be moved to wire for easy maintenance, and clear separation of tasks. |
Beta Was this translation helpful? Give feedback.
-
@camelator,
1/ Aim of Stm32duino is not to fix HAL bad error management: Then, about function `HAL_I2C_Master_Seq_Receive_IT()
It looks normal to me, 2a/ 2b/
Hardware clock stretching is there for that purpose: Slave keeps clock low until data is ready to be send. No need for extra software. If Slave doesn't use stretch capability, the master will not wait.
I disagree: aim is not only simplicity, but also efficiency, and respect of Arduino API. Please note that I convert this thread to discussion, as I see no clear failing use case. |
Beta Was this translation helpful? Give feedback.
-
hi, Consequently Stm32duino should return 0 in case of 0 bytes red. But as I said there are situations it returns for example 8 and data are not consistent instead of returning 0. And I am not sure this line is helping: Please see below one of potential source of error: 2B/ Please have a look in this function: please come back to the call stack, in function i2c_master_read We just said HAL_I2C_Master_Seq_Receive_IT returned HAL_I2C_BUSY ( note there are no error code in hi2c->ErrorCode) in this situation i2c_master_read returns HAL_OK (is it normal ??????) Please continue to the call stack, in the last function requestFrom. Now we can be sure there are at least two or threee problems here.... But let's continue.... and because of no errors management, if the line is broken it remains broken. You can call the function requestFrom 10 times if you want... Please excuse me for that, I have no falling use case, because it is really hard to understand the exact root cause to reproduce that. But it can happen very often, and as I said, there is no way to come back in the right state when it is broken. I suspect it is because CPU are not dedicated on single task and it may have a kind of jitter coming from the master, the CPU may not be answered instantaneously and the problem are beginning... With some complex program and a logic analyzer it is possible to see the problem. etc.... for the list of possible not managed errors. This is why with this architecture I am asking myself how you can manage master errors in blocking mode? Where / and How you manage timeout between the write and the receive? And How sure you can be sure to match the Arduino description for RequestFrom: I don't know if your way is more efficient.... But for sure it is more difficult to debug and find the root cause of the bugs.... Isn't it? Actually, the only way I found to byepass the bad I2C error management in Stm32Duino was to implement the following error management:
by this way I am sure to reach a synchronization . Maybe there are other ways but I don't know how to. |
Beta Was this translation helpful? Give feedback.
-
2A/ If
We don't count, Hardware do it for us: As soon as slave is ready (slave don't stretch the clock), I2C hardware (master) will initiate read operation with the number of bytes requested. And either there is an error detected and it will be handle (see link below) then 2B/
I think there is a confusion here:
When Note: I am based on latest commit from Core repo but according to your comment I am not sure you have patch #1775
Please details your setup, what board, what MCU, which Stm32duino core version, what is CPU you are talking about, ...
There is no timeout to manage:
This is automatically managed by hardware. As I understand at some point your bus is stuck, to go further in the analysis, you should identify which device is blocking the line: slave or master ? |
Beta Was this translation helpful? Give feedback.
-
Well...
I don't know how the tests are done as master, but to me, it may work with fast MCU but not with CPU as I2S slave:
1/ To me, the HAL functions are not correct and for that STM32Duino must deliver / correct the bad error management from HAL.
Example in function HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT
This function has a bad mix of error management and state and return value.
Then, it is possible (and because of other errors in STM32duino) to have this function returning HAL_OK but reading nothing (for example, if the line is busy)
=> STM32Duino should not only manage the return value of the HAL functions but as well error codes and state values, for each call o HAL function, mainly in master mode.
2/ In master mode, The philosophy of the requestFrom is we have to send a request, wait the slave to be ready, and read the data and check errors during the process.
2a/ There is no error check after the TX in function requestFrom
2b/
There is no waiting code in STM32Duino resulting errors returned, or random results, or 0 data, or n random data.
There is something that look like waiting code in function i2c_master_read but it is not well managed as the errors, states and return values from HAL functions are too bad.
For example it is clearly possible that the RX become ready after a while but before the timeout. In this condition, the reading is not repeated resulting wrong results and random behaviors like this one:
https://community.st.com/s/question/0D53W00000EnOPYSA3/stm32l4-hali2cstatebusyrx-issue
but it is not for a short time, when it happens it is stay.
I am not sure part 1/ is related to master as the code on my slave can't see the errors on the line.
I am sure there are other mistakes as I can see sometime strange state values with strange logic state on SCL and SDA with a logic analyzer.
Beta Was this translation helpful? Give feedback.
All reactions