<?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>Wireless MCUのトピックRe: I2C communication issue</title>
    <link>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1196675#M10433</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;This not correct way how to read back data from slave.&lt;/P&gt;&lt;P&gt;That is a bit disappointing there is no simple example in SDK for something like:&lt;/P&gt;&lt;P&gt;Read 2 bytes from register 0x01 from Slave 0x78.&lt;/P&gt;&lt;P&gt;However, it took me a while figuring out what to do and everything works fine.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Fri, 11 Dec 2020 00:20:56 GMT</pubDate>
    <dc:creator>MikeCalm</dc:creator>
    <dc:date>2020-12-11T00:20:56Z</dc:date>
    <item>
      <title>I2C communication issue</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1194980#M10427</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the issue with I2C communication between QN9090 and temperature sensor TM116.&lt;/P&gt;&lt;P&gt;This is my first attempt using SDK for I2C, and I am not sure if everything is right.&lt;/P&gt;&lt;P&gt;There is no example reading from slave device, and not even one topic here.&lt;/P&gt;&lt;P&gt;Following existing examples, here is what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;I2C_MasterGetDefaultConfig(&amp;amp;masterConfig);

/* Change the default baudrate configuration */
masterConfig.baudRate_Bps = I2C_BAUDRATE;

/* Initialize the I2C master peripheral */
I2C_MasterInit(EXAMPLE_I2C_MASTER, &amp;amp;masterConfig, I2C_MASTER_CLOCK_FREQUENCY);

/* prepare for reading
 * 1. write register 2. read 2 bytes
 */
I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_SLAVE_ADDR_7BIT, kI2C_Write);
g_master_buff[0] = 0x00U;

reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_buff, 1, kI2C_TransferDefaultFlag);
if (reVal != kStatus_Success)
{
	PRINTF(printf("Write Error! %d\n", reVal));
}
else
{
	PRINTF("Write Success\n");
}
I2C_MasterStop(EXAMPLE_I2C_MASTER);&lt;/LI-CODE&gt;&lt;P&gt;Above works fine. Writing returns no error.&lt;/P&gt;&lt;P&gt;Reading part never worked:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_SLAVE_ADDR_7BIT, kI2C_Read);
int32_t i2c_status = I2C_MasterReadBlocking(I2C_SLAVE_ADDR_7BIT, g_slave_buff, 2, kI2C_TransferDefaultFlag);
if (i2c_status != kStatus_Success)
{
	PRINTF(printf("Read Error! %d\n", i2c_status));
}
else
{
	PRINTF("Read Success\n");
}&lt;/LI-CODE&gt;&lt;P&gt;I have i2c_status error 2605 - kStatus_I2C_ArbitrationLost error.&lt;/P&gt;&lt;P&gt;I am sure there might be something missing. Not sure if writing works fine, despite no error.&lt;/P&gt;&lt;P&gt;I will have it checked with oscilloscope in few day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone point possible solution?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 23:00:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1194980#M10427</guid>
      <dc:creator>MikeCalm</dc:creator>
      <dc:date>2020-12-07T23:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: I2C communication issue</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1196675#M10433</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;This not correct way how to read back data from slave.&lt;/P&gt;&lt;P&gt;That is a bit disappointing there is no simple example in SDK for something like:&lt;/P&gt;&lt;P&gt;Read 2 bytes from register 0x01 from Slave 0x78.&lt;/P&gt;&lt;P&gt;However, it took me a while figuring out what to do and everything works fine.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 00:20:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1196675#M10433</guid>
      <dc:creator>MikeCalm</dc:creator>
      <dc:date>2020-12-11T00:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: I2C communication issue</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1715181#M15590</link>
      <description>&lt;P&gt;I know it's been a while, but any chance that you could share your code, since I also noticed that there isn't a simple example that uses the API (fsl_i2c) to do something like:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; Read 2 bytes from register 0x01 from Slave 0x78.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm trying to read the LM75 sensor on the OM40001&amp;nbsp; LPCXpresso804 board, and although I have the sample "I2C_temperature" project working, that project doesn't use the fsl_i2c SDK API calls.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I try to implement it using the&amp;nbsp;&lt;EM&gt;I2C_MasterWriteBlocking()&lt;/EM&gt; and&amp;nbsp;&lt;EM&gt;I2C_MasterReadBlocking()&lt;/EM&gt; calls, the&amp;nbsp;I2C_MasterReadBlocking() call is failing.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Instead of getting the &lt;EM&gt;master_state&lt;/EM&gt; value of I2C_STAT_MSTCODE_RXREADY (value = 1) so it would read out the data, it is instead seeing a value of 2, which makes the code fall to the default: case and sets &lt;STRONG&gt;err = kStatus_I2C_UnexpectedState;&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Does anyone have a simple I2C code example that just reads two bytes from a slave SPI device using the&amp;nbsp;&lt;EM&gt;I2C_MasterWriteBlocking()&lt;/EM&gt; and&amp;nbsp;&lt;EM&gt;I2C_MasterReadBlocking()&lt;/EM&gt; calls from the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;fsl_i2c SDK API?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The&amp;nbsp;&lt;EM&gt;lpcxpresso804_lpc_i2c_polling&lt;/EM&gt; sample project is too generic.&amp;nbsp; Why wouldn't NXP create the sample project to talk to the I2C device (&lt;EM&gt;the LM75&lt;/EM&gt;) that is on the actual board that the project is named for and supposedly a project for?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 15:13:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1715181#M15590</guid>
      <dc:creator>jrevans</dc:creator>
      <dc:date>2023-08-31T15:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: I2C communication issue</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1715248#M15591</link>
      <description>&lt;P&gt;Of course, ten minutes after posting this, I figured out how to use the code from the&amp;nbsp;&lt;EM&gt;lpcxpresso804_lpc_i2c_polling&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;sample project and modify it to correctly read the temperature from the on-board LM75 sensor....&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'll clean up my code and post it here in a little while, to hopefully help anyone else who is looking to do this.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 16:34:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1715248#M15591</guid>
      <dc:creator>jrevans</dc:creator>
      <dc:date>2023-08-31T16:34:36Z</dc:date>
    </item>
    <item>
      <title>SDK I2C sample code to read LM75 on the LPCXpresso804 board</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1718177#M15609</link>
      <description>&lt;P&gt;Okay, here is the code that I used to be able to use the SDK's I2C library to communicate with the LM75 on the OM40001 LPCXpresso804 development board.&lt;/P&gt;&lt;P&gt;Create a project and use the ConfigTools to enable the Peripheral Signals to include I2C0.&amp;nbsp; Then setup PIO0_7 with pin identifier I2C_SDA, and PIO0_14 with pin identifier I2C_SCL.&lt;/P&gt;&lt;P&gt;First make sure you include the i2c header file.&amp;nbsp; When you make you project and select the pins for I2C, it may add this already:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#include "fsl_i2c.h"  // For I2C calls&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After the includes, add this glob:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#define I2C_MASTER_BASE    			(I2C0_BASE)
#define I2C_MASTER_CLOCK_FREQUENCY	(12000000)
#define I2C_MASTER 					((I2C_Type *)I2C_MASTER_BASE)
#define I2C_BAUDRATE               	100000U
#define I2C_DATA_LENGTH				16U  // Used to set the size of the buffers

i2c_master_config_t masterConfig;
uint8_t g_master_txBuff[I2C_DATA_LENGTH];
uint8_t g_master_rxBuff[I2C_DATA_LENGTH];

// The OM40001 documentation says: NXP LM75BDP temperature sensor
// JP4 and JP23 need to be installed, which they are by default
// Temperature sensor (LM75, circuit ref U7)
// The I2C address is 0x1001100.
// From I2C_temperature_main.c
//#define LM75_ADDR			(0x90 &amp;gt;&amp;gt; 1) // = 0x48 72d ('H')
#define LM75_ADDR			0x48  // Should be the same as (0x90 &amp;gt;&amp;gt; 1)
#define LM75_CONFIG			0x01
#define LM75_TEMPERATURE	0x00

