I'm using the KT9Z1J638 eval board with the KT9Z1_638_SCI_demo firmware project and unable to achieve reliable sleep with wake on PTB4.
I'm not using CAN or LIN, but instead plan to transfer measurement data over SPI to another system. The application will use sleep mode and the wake on PTB4 and wake on current threshold features.
I can put the demo code to sleep by setting bmsmode=BMS_SLEEP, and wake on PTB4 rising edge (press BP3), but it isn't reliable -- it seems to work exactly once after full power cycle, USB connect, and reflashing the firmware. Subsequent attempts to enter sleep mode hang with 15mA supply current drain.
Also tested standalone (without USB attached). With S1-1 open (RESET_A and RESET not connected), when VBAT is applied, it hangs consistently, again with the 15mA drain. Hardware RESET gets it going, but then it hangs after entering sleep mode, again with the 15mA.
With S1-1 closed (RESET_A and RESET tied together), the system starts reliably at power on, but when the code enters sleep mode, the system immediately restarts through reset.
I suspected it was hanging in d2d.c:isrd2derr, and confirmed my suspicion by pulsing a debug output inside the loop.
You definitely have to connect the RESET <> RESET_A (S1-1 closed) for proper operation.
If in your setup the system immediately restarts, then this most likely will be due to a wakeup (in Sleep mode the wakeup is a "Reset").
If you use the BP3 switch on the EVB to wakeup the MM9Z1J638, then you have to add a pull down resistor (there is none on the KT9Z1J638EVM! Maybe try to enable the internal Pull Down for PTB4:
void GPIOInit(void) {
B_GPIO_CTL = GPIO_CTL_PTB1_DISABLE;
// map SCI to pins
B_GPIO_CTL = GPIO_CTL_PTB2_OUTPUT;
B_GPIO_CTL = GPIO_CTL_PTB2_ENABLE;
B_GPIO_OUT2 = OUT_SCITX;
B_GPIO_CTL = GPIO_CTL_PTB3_INPUT;
B_GPIO_CTL = GPIO_CTL_PTB3_ENABLE;
B_GPIO_IN3 = IN_SCIRX;
B_GPIO_PUC_PDE4 = 1; // enable pull down (missing on KT9Z1638EVM)
B_GPIO_CTL = GPIO_CTL_PTB4_ENABLE; // PTB4 is used for Wakeup testing
B_GPIO_IN4 = IN4_PTWU; // enable WU in low power mode, positive edge
}
Note:
you can send the device to sleep mode with a connected Terminal Program by transmitting a "S\n". E.g.:
The transmitted text "Sleep Mode" is interrupted as the device enters sleep w/o waiting for the transmission being complete.
Wolfgang,
Thank you for the detailed response.
The PTB4 pulldown option did the trick. There is nothing in the board documentation or demo source code about enabling this.
Board documentation regarding S1-1 is conflicted - setup shows S1-1 off for OSBDM, but the footnote says it should be on. As I said, I tried S1-1 both ways, no joy.
Seems to flash ok without the 470nF cap, but will try adding it.
Thanks,
Darryl