<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Kinetis MicrocontrollersのトピックRe: I2C module initialisation</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1346888#M61571</link>
    <description>&lt;P&gt;I have finally managed to get data out of my I2C module. Man I'm sure I wrote 10000 different codes just trying to read the WhoAmI register. After 3 months of suffering it turned out the problem was not in the code, it was a hardware issue. The module I'm trying to read has a reset pin. According to the datasheet this reset pin should be connected to ground if not used. So that's what I did the first time I started working with it, I soldered it to ground. I was giving up on this module. I just pulled out this reset wire without even desoldering it properly, and luckily I just decided to run the code just one more time before breaking the SDA and SCL line and throwing away the module and to my surprise I got an acknowledgement. Now I can start configuring the module. Thanks to everyone who took their time and participated in this thread, especially &lt;SPAN class="UserName lia-user-name lia-user-rank-Senior-Contributor-III lia-component-message-view-widget-author-username"&gt;bobpadock&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Sep 2021 13:12:34 GMT</pubDate>
    <dc:creator>Psy_coder</dc:creator>
    <dc:date>2021-09-27T13:12:34Z</dc:date>
    <item>
      <title>I2C module initialisation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1309897#M61054</link>
      <description>&lt;P&gt;The chip is MK10DN512VMC10. I'm trying to initialise the I2C module so that I can interface with accellerometer/gyroscope. I can't get to the point where I can configure the gyroscope. I'm failing to just see the SCL square waves on the oscilloscope. When I try to write to the I2C registers the system runs into hard fault.&lt;/P&gt;&lt;P&gt;here is my code&lt;/P&gt;&lt;P&gt;#define I2C_Frequency_Divider_register__I2C1_F (*(uint32_t *)0x40067001U)&lt;BR /&gt;#define I2C_Control_Register_1__I2C1_C1 (*(uint32_t *)0x40067002U)&lt;BR /&gt;#define I2C_Status_Register__I2C1_S (*(uint32_t *)0x40067003U)&lt;/P&gt;&lt;P&gt;#define Pin_Control_Register_n__PORTE_PCR0 (*(uint32_t *)0x4004D000U)&lt;BR /&gt;#define Pin_Control_Register_n__PORTE_PCR1 (*(uint32_t *)0x4004D004U)&lt;BR /&gt;#define System_Clock_Gating_Control_Register_4_SIM_SCGC4 (*(uint32_t *)0x40048034U)&lt;BR /&gt;#define System_Clock_Gating_Control_Register_5_SIM_SCGC5 (*(uint32_t *)0x40048038U)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void mcu_Initialise()&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;Pin_Control_Register_n__PORTE_PCR0 = 0x00000620U;&lt;BR /&gt;Pin_Control_Register_n__PORTE_PCR1 = 0x00000620U;&lt;/P&gt;&lt;P&gt;System_Clock_Gating_Control_Register_4_SIM_SCGC4 |= 0x00000080U;&lt;BR /&gt;System_Clock_Gating_Control_Register_5_SIM_SCGC5 |= 0x00002000U;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void intitialiseI2C()&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;I2C_Frequency_Divider_register__I2C0_F |= 0x29U; //writing to this register takes the system into hard fault&lt;/P&gt;&lt;P&gt;I2C_Control_Register_1__I2C1_C1 |= 0x80;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;int main(void) {&lt;/P&gt;&lt;P&gt;BOARD_InitBootPins();&lt;BR /&gt;BOARD_InitBootClocks();&lt;BR /&gt;&amp;nbsp;mcu_Initialise();&lt;BR /&gt;intitialiseI2C();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 14:08:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1309897#M61054</guid>
      <dc:creator>Psy_coder</dc:creator>
      <dc:date>2021-07-19T14:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: I2C module initialisation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1310556#M61060</link>
      <description>&lt;P&gt;Do you really want to be using OR (|=) rather than assignment (=) everyplace?&lt;BR /&gt;&lt;BR /&gt;The hard fault indicates that the module clock is not running.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 15:29:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1310556#M61060</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2021-07-20T15:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: I2C module initialisation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1311908#M61066</link>
      <description>&lt;P&gt;"Do you really want to be using OR (|=) rather than assignment (=) everyplace?"&lt;/P&gt;&lt;P&gt;I didn't think it could be the effect towards my problem because I thought it simply means I'm setting individual bits in a register without affecting the other bits, but I have removed the "|" as you suggested. The problem is still there though&lt;/P&gt;&lt;P&gt;"The hard fault indicates that the module clock is not running."&lt;/P&gt;&lt;P&gt;Do you mean the I2C module clock?... If that's the case, then it means my logic is flawed of thinking I'm enabling the clock with the line -&amp;nbsp;&lt;/P&gt;&lt;P&gt;System_Clock_Gating_Control_Register_4_SIM_SCGC4 = 0x00000080U;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 09:34:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1311908#M61066</guid>
      <dc:creator>Psy_coder</dc:creator>
      <dc:date>2021-07-22T09:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: I2C module initialisation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1311995#M61068</link>
      <description>&lt;P&gt;It is best to use the defines from the header file rather than magic numbers like 0x80:&lt;BR /&gt;&lt;BR /&gt;SIM_SCGC4_I2C1_MASK&lt;/P&gt;&lt;P&gt;Yes, that would enable the clock for I2C1.&lt;BR /&gt;&lt;BR /&gt;Look at the clock tree diagram for your part and see if anything else upstream in the clock tree also needs setup.&lt;/P&gt;&lt;P&gt;As to the |= issue, it usually makes no difference, other than a bit of wasted CPU time.&lt;BR /&gt;The critical place it can bite you is in clearing a bit in a status requester, with the 'Write-1-To-Clear' mechanism.&amp;nbsp; Give consideration to when to use (=) and when to use (|=).&amp;nbsp; NXP frequently uses |= in their examples, when they really shouldn't.&lt;BR /&gt;&lt;BR /&gt;As example:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SIMs should use |= to prevent turning off other active clocks while turning on I2C clock.&lt;/P&gt;&lt;P&gt;I2C FRQ DIV should not use |= to be sure the register is as you want and it wasn't changed by something like a bootloader from the data sheet default value.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 12:27:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1311995#M61068</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2021-07-22T12:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: I2C module initialisation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1317373#M61128</link>
      <description>&lt;P&gt;I have 3 weeks now failing to just get the WhoAmI value from the I2C module "FXOS8700 + FXAS21002"&lt;/P&gt;&lt;P&gt;What is wrong with my code, what am I missing?&lt;/P&gt;&lt;P&gt;The supply voltage to the I2C module is 5V. Before programming the mcu, Both the SCL and SDA lines measure 5 volts with reference to the ground. Then when I'm in debugg, with oscilloscope connected to the I2C bus, The voltage drops from 5V to 3.75V and stay there when I mux PortD in my code. Shouldn't i be seeing square waves on the scl line even with no data transfer between mcu and the module?&lt;/P&gt;&lt;P&gt;I get Arbitration lost in the status register.&lt;/P&gt;&lt;P&gt;What is wrong with my code?&lt;/P&gt;&lt;P&gt;Below is my code&lt;/P&gt;&lt;P&gt;Printing "ReceivedByte" array on tera term shows wrong WhoAmI value&lt;BR /&gt;uint8_t Receivedbyte[3];&lt;BR /&gt;uint8_t WhoAmI_address[1] = {0x0D};&lt;BR /&gt;size_t RegSize = 1;&lt;/P&gt;&lt;P&gt;void Mcu_Initialise()&lt;BR /&gt;{&lt;BR /&gt;PORTD-&amp;gt;PCR[8] = 0x01000000; //clear the ISF flag&lt;BR /&gt;PORTD-&amp;gt;PCR[9] = 0x01000000; //clear the ISF flag&lt;/P&gt;&lt;P&gt;PORTD-&amp;gt;PCR[8] |= 0x00000200; //mux PTD8 for I2C0_SCL&lt;BR /&gt;PORTD-&amp;gt;PCR[9] |= 0x00000200; //mux PTD9 for I2C0_SDA&lt;/P&gt;&lt;P&gt;SIM-&amp;gt;SCGC4 |= SIM_SCGC4_I2C0_MASK; // I2C0 clock&lt;BR /&gt;SIM-&amp;gt;SCGC5 |= 0x00002000U; //portD&lt;/P&gt;&lt;P&gt;//I'm not sure about the following two lines&lt;BR /&gt;EnableIRQ(I2C0_IRQn);&lt;BR /&gt;NVIC_SetPriority(I2C0_IRQn,0);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;void I2C_Initialise()&lt;BR /&gt;{&lt;BR /&gt;I2C0-&amp;gt;A1 = 0;&lt;BR /&gt;I2C0-&amp;gt;F = 0;&lt;BR /&gt;I2C0-&amp;gt;C1 = 0;&lt;BR /&gt;I2C0-&amp;gt;S = 0xFFU;&lt;BR /&gt;I2C0-&amp;gt;C2 = 0;&lt;/P&gt;&lt;P&gt;I2C0-&amp;gt;S |= I2C_S_IICIF_MASK ; //clear IICIF&lt;/P&gt;&lt;P&gt;I2C0-&amp;gt;F = 0x27U; //bus clock is 48MHz, calculated baud rate for 100khz&lt;BR /&gt;I2C0-&amp;gt;C1 = I2C_C1_IICEN_MASK;&lt;BR /&gt;//I2C0-&amp;gt;C1 |= I2C_C1_IICIE_MASK; // When I enable this interrupt the system gets stuck in CLOCK_GetOutClkFreq() function. When I disable it I'm able to run my code from mcu_initialise() to Read()&lt;/P&gt;&lt;P&gt;void StartCondition()&lt;BR /&gt;{&lt;BR /&gt;I2C_MasterStart(I2C0, FXOS8700CQ_Address, kI2C_Write);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void StartRepeat()&lt;BR /&gt;{&lt;BR /&gt;I2C_MasterRepeatedStart(I2C0, FXOS8700CQ_Address, kI2C_Read);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void sendRegister()&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;I2C_MasterWriteBlocking(I2C0, WhoAmI_address, RegSize, kI2C_TransferNoStopFlag);&lt;BR /&gt;}&lt;BR /&gt;void Read()&lt;BR /&gt;{&lt;BR /&gt;I2C_MasterReadBlocking(I2C0,ReceivedByte, RegSize, kI2C_TransferNoStartFlag);&lt;BR /&gt;}&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;BOARD_InitPins();&lt;BR /&gt;__disable_irq();&lt;BR /&gt;InitVersion();&lt;BR /&gt;/* Init board hardware. */&lt;BR /&gt;BOARD_InitBootPins();&lt;BR /&gt;BOARD_InitBootClocks();&lt;BR /&gt;BOARD_InitBootPeripherals();&lt;/P&gt;&lt;P&gt;mcu_Initialise();&lt;BR /&gt;intitialiseI2C();&lt;BR /&gt;StartCondition();&lt;BR /&gt;sendRegister();&lt;BR /&gt;StartRepeat();&lt;BR /&gt;Read();&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 13:16:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1317373#M61128</guid>
      <dc:creator>Psy_coder</dc:creator>
      <dc:date>2021-08-03T13:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: I2C module initialisation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1317499#M61132</link>
      <description>&lt;P&gt;[Will someone PLEASE fix the form to not allow replies when not logged in!&amp;nbsp; Just lost a long one.]&lt;BR /&gt;&lt;BR /&gt;Isn't there a bit in C1 that needs set to indicate this is the Master?&amp;nbsp; I don't have a datasheet at hand.&lt;BR /&gt;&lt;BR /&gt;SCL is only toggling during a transfer, not all the time.&lt;BR /&gt;&lt;BR /&gt;How is 5V involved in this?&lt;BR /&gt;&lt;BR /&gt;SCL/SDA need set to open-drain/collector.&lt;BR /&gt;Some NXP parts are only pseudo-open ports, going above 3.6V could damage something in such parts, which is where your 3.7V comes from when the code starts.&lt;BR /&gt;&lt;BR /&gt;Is the Accel/Gyro/whatever a 5V part? That would be rare.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 17:25:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1317499#M61132</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2021-08-03T17:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: I2C module initialisation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1346888#M61571</link>
      <description>&lt;P&gt;I have finally managed to get data out of my I2C module. Man I'm sure I wrote 10000 different codes just trying to read the WhoAmI register. After 3 months of suffering it turned out the problem was not in the code, it was a hardware issue. The module I'm trying to read has a reset pin. According to the datasheet this reset pin should be connected to ground if not used. So that's what I did the first time I started working with it, I soldered it to ground. I was giving up on this module. I just pulled out this reset wire without even desoldering it properly, and luckily I just decided to run the code just one more time before breaking the SDA and SCL line and throwing away the module and to my surprise I got an acknowledgement. Now I can start configuring the module. Thanks to everyone who took their time and participated in this thread, especially &lt;SPAN class="UserName lia-user-name lia-user-rank-Senior-Contributor-III lia-component-message-view-widget-author-username"&gt;bobpadock&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 13:12:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-module-initialisation/m-p/1346888#M61571</guid>
      <dc:creator>Psy_coder</dc:creator>
      <dc:date>2021-09-27T13:12:34Z</dc:date>
    </item>
  </channel>
</rss>