int32_t init_LM75(void);
uint32_t read_LM75(void);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In main() after BOARD_InitBootPeripherals() you want to add this glob:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    BOARD_InitI2CPins();  // Enable the I2C pins
    CLOCK_Select(kI2C0_Clk_From_MainClk);  // Select the main clock as the source clock for I2C0
    I2C_MasterGetDefaultConfig(&amp;amp;masterConfig);  // Load the default values into masterConfig
    masterConfig.baudRate_Bps = I2C_BAUDRATE;  // Change the default baudrate in the configuration to our value
    I2C_MasterInit(I2C_MASTER, &amp;amp;masterConfig, I2C_MASTER_CLOCK_FREQUENCY);  // Initialize the I2C master peripheral using our masterConfig
    init_LM75();  // Initialize the sensor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created two functions related to the LM75.&amp;nbsp; &lt;STRONG&gt;init_LM75()&lt;/STRONG&gt; and &lt;STRONG&gt;read_LM75()&lt;/STRONG&gt;.&amp;nbsp; Here they are:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;int32_t init_LM75(void)
{
    status_t retVal = kStatus_Fail;

    // The write only process is done by:
    //  I2C_MasterStart()
    //  I2C_MasterWriteBlocking() with kI2C_TransferDefaultFlag flag
    //  I2C_MasterStop()
	if (kStatus_Success == I2C_MasterStart(I2C_MASTER, LM75_ADDR, kI2C_Write))
    {
    	g_master_txBuff[0] = LM75_CONFIG;
    	g_master_txBuff[1] = 0x00;  // Set the default operating mode

        retVal = I2C_MasterWriteBlocking(I2C_MASTER, g_master_txBuff, 2, kI2C_TransferDefaultFlag);

        if (retVal != kStatus_Success)
        {
            return -1;
        }

        retVal = I2C_MasterStop(I2C_MASTER);

        if (retVal != kStatus_Success)
        {
            return -1;
        }

        retVal = kStatus_Success;
    }

	return(retVal);
}


