<?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>topic Re: LPC55 Flexcomm5 I2C in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1284608#M45234</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;SPAN&gt;christian&lt;/SPAN&gt;&lt;SPAN&gt;lees,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Recommend you first refer to the I2C demo under SDK:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://mcuxpresso.nxp.com/en/builder?hw=LPCXpresso55S06" target="_blank"&gt;https://mcuxpresso.nxp.com/en/builder?hw=LPCXpresso55S06&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Alice_Yang_0-1622448039750.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/145866iE4940D0D33CEDC8D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Alice_Yang_0-1622448039750.png" alt="Alice_Yang_0-1622448039750.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 31 May 2021 08:01:06 GMT</pubDate>
    <dc:creator>Alice_Yang</dc:creator>
    <dc:date>2021-05-31T08:01:06Z</dc:date>
    <item>
      <title>LPC55 Flexcomm5 I2C</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1283906#M45200</link>
      <description>&lt;P&gt;For some reason I can't get an I2C interface to work on Flexcomm5 on an LPC5506.&lt;/P&gt;&lt;P&gt;I have double checked my code, most of it was generated by the pin and peripheral tools inside MCUXpresso.&amp;nbsp; The SDA and SCL lines never get driven low.&amp;nbsp; I have verified my PCB by changing them to GPIO and making sure they can go low.&lt;/P&gt;&lt;P&gt;I have also tried using the polling method with the same results, no action on the SDA and SCL lines.&amp;nbsp; I have 10k pull up resistors.&lt;/P&gt;&lt;P&gt;Any help will be appreciated&lt;/P&gt;&lt;P&gt;From perhipherals.c&lt;/P&gt;&lt;LI-CODE lang="c"&gt; **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'I2C'
- type: 'flexcomm_i2c'
- mode: 'I2C_Transfer'
- custom_name_enabled: 'true'
- type_id: 'flexcomm_i2c_567d1a9d97c12e5d39b00259c3436dc4'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'FLEXCOMM5'
- config_sets:
  - transferCfg:
    - transfer:
      - init_callback: 'true'
      - callback_fcn: 'I2C_callback'
      - user_data: ''
      - init_transfer: 'false'
      - master_transfer_cfg:
        - flags: 'kI2C_TransferDefaultFlag'
        - slaveAddress: '0'
        - direction: 'kI2C_Write'
        - subaddressSize: '0'
        - subaddress: '0'
        - dataSize: '32'
  - fsl_i2c:
    - i2c_mode: 'kI2C_Master'
    - clockSource: 'FXCOMFunctionClock'
    - clockSourceFreq: 'BOARD_BootClockFRO12M'
    - i2c_master_config:
      - enableMaster: 'true'
      - baudRate_Bps: '100000'
      - enableTimeout: 'true'
    - interrupt_priority:
      - IRQn: 'FLEXCOMM5_IRQn'
      - enable_priority: 'false'
      - priority: '5'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const i2c_master_config_t I2C_config = {
  .enableMaster = true,
  .baudRate_Bps = 100000UL,
  .enableTimeout = true
};
i2c_master_handle_t I2C_handle;

static void I2C_init(void) {
  RESET_PeripheralReset( kFC5_RST_SHIFT_RSTn);
  /* Initialization function */
  I2C_MasterInit(I2C_PERIPHERAL, &amp;amp;I2C_config, I2C_CLOCK_SOURCE);
  memset(&amp;amp;I2C_handle, 0, sizeof(I2C_handle));
  I2C_MasterTransferCreateHandle(I2C_PERIPHERAL, &amp;amp;I2C_handle, I2C_callback, NULL);
}&lt;/LI-CODE&gt;&lt;P&gt;Peripherals.h&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* BOARD_InitPeripherals defines for FLEXCOMM5 */
/* Definition of peripheral ID */
#define I2C_PERIPHERAL ((I2C_Type *)FLEXCOMM5)
/* Definition of the clock source frequency */
#define I2C_CLOCK_SOURCE 8000000UL
/* I2C interrupt vector ID (number). */
#define I2C_FLEXCOMM_IRQN FLEXCOMM5_IRQn&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I2C routines&lt;/P&gt;&lt;LI-CODE lang="c"&gt;uint8_t completion_flag;
uint8_t nak_flag;

