Chris
Thanks again for looking into this.
Yes, you have seen the same behavior as myself when working with the debugger. DBGEN set to 0 means that the LPI2C sends a stop condition after the address. With DBGEN set to '1' the LPI2C freezes and so it continues correctly when the core operates again.
I don't understand the actual meaning of DBGEN since I would expect it to freeze with '0' set but this behavior has been confirmed by both of us and so it shows that it is not possible to use DGBEN at '0' but it is possible with DBGEN at '1' - that is the only option to allow LPI2C to operate correctly. Whether this a bug or not is another question but it is obviously the only possibility to actually work.
Since I was very worried that this behavior (sending STOP if the core didn't supply data on time) could happen in general operation too I made some more test without the debugger connected (in RUN, WAIT and STOP modes). I am pleased to report that I couldn't detect this error in any of these mode when the core doesn't supply the data on time - it is restricted to the operation in debug mode.
However I do detect a potential serious problem with the AUTOSTOP mode and I can confirm that the DOZEN description is inverted in the user's manual and that there is a difference between WAIT and STOP mode behavior.
This is the conclusion after I repeated the tests many times and checked carefully that I wasn't making any mistakes in configurations or measurements. I have attached a binary file for the FRDM-KL28Z board that can be used to see the behavior too.
1. DBGEN state has no effect when the processor is not connected to the debugger/paused.
2. DBGEN has an effect when paused by the debugger and only DBGEN = '1' allows operation without the LPI2C sending an incorrect stop bit. WORKAROUND: Always set DBGEN to '1' and there are no issues.
3. DOZEN = 1 means that the LPI2C runs as normal in both WAIT and STOP modes.
4. DOZEN = 0 means that the LPI2C runs as normal in WAIT mode but stops in STOP mode. This is not as detailed in the user's manual, where it is states that it also stops in WAIT mode. The polarity is also inverted in the user's manual.
5. When AUTOSTOP is set to '0' all read operation is as expected in all modes.
6. When AUTOSTOP is set to '1' all read operation is as expected in all modes as long as the core immediately command the read after sending the slave address.
If the core doesn't command the read "immediately" it stops sending, but it never sends a STOP condition.
WORKAROUND: Never leave the AUTOSTOP bit set during the transmission of the slave's read address!
7. When AUTOSTOP is set to '0' all transmission is as expected in all modes.
8. If AUTOSTOP mode is set to '1' the Tx buffer should be kept fed otherwise a STOP condition will be sent prematurely - also after the slave write address. This is however the correct operation and so it is up to the user to correctly make use of it.
>>One theory I have though, is maybe the interrupt signal from the LPI2C is waking up the processor? Could this be happening in your system?
As shown in one of the previous screen shots (and various below), there are interrupts taking place on each LPI2C data byte (tx and rx) and so the core is continuously moving between WAIT and RUN or STOP and RUN.
What I see when DOZEN = 1 is used and the core moves to STOP is that the LPI2C state 'freezes' (screen shots below). When the core moves to WAIT the LPI2C activity continues normally.
In the STOP state (and frozen LPI2C) I have a 1s interrupt for the RTC that wakes the processor momentarily to RUN and it then immediately returns the STOP state. Sometimes I see that the state of the LPI2C bus changes when this happens, showing that the LPI2C also operates during this moment before freezing again.
>>By the way, are you also using the SDK drivers in your project?
No, I am using the uTasker project and working on integration of the simulation of the LPI2C interface, where I have noticed deviations. This project uses dynamic low power management and so allows more flexible and meaningful tests in a complete working environment, rather than a single example setup.
In case you would like to repeat some tests you can load the attached binary file to a FRDM-KL28Z and control it as follows:
1. When the board starts it will continuously read the accelerometer (50kHz clock and almost no pauses on the bus)

2. It will be in WAIT mode whenever there is no activity (default behavior). The RED led is connected to a GPIO that is set to '1' when the processor is in RUN mode and '0' when in WAIT mode. This is seen below the 2 I2C lines in the screen shot and follows the LPI2C interrupts since there is not much else happening on the board (there is a 50ms TICK plus a 1s RTC interrupt [plus USB and LPUART that are irregular])
3. There is a command line interface on the VCOM UART and also on the USB (as CDC) so either can be used for control.
When the enter key is hit a menu appears:
Main menu
===================
1 Configure LAN interface
2 Configure serial interface
3 Go to I/O menu
4 Go to administration menu
5 Go to overview/statistics menu
6 Go to USB menu
7 Go to I2C menu
8 Go to utFAT disk interface
9 FTP/TELNET commands
a CAN commands
b Advanced commands
help Display menu specific help
quit Leave command mode
4. In menu 7 some I2C commands can be exercised.
I2C menu
===================
up go to main menu
acc_on enable accelerometer output
acc_off disable output
tpause test potential bug [1/0]
rpause test potential bug [1/0]
dozen DOZEN [1/0]
dbgen DBGEN [1/0]
auto AUTOSTOP [1/0]
help Display menu specific help
quit Leave command mode
"acc_on" turns on the accelerometer output display and "acc_off" disables it again.
With "dozen 0" and "dozen 1" the state of the DOZEN control can be changed.
With "dbgen 0" and "dbgen 1" the state of the DBGEN control can be changed.
With "auto 0" and "auto 1" the state of the AUTOSTOP control can be changed.
With "tpause 0" and "pause 1" the behavior to delaying the write of the first data byte - it adds a 0.5ms delay between commanding the START + address and allowing further operation to continue
With "rpause 0" and "pause 1" the behavior to delaying the read of the first data byte - it adds a 0.5ms delay between commanding the START + address and allowing further operation to continue
Move up a menu level with "up"
5. In menu 4 (administration) the low power mode being used can be displayed (with "show_lp") and the mode changed with "set_lp 2" (2 sets STOP mode rather than the default WAIT mode [1]). In stop mode USB-CDC will stop and it may be necessary to reset to get out (possibly the UART responds but I don't know since the OpenSDA debugger on my board gets deleted all the time so I just use an external one [The DAP OpenSource debuggers are really awful - they either don't work or delete themselves when connected to a PC - their MSD and CDC are also only partly operational - I wish we could load a P&E or Segger version to this board ;-( ]).
6. This is the recording showing 0.5ms pause after writing the START + slave write address

As can be seen, the delay doesn't affect operation - there is a following STOP and START (rather than repeated start) due to the firmware slowness, but this is correct.
7. This is the recording of the same with AUTOSTOP enabled.

The slowness of the firmware causes the LPI2C to automatically send the STOP condition. This is premature for correct behavior but is the fault of the slow firmware for using a mode that it can't keep up with. Therefore OK.
8. This is a normal read reference (just start of multi-byte read)

and the effect of a pause of 0.5ms.

The LPI2C waits correctly.
9. This is the effect of using AUTOSTOP and a pause in the read.

Note that now the LPI2C module sets the SCLK line high but the SDA line stays low forever.
This never recovers! NEVER start a read with AUTOSTOP set !!!!
10 Finally, the effect of setting DOZEN to 0 and the STOP mode (commands "dozen 0" followed by "set_lp 2"):

When the STOP mode is set (lower line goes to '0' the LPI2C activity 'freezes in an active bus state). In WAIT mode it continues.
Looking at a bigger picture.

About 0.8s after the big freeze there is a momentary wake-up to RUN mode due to a RTC seconds interrupt, where it is seen that the LPI2C briefly continues with some activity during the short RUN state.
If I monitor this over a long period of time it is seen that there is a single LPI2C movement each time the RUN mode is executed for a few us so the LPI2C activity is operating but extremely slowly since it only operates a few us each second.....
[Note also that the 50ms TICK is from the SYSTICK in this configuration, and this also stops in STOP mode].
All permutations can be tested easily with the attached binary and each test is fully reproducible....
Regards
Mark