uint32_t read_LM75(void)
{
    status_t retVal = kStatus_Fail;
    uint8_t deviceAddress = LM75_TEMPERATURE;

    memset(g_master_rxBuff, 0, I2C_DATA_LENGTH);

    // The combination write/read is done by:
    //  I2C_MasterStart()
    //  I2C_MasterWriteBlocking() with kI2C_TransferNoStopFlag flag
    //  I2C_MasterRepeatedStart()
    //  I2C_MasterReadBlocking() with kI2C_TransferDefaultFlag flag
    //  I2C_MasterStop()
	if (kStatus_Success == I2C_MasterStart(I2C_MASTER, LM75_ADDR, kI2C_Write))
	{
		// We're writing one byte, the register value of 0x00 to immediately read temperature data from.
		// We set the flag to kI2C_TransferNoStopFlag since we're doing a read right after this.
		retVal = I2C_MasterWriteBlocking(I2C_MASTER, &amp;amp;deviceAddress, 1, kI2C_TransferNoStopFlag);

		if (retVal != kStatus_Success)
		{
			return -1;
		}

		retVal = I2C_MasterRepeatedStart(I2C_MASTER, LM75_ADDR, kI2C_Read);

		if (retVal != kStatus_Success)
		{
			return -1;
		}

		// Now we're reading two bytes of the temperature data from the slave device, into g_master_rxBuff
		retVal = I2C_MasterReadBlocking(I2C_MASTER, g_master_rxBuff, 2, kI2C_TransferDefaultFlag);

		if (retVal != kStatus_Success)
		{
			return -1;
		}

		retVal = I2C_MasterStop(I2C_MASTER);

		if (retVal != kStatus_Success)
		{
			return -1;
		}
	}

	uint32_t temperatureValue = 0;

	// NXP's LM75B data sheet shows the format of the data https://www.nxp.com/docs/en/data-sheet/LM75B.pdf
	if ((g_master_rxBuff[0] &amp;amp; 0x80) &amp;gt; 0) {  // This is the sign bit
		temperatureValue = 0xffffff00;
	}

	temperatureValue |= (g_master_rxBuff[0] &amp;amp; 0x7f) &amp;lt;&amp;lt; 1;
	temperatureValue |= ((g_master_rxBuff[1] &amp;gt;&amp;gt; 7) &amp;amp; 1);

	// Since we're not using the half degrees, just shift right by one and lose that piece of data
	temperatureValue = temperatureValue &amp;gt;&amp;gt; 1;

	return(temperatureValue);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code we added in &lt;STRONG&gt;main()&lt;/STRONG&gt; already called &lt;STRONG&gt;init_LM75()&lt;/STRONG&gt; and you just need to call &lt;STRONG&gt;read_LM75()&lt;/STRONG&gt; when you want to read the temperature.&amp;nbsp; (&lt;EM&gt;You may not need to call &lt;STRONG&gt;init_LM75()&lt;/STRONG&gt; as the sensor seems to startup in the correct mode to begin with.&lt;/EM&gt;)&amp;nbsp; My demo program just calls &lt;STRONG&gt;read_LM75()&lt;/STRONG&gt; from a one second interval&amp;nbsp;&lt;STRONG&gt;SysTick_Handler()&lt;/STRONG&gt; and uses this code to display the value:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;	int32_t temperatureReading = read_LM75();
	char console_string[128];

	// Bit 16 is the sign (1 is negative, 0 is positive) after the temperature conversion
	if (temperatureReading &amp;amp; 0x10000) {
		snprintf(console_string, 128, "Current temperature is -%d degrees C.\r\n", (temperatureReading &amp;amp; 0xFFFF));
	}
	else {
		uint16_t temperature_farenheit = (temperatureReading * 9 / 5) + 32;  // Create the farenheit temperature value for positive temperatures
		snprintf(console_string, 128, "Current temperature is %d degrees C and %d degrees F.\r\n", temperatureReading, temperature_farenheit);
	}

	PutTerminalString(USART0, (unsigned char *)console_string);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not doing much in the way of checking return values, but you should get the idea.&amp;nbsp; The &lt;STRONG&gt;PutTerminalString()&lt;/STRONG&gt; function above is just a function that I'm using to send the string out on the USART0 port that I'm using.&amp;nbsp; Replace it with whatever diagnostic print that you're using.&lt;/P&gt;&lt;P&gt;Enjoy!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 17:25:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/1718177#M15609</guid>
      <dc:creator>jrevans</dc:creator>
      <dc:date>2023-09-06T17:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: I2C communication issue</title>
      <link>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/2339085#M20330</link>
      <description>&lt;P&gt;The I2C_MasterTransferBlocking function can be used for receiving. Example code:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;static status_t I2C_Write(handle_t *handle, uint16_t memAddr,
                                     const uint8_t *data, uint32_t dataLen)
{
    i2c_master_transfer_t xfer;
    status_t status;

    memset(&amp;amp;xfer, 0, sizeof(xfer));

    xfer.slaveAddress   = handle-&amp;gt;slaveAddress;
    xfer.direction      = kI2C_Write;
    xfer.subaddress     = (uint32_t)memAddr;
    xfer.subaddressSize = ADDR_SIZE;
    xfer.data           = (uint8_t *)data;
    xfer.dataSize       = dataLen;
    xfer.flags          = kI2C_TransferDefaultFlag;

    status = I2C_MasterTransferBlocking(handle-&amp;gt;i2cBase, &amp;amp;xfer);

    return ConvertStatus(status);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The key point is "direction"&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 08:47:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Wireless-MCU/I2C-communication-issue/m-p/2339085#M20330</guid>
      <dc:creator>maliunal</dc:creator>
      <dc:date>2026-03-25T08:47:40Z</dc:date>
    </item>
  </channel>
</rss>