void I2C_callback(I2C_Type *base, i2c_master_handle_t *handle, status_t status, void *userData)
{
    /* Signal transfer success when received success status. */
    if (status == kStatus_Success)
    {
        completion_flag = true;
    }
    /* Signal transfer success when received success status. */
    if ((status == kStatus_I2C_Nak))
    {
        nak_flag = true;
    }
}

uint8_t i2c_wait(int timeout)
{
	uint32_t start_time = tick_counter;
	while(1)
	{

		if(start_time + timeout &amp;gt; start_time)
		{
			if((start_time + timeout) &amp;lt; tick_counter)
				break;
		}
		else
		{
			if((start_time + timeout) &amp;lt; tick_counter &amp;amp;&amp;amp; tick_counter &amp;lt; (4294967295 - timeout))
				break;
		}

		if(completion_flag)
			return 0;
	}

	return 1;
}

uint8_t i2c_write(uint8_t addr, uint16_t sub_addr, uint8_t sub_addr_len, uint8_t *d, uint8_t len, int timeout)
{
	i2c_master_transfer_t i2c_transfer;
	memset(&amp;amp;i2c_transfer, 0, sizeof(i2c_transfer));
	i2c_transfer.slaveAddress = addr;
	i2c_transfer.direction = kI2C_Write;
	i2c_transfer.subaddress = sub_addr;
	i2c_transfer.subaddressSize = sub_addr_len;
	i2c_transfer.data = d;
	i2c_transfer.dataSize = len;
	i2c_transfer.flags = kI2C_TransferDefaultFlag;

	completion_flag = false;
	nak_flag = false;
	I2C_MasterTransferNonBlocking(I2C_PERIPHERAL, &amp;amp;I2C_handle, &amp;amp;i2c_transfer);

	if(i2c_wait(timeout))
		return 1;
	else
		return 0;
}


uint8_t i2c_read(uint8_t addr, uint16_t sub_addr, uint8_t sub_addr_len, uint8_t *d, uint8_t len, int timeout)
{
	i2c_master_transfer_t i2c_transfer;
	memset(&amp;amp;i2c_transfer, 0, sizeof(i2c_transfer));
	i2c_transfer.slaveAddress = addr;
	i2c_transfer.direction = kI2C_Read;
	i2c_transfer.subaddress = sub_addr;
	i2c_transfer.subaddressSize = sub_addr_len;
	i2c_transfer.data = d;
	i2c_transfer.dataSize = len;
	i2c_transfer.flags = kI2C_TransferDefaultFlag;

	completion_flag = false;
	nak_flag = false;
	I2C_MasterTransferNonBlocking(I2C_PERIPHERAL, &amp;amp;I2C_handle, &amp;amp;i2c_transfer);

	if(i2c_wait(timeout))
		return 1;
	else
		return 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 06:18:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1283906#M45200</guid>
      <dc:creator>christianlees</dc:creator>
      <dc:date>2021-05-28T06:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55 Flexcomm5 I2C</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1284608#M45234</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;SPAN&gt;christian&lt;/SPAN&gt;&lt;SPAN&gt;lees,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Recommend you first refer to the I2C demo under SDK:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://mcuxpresso.nxp.com/en/builder?hw=LPCXpresso55S06" target="_blank"&gt;https://mcuxpresso.nxp.com/en/builder?hw=LPCXpresso55S06&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Alice_Yang_0-1622448039750.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/145866iE4940D0D33CEDC8D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Alice_Yang_0-1622448039750.png" alt="Alice_Yang_0-1622448039750.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 08:01:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1284608#M45234</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2021-05-31T08:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55 Flexcomm5 I2C</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1285657#M45251</link>
      <description>&lt;P&gt;Alice,&lt;/P&gt;&lt;P&gt;I did that and it worked.&amp;nbsp; But if I start a new project, use the supplies gui tools for setting the clocks and pins and then use the simplest I2C code it still doesn't work.&amp;nbsp; &amp;nbsp;A solution is to not use the GUI tools for this part of my code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 23:03:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1285657#M45251</guid>
      <dc:creator>christianlees</dc:creator>
      <dc:date>2021-06-01T23:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55 Flexcomm5 I2C</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1287139#M45277</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;SPAN&gt;christianlees,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The MCUXpressso config GUI not generate all the related code, you can compare the generated code with demo project code, check which code you need to add .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;BR&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Alice&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 01:46:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55-Flexcomm5-I2C/m-p/1287139#M45277</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2021-06-04T01:46:08Z</dc:date>
    </item>
  </channel>
</rss>

