Hi @myke_predko ,
First of all, I got the demo project from SDK for FRDM-K27L, because I am using MKL27Z256 microcontroller. the other codes for usb are also from the SDK. I just added some lines for printf using in terminal program.
Second, I applied clock setting same as the demo code, clock_config.
Core clock frequency is 48000000Hz for normal mode and 2000000Hz for VLPR.
As my experience, HIRC source is enabled for normal mode. If it is changed LIRC mode, the sensor runs well.
I add part of the detail code below.
For clock_config,
const mcglite_config_t mcgliteConfig_BOARD_BootClockRUN =
{
.outsrc=kMCGLITE_ClkSrcHirc, /* MCGOUTCLK source is HIRC */
.irclkEnableMode = kMCGLITE_IrclkEnable, /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */
.ircs = kMCGLITE_Lirc8M, /* Slow internal reference (LIRC) 8 MHz clock selected */
.fcrdiv = kMCGLITE_LircDivBy1, /* Low-frequency Internal Reference Clock Divider: divided by 1 */
.lircDiv2 = kMCGLITE_LircDivBy1, /* Second Low-frequency Internal Reference Clock Divider: divided by 1 */
.hircEnableInNotHircMode = true, /* HIRC source is enabled */
};
const sim_clock_config_t simConfig_BOARD_BootClockRUN =
{
.er32ksrc=SIM_OSC32KSEL_OSC32KCLK_CLK, /* OSC32KSEL select: OSC32KCLK clock */
.clkdiv1 = 0x10000U, /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV4: /2 */
};
const osc_config_t oscConfig_BOARD_BootClockRUN =
{
.freq = 0U, /* Oscillator frequency: 0Hz */
.capLoad = (kOSC_Cap4P | kOSC_Cap8P), /* Oscillator capacity load: 12pF */
.workMode = kOSC_ModeOscLowPower, /* Oscillator low power */
.oscerConfig =
{
.enableMode = kOSC_ErClkEnable, /* Enable external reference clock, disable external reference clock in STOP mode */
}
};
void BOARD_BootClockRUN(void)
{
/* Set the system clock dividers in SIM to safe value. */
CLOCK_SetSimSafeDivs();
/* Set MCG to HIRC mode. */
CLOCK_SetMcgliteConfig(&mcgliteConfig_BOARD_BootClockRUN);
/* Set the clock configuration in SIM module. */
CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
}
For I2C Initialisation,
I2C_MasterGetDefaultConfig(&i2c_Mconfig);
i2c_Mconfig.baudRate_Bps = 400000U;
i2c_Mconfig.enableMaster = ON;
i2c_Mconfig.enableStopHold = OFF;
i2c_Mconfig.glitchFilterWidth = 0;
int16_t srcclock = CLOCK_GetFreq(I2C0_CLK_SRC);
I2C_MasterInit(I2C0, &i2c_Mconfig, srcclock);
itr