Fix timing issues in initialization sequence #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due to the particular example used by the documentation of the HAL I'm using, I first tried using this library with an I²C clock of 50 kHz (I'm using an adapter based on a PCF8574). Although I didn't know the cause at the time, this was preventing my LCD from working. I eventually perturbed it into working by switching to 100 kHz, but the mystery was getting to me – why would a slower I²C clock break things?
After some experiments, things got weirder – if I inserted some delay into
write_bits_to_gpio, making things even slower, it started working again!The mystery was getting to me, and eventually, I narrowed it down to the init sequence, and how it doesn't wait for the CLEAR and HOME commands to finish executing. I believe that for a 100 kHz I²C clock, things just happened to align in such a way, that one of these commands would get skipped completely. Slowing things down made it catch some of the writes again, which probably misaligned the phase of the 4-bit-wide bus – and slowing things down even more made everything work as written in the code.
While I'm at it, I'm also including a fix to make sure that the address set up time is observed – see t_AS on the figure below, which Hitachi have helpfully buried at the very end of the datasheet:
Admittedly, I couldn't find an experimental setup in which this particular issue prevented my LCD from working – but complying with the spec is always a good idea ;3