<?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 i2c reading problem in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/i2c-reading-problem/m-p/909966#M36437</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i am using LPC824 MCUXPRESSO IDE&amp;nbsp; &amp;nbsp; i need to read 16 bit adc but in lpc824 having only 12 bit so thats why i got external adc ADS1115 module this I2C based module . i try to read this o/p till 1 month but i don't know why i am facing this problem . i asked lot of time in NXP community but didn't got correct answer still . used in ardiuno uno for testing purpose in ardiuno controller ADS1115 O/P getting correctly please let me know the solution what i did the mistake in my code in below provided the code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my controller working frequency is 12mhz&amp;nbsp; AND i2c_freq i set 30mhz and 400khz speed&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt; * Copyright (c) 2016, Freescale Semiconductor, Inc.&lt;BR /&gt; * Copyright 2016-2019 NXP&lt;BR /&gt; * All rights reserved.&lt;BR /&gt; *&lt;BR /&gt; * SPDX-License-Identifier: BSD-3-Clause&lt;BR /&gt; */&lt;/P&gt;&lt;P&gt;/* Standard C Included Files */&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "fsl_debug_console.h"&lt;BR /&gt;#include "fsl_i2c.h"&lt;BR /&gt;#include "fsl_i2c.h"&lt;BR /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include "pin_mux.h"&lt;BR /&gt;#include "fsl_device_registers.h"&lt;BR /&gt;#include "fsl_common.h"&lt;BR /&gt;#include"lpc8xx_i2c.h"&lt;BR /&gt;#include"fsl_usart.h"&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Definitions&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;#define START_BYTE "START_BYTE\n\r"&lt;BR /&gt;#define SEPERATE_BYTE "-"&lt;BR /&gt;#define STOP_BYTE "STOP_BYTE\n\r"&lt;BR /&gt;#define atcmd "AT"&lt;BR /&gt;uint8_t F_DEMOCHECK[] = "4096";&lt;BR /&gt;uint8_t s_identifier[] = "SPEEDTECH";&lt;BR /&gt;uint8_t g_demoInfo[] = " IOT CHECKING............\r\n";&lt;BR /&gt;uint8_t A_sensor1[] = " ADC_1 SENSOR_READING:\r\n";&lt;BR /&gt;uint8_t A_sensor2[] = " ADC_2 SENSOR_READING:\r\n";&lt;BR /&gt;uint8_t A_sensor3[] = " ADC_3 SENSOR_READING:\r\n";&lt;BR /&gt;uint8_t A_sensor4[] = " ADC_4 SENSOR_READING:\r\n";&lt;BR /&gt;uint8_t g_logInfo[] = "The received characters are:";&lt;BR /&gt;uint8_t g_overFlowInfo[] = "\r\nYou have input too many characters, Please try again!\r\n";&lt;BR /&gt;uint8_t g_checking[] = "\r\n condition stopped before the while loop ...!\r\n";&lt;/P&gt;&lt;P&gt;#define EXAMPLE_USART USART0&lt;BR /&gt;#define EXAMPLE_USART1 USART1&lt;BR /&gt;#define EXAMPLE_USART_CLK_SRC kCLOCK_MainClk&lt;BR /&gt;#define EXAMPLE_USART_CLK_FREQ CLOCK_GetFreq(EXAMPLE_USART_CLK_SRC)&lt;BR /&gt;#define EXAMPLE_USART_IRQn USART0_IRQn&lt;/P&gt;&lt;P&gt;#define EXAMPLE_I2C_MASTER_BASE (I2C0_BASE)&lt;BR /&gt;#define I2C_MASTER_CLOCK_FREQUENCY (30000000)&lt;BR /&gt;#define WAIT_TIME 10U&lt;BR /&gt;#define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE)&lt;/P&gt;&lt;P&gt;#define Self_Slave_address 0x48U&lt;BR /&gt; #define ADS1015_REG_POINTER_MASK (0x03)&lt;BR /&gt; #define ADS1015_REG_POINTER_CONVERT (0x00)&lt;BR /&gt; #define ADS1015_REG_POINTER_CONFIG (0x01)&lt;BR /&gt; #define ADS1015_REG_POINTER_LOWTHRESH (0x02)&lt;BR /&gt; #define ADS1015_REG_POINTER_HITHRESH (0x03)&lt;BR /&gt; #define config_high 0xD1&lt;BR /&gt; #define config_low 0x83&lt;BR /&gt; #define config_line 0x0083&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#define BOARD_LED_PORT 0U&lt;BR /&gt;#define BOARD_LED_PIN 23U&lt;BR /&gt;static void EXAMPLE_USARTInit(void);&lt;BR /&gt;void delay_ms(int a);&lt;BR /&gt; int main(void)&lt;BR /&gt; {&lt;BR /&gt; unsigned int msb_byte,lsb_byte,msb=5,lsb=9;&lt;BR /&gt; unsigned char * tx_ptr;&lt;BR /&gt; unsigned int temp1=5009;&lt;BR /&gt; gpio_pin_config_t led_config = {&lt;BR /&gt; kGPIO_DigitalOutput,&lt;BR /&gt; 0,&lt;BR /&gt; };&lt;/P&gt;&lt;P&gt;GPIO_PortInit(GPIO, BOARD_LED_PORT);&lt;BR /&gt; GPIO_PinInit(GPIO, BOARD_LED_PORT, BOARD_LED_PIN, &amp;amp;led_config);&lt;BR /&gt; // i2c_master_config_t masterConfig;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; /* Enable clock of uart0. */&lt;BR /&gt; CLOCK_EnableClock(kCLOCK_Uart0);&lt;BR /&gt; /* Ser DIV of uart0. */&lt;BR /&gt; CLOCK_SetClkDivider(kCLOCK_DivUsartClk, 1U);&lt;BR /&gt; /* Enable clock of I2C0. */&lt;BR /&gt; CLOCK_EnableClock(kCLOCK_Uart1);&lt;BR /&gt; /* Ser DIV of uart0. */&lt;BR /&gt; CLOCK_SetClkDivider(kCLOCK_DivUsartClk, 1U);&lt;BR /&gt; /* Enable clock of I2C0. */&lt;BR /&gt; CLOCK_EnableClock( kCLOCK_I2c0 );&lt;/P&gt;&lt;P&gt;BOARD_InitPins();&lt;BR /&gt; BOARD_BootClockIRC12M();&lt;BR /&gt; BOARD_InitDebugConsole();&lt;BR /&gt; EXAMPLE_USARTInit();&lt;BR /&gt; SYSCON-&amp;gt;PRESETCTRL &amp;amp;= (I2C0_RST_N);&lt;BR /&gt; SYSCON-&amp;gt;PRESETCTRL |= ~(I2C0_RST_N);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; // Configure the I2C0 clock divider&lt;BR /&gt; // Desired bit rate = Fscl = 100,000 Hz (1/Fscl = 10 us, 5 us low and 5 us high)&lt;BR /&gt; // Use default clock high and clock low times (= 2 clocks each)&lt;BR /&gt; // So 4 I2C_PCLKs = 100,000/second, or 1 I2C_PCLK = 400,000/second&lt;BR /&gt; // I2C_PCLK = SystemClock = 30,000,000/second, so we divide by 30/.4 = 75&lt;BR /&gt; // Remember, value written to DIV divides by value+1&lt;/P&gt;&lt;P&gt;I2C0-&amp;gt;CLKDIV = (75-1);&lt;BR /&gt; I2C0-&amp;gt;CFG = CFG_MSTENA ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; WaitI2CMasterState(STAT_MSTIDLE ); // CHECKING MASTER IS IDLE&lt;BR /&gt; // I2C0-&amp;gt;INTENSET = STAT_MSTPEND|STAT_SLVPEND ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//////////////////////////// configuration bits write to ads1115 //////////////////////////////////////////////////////&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTART; // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = (Self_Slave_address&amp;lt;&amp;lt;1) | 0; // Address with 0 for RWn bit (WRITE)&lt;BR /&gt; WaitI2CMasterState(I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = ADS1015_REG_POINTER_CONFIG; // Address with 0 for RWn bit (WRITE)&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // MASTER CONTINUE THE TRANSCATION&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = config_high; // Address with 0 for RWn bit (WRITE) config&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // MASTER CONTINUE THE TRANSCATION&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd&lt;BR /&gt; I2C0-&amp;gt;MSTDAT =config_low; // Address with 0 for RWn bit (WRITE) config&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // MASTER CONTINUE THE TRANSCATION&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction&lt;BR /&gt; WaitI2CMasterState(STAT_MSTIDLE ); // checking idle state&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// //////////////////////////// convertion bits write to ads1115 //////////////////////////////////////////////////////&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTART; // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = (Self_Slave_address&amp;lt;&amp;lt;1) | 0; // Address with 0 for RWn bit (write)&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = ADS1015_REG_POINTER_CONVERT; // SENDING THE COVERSION REG BITS&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // MASTER CONTINUE THE TRANSCATION&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction&lt;BR /&gt; WaitI2CMasterState(STAT_MSTIDLE ); // CHECKING MASTER IS IDLE&lt;/P&gt;&lt;P&gt;I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE;&lt;BR /&gt; while(1)&lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;GPIO_PortToggle(GPIO, BOARD_LED_PORT, 1u &amp;lt;&amp;lt; BOARD_LED_PIN);&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART, START_BYTE , (sizeof( START_BYTE ))-1); // SEPERATE BYTE '-&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART1, atcmd , (sizeof( atcmd ))-1); // SEPERATE BYTE '-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/////////////////////////// convertion bits read from ads1115 //////////////////////////////////////////////////////&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = (Self_Slave_address&amp;lt;&amp;lt;1) | 1; // Address with 0 for RWn bit (read)&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTART;&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; msb_byte = I2C0-&amp;gt;MSTDAT; // Read the data&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE;&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; lsb_byte = I2C0-&amp;gt;MSTDAT; // Read the data&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE;&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; USART_WriteBlocking1(EXAMPLE_USART, msb_byte, lsb_byte ); // SEPERATE BYTE '-&lt;BR /&gt; USART_WriteBlocking2(EXAMPLE_USART, lsb_byte ); // SEPERATE BYTE '-&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; USART_WriteBlocking2(EXAMPLE_USART, msb_byte ) ; // SEPERATE BYTE '-&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART, STOP_BYTE , (sizeof( STOP_BYTE ))-1); // SEPERATE BYTE '-&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTOP;&lt;/P&gt;&lt;P&gt;// delay_ms(100);&lt;/P&gt;&lt;P&gt;// slave_rx_data[slave_data_counter++] = temp; // Store it in the array, increment counter&lt;/P&gt;&lt;P&gt;// WaitI2CMasterState(I2C0, I2C_STAT_MSTST_RX); // Wait for the data to be ACK'd&lt;BR /&gt; // NVIC_EnableIRQ(I2C0_IRQn);&lt;BR /&gt; // Send a stop to end the transaction&lt;BR /&gt;//PutTerminalString(LPC_USART0, (uint8_t *)stop_bit);// Print a massage&lt;BR /&gt;//delay_ms(100);&lt;BR /&gt;} // end of while 1&lt;/P&gt;&lt;P&gt;} // end of main&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; void delay_ms(int a)&lt;BR /&gt; {&lt;BR /&gt; int i,j;&lt;BR /&gt; for(i=0;i&amp;lt;a;i++)&lt;BR /&gt; for(j=0;j&amp;lt;a;j++);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;/////////////////////////////////////&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;static void EXAMPLE_USARTInit(void)&lt;BR /&gt; {&lt;BR /&gt; usart_config_t config;&lt;BR /&gt; /* Default config by using USART_GetDefaultConfig():&lt;BR /&gt; * config.baudRate_Bps = 9600U;&lt;BR /&gt; * config.parityMode = kUSART_ParityDisabled;&lt;BR /&gt; * config.stopBitCount = kUSART_OneStopBit;&lt;BR /&gt; * config.bitCountPerChar = kUSART_8BitsPerChar;&lt;BR /&gt; * config.loopback = false;&lt;BR /&gt; * config.enableRx = false;&lt;BR /&gt; * config.enableTx = false;&lt;BR /&gt; * config.syncMode = kUSART_SyncModeDisabled;&lt;BR /&gt; */&lt;BR /&gt; USART_GetDefaultConfig(&amp;amp;config);&lt;BR /&gt; config.enableRx = true;&lt;BR /&gt; config.enableTx = true;&lt;BR /&gt; config.baudRate_Bps = BOARD_DEBUG_USART_BAUDRATE;&lt;/P&gt;&lt;P&gt;/* Initialize the USART with configuration. */&lt;BR /&gt; USART_Init(EXAMPLE_USART, &amp;amp;config, EXAMPLE_USART_CLK_FREQ);&lt;BR /&gt; USART_Init(EXAMPLE_USART1, &amp;amp;config, EXAMPLE_USART_CLK_FREQ);&lt;BR /&gt; /* Send demo info and prompt info out to terminal in blocking way. */&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART, g_demoInfo, (sizeof(g_demoInfo) / sizeof(g_demoInfo[0])) - 1);&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART1, g_demoInfo, (sizeof(g_demoInfo) / sizeof(g_demoInfo[0])) - 1);&lt;/P&gt;&lt;P&gt;EnableIRQ(EXAMPLE_USART_IRQn);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&amp;amp; Regards&lt;/P&gt;&lt;P&gt;Aravind P&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Jul 2019 13:27:30 GMT</pubDate>
    <dc:creator>aravindpb5009</dc:creator>
    <dc:date>2019-07-26T13:27:30Z</dc:date>
    <item>
      <title>i2c reading problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/i2c-reading-problem/m-p/909966#M36437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i am using LPC824 MCUXPRESSO IDE&amp;nbsp; &amp;nbsp; i need to read 16 bit adc but in lpc824 having only 12 bit so thats why i got external adc ADS1115 module this I2C based module . i try to read this o/p till 1 month but i don't know why i am facing this problem . i asked lot of time in NXP community but didn't got correct answer still . used in ardiuno uno for testing purpose in ardiuno controller ADS1115 O/P getting correctly please let me know the solution what i did the mistake in my code in below provided the code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my controller working frequency is 12mhz&amp;nbsp; AND i2c_freq i set 30mhz and 400khz speed&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt; * Copyright (c) 2016, Freescale Semiconductor, Inc.&lt;BR /&gt; * Copyright 2016-2019 NXP&lt;BR /&gt; * All rights reserved.&lt;BR /&gt; *&lt;BR /&gt; * SPDX-License-Identifier: BSD-3-Clause&lt;BR /&gt; */&lt;/P&gt;&lt;P&gt;/* Standard C Included Files */&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "fsl_debug_console.h"&lt;BR /&gt;#include "fsl_i2c.h"&lt;BR /&gt;#include "fsl_i2c.h"&lt;BR /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;#include "pin_mux.h"&lt;BR /&gt;#include "fsl_device_registers.h"&lt;BR /&gt;#include "fsl_common.h"&lt;BR /&gt;#include"lpc8xx_i2c.h"&lt;BR /&gt;#include"fsl_usart.h"&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Definitions&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;#define START_BYTE "START_BYTE\n\r"&lt;BR /&gt;#define SEPERATE_BYTE "-"&lt;BR /&gt;#define STOP_BYTE "STOP_BYTE\n\r"&lt;BR /&gt;#define atcmd "AT"&lt;BR /&gt;uint8_t F_DEMOCHECK[] = "4096";&lt;BR /&gt;uint8_t s_identifier[] = "SPEEDTECH";&lt;BR /&gt;uint8_t g_demoInfo[] = " IOT CHECKING............\r\n";&lt;BR /&gt;uint8_t A_sensor1[] = " ADC_1 SENSOR_READING:\r\n";&lt;BR /&gt;uint8_t A_sensor2[] = " ADC_2 SENSOR_READING:\r\n";&lt;BR /&gt;uint8_t A_sensor3[] = " ADC_3 SENSOR_READING:\r\n";&lt;BR /&gt;uint8_t A_sensor4[] = " ADC_4 SENSOR_READING:\r\n";&lt;BR /&gt;uint8_t g_logInfo[] = "The received characters are:";&lt;BR /&gt;uint8_t g_overFlowInfo[] = "\r\nYou have input too many characters, Please try again!\r\n";&lt;BR /&gt;uint8_t g_checking[] = "\r\n condition stopped before the while loop ...!\r\n";&lt;/P&gt;&lt;P&gt;#define EXAMPLE_USART USART0&lt;BR /&gt;#define EXAMPLE_USART1 USART1&lt;BR /&gt;#define EXAMPLE_USART_CLK_SRC kCLOCK_MainClk&lt;BR /&gt;#define EXAMPLE_USART_CLK_FREQ CLOCK_GetFreq(EXAMPLE_USART_CLK_SRC)&lt;BR /&gt;#define EXAMPLE_USART_IRQn USART0_IRQn&lt;/P&gt;&lt;P&gt;#define EXAMPLE_I2C_MASTER_BASE (I2C0_BASE)&lt;BR /&gt;#define I2C_MASTER_CLOCK_FREQUENCY (30000000)&lt;BR /&gt;#define WAIT_TIME 10U&lt;BR /&gt;#define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE)&lt;/P&gt;&lt;P&gt;#define Self_Slave_address 0x48U&lt;BR /&gt; #define ADS1015_REG_POINTER_MASK (0x03)&lt;BR /&gt; #define ADS1015_REG_POINTER_CONVERT (0x00)&lt;BR /&gt; #define ADS1015_REG_POINTER_CONFIG (0x01)&lt;BR /&gt; #define ADS1015_REG_POINTER_LOWTHRESH (0x02)&lt;BR /&gt; #define ADS1015_REG_POINTER_HITHRESH (0x03)&lt;BR /&gt; #define config_high 0xD1&lt;BR /&gt; #define config_low 0x83&lt;BR /&gt; #define config_line 0x0083&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#define BOARD_LED_PORT 0U&lt;BR /&gt;#define BOARD_LED_PIN 23U&lt;BR /&gt;static void EXAMPLE_USARTInit(void);&lt;BR /&gt;void delay_ms(int a);&lt;BR /&gt; int main(void)&lt;BR /&gt; {&lt;BR /&gt; unsigned int msb_byte,lsb_byte,msb=5,lsb=9;&lt;BR /&gt; unsigned char * tx_ptr;&lt;BR /&gt; unsigned int temp1=5009;&lt;BR /&gt; gpio_pin_config_t led_config = {&lt;BR /&gt; kGPIO_DigitalOutput,&lt;BR /&gt; 0,&lt;BR /&gt; };&lt;/P&gt;&lt;P&gt;GPIO_PortInit(GPIO, BOARD_LED_PORT);&lt;BR /&gt; GPIO_PinInit(GPIO, BOARD_LED_PORT, BOARD_LED_PIN, &amp;amp;led_config);&lt;BR /&gt; // i2c_master_config_t masterConfig;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; /* Enable clock of uart0. */&lt;BR /&gt; CLOCK_EnableClock(kCLOCK_Uart0);&lt;BR /&gt; /* Ser DIV of uart0. */&lt;BR /&gt; CLOCK_SetClkDivider(kCLOCK_DivUsartClk, 1U);&lt;BR /&gt; /* Enable clock of I2C0. */&lt;BR /&gt; CLOCK_EnableClock(kCLOCK_Uart1);&lt;BR /&gt; /* Ser DIV of uart0. */&lt;BR /&gt; CLOCK_SetClkDivider(kCLOCK_DivUsartClk, 1U);&lt;BR /&gt; /* Enable clock of I2C0. */&lt;BR /&gt; CLOCK_EnableClock( kCLOCK_I2c0 );&lt;/P&gt;&lt;P&gt;BOARD_InitPins();&lt;BR /&gt; BOARD_BootClockIRC12M();&lt;BR /&gt; BOARD_InitDebugConsole();&lt;BR /&gt; EXAMPLE_USARTInit();&lt;BR /&gt; SYSCON-&amp;gt;PRESETCTRL &amp;amp;= (I2C0_RST_N);&lt;BR /&gt; SYSCON-&amp;gt;PRESETCTRL |= ~(I2C0_RST_N);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; // Configure the I2C0 clock divider&lt;BR /&gt; // Desired bit rate = Fscl = 100,000 Hz (1/Fscl = 10 us, 5 us low and 5 us high)&lt;BR /&gt; // Use default clock high and clock low times (= 2 clocks each)&lt;BR /&gt; // So 4 I2C_PCLKs = 100,000/second, or 1 I2C_PCLK = 400,000/second&lt;BR /&gt; // I2C_PCLK = SystemClock = 30,000,000/second, so we divide by 30/.4 = 75&lt;BR /&gt; // Remember, value written to DIV divides by value+1&lt;/P&gt;&lt;P&gt;I2C0-&amp;gt;CLKDIV = (75-1);&lt;BR /&gt; I2C0-&amp;gt;CFG = CFG_MSTENA ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; WaitI2CMasterState(STAT_MSTIDLE ); // CHECKING MASTER IS IDLE&lt;BR /&gt; // I2C0-&amp;gt;INTENSET = STAT_MSTPEND|STAT_SLVPEND ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//////////////////////////// configuration bits write to ads1115 //////////////////////////////////////////////////////&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTART; // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = (Self_Slave_address&amp;lt;&amp;lt;1) | 0; // Address with 0 for RWn bit (WRITE)&lt;BR /&gt; WaitI2CMasterState(I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = ADS1015_REG_POINTER_CONFIG; // Address with 0 for RWn bit (WRITE)&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // MASTER CONTINUE THE TRANSCATION&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = config_high; // Address with 0 for RWn bit (WRITE) config&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // MASTER CONTINUE THE TRANSCATION&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd&lt;BR /&gt; I2C0-&amp;gt;MSTDAT =config_low; // Address with 0 for RWn bit (WRITE) config&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // MASTER CONTINUE THE TRANSCATION&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction&lt;BR /&gt; WaitI2CMasterState(STAT_MSTIDLE ); // checking idle state&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// //////////////////////////// convertion bits write to ads1115 //////////////////////////////////////////////////////&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTART; // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = (Self_Slave_address&amp;lt;&amp;lt;1) | 0; // Address with 0 for RWn bit (write)&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = ADS1015_REG_POINTER_CONVERT; // SENDING THE COVERSION REG BITS&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // MASTER CONTINUE THE TRANSCATION&lt;BR /&gt; delay_ms(200);&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction&lt;BR /&gt; WaitI2CMasterState(STAT_MSTIDLE ); // CHECKING MASTER IS IDLE&lt;/P&gt;&lt;P&gt;I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE;&lt;BR /&gt; while(1)&lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;GPIO_PortToggle(GPIO, BOARD_LED_PORT, 1u &amp;lt;&amp;lt; BOARD_LED_PIN);&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART, START_BYTE , (sizeof( START_BYTE ))-1); // SEPERATE BYTE '-&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART1, atcmd , (sizeof( atcmd ))-1); // SEPERATE BYTE '-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/////////////////////////// convertion bits read from ads1115 //////////////////////////////////////////////////////&lt;BR /&gt; I2C0-&amp;gt;MSTDAT = (Self_Slave_address&amp;lt;&amp;lt;1) | 1; // Address with 0 for RWn bit (read)&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTART;&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; msb_byte = I2C0-&amp;gt;MSTDAT; // Read the data&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE;&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; lsb_byte = I2C0-&amp;gt;MSTDAT; // Read the data&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE;&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; USART_WriteBlocking1(EXAMPLE_USART, msb_byte, lsb_byte ); // SEPERATE BYTE '-&lt;BR /&gt; USART_WriteBlocking2(EXAMPLE_USART, lsb_byte ); // SEPERATE BYTE '-&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; USART_WriteBlocking2(EXAMPLE_USART, msb_byte ) ; // SEPERATE BYTE '-&lt;BR /&gt; delay_ms(500);&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART, STOP_BYTE , (sizeof( STOP_BYTE ))-1); // SEPERATE BYTE '-&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTOP;&lt;/P&gt;&lt;P&gt;// delay_ms(100);&lt;/P&gt;&lt;P&gt;// slave_rx_data[slave_data_counter++] = temp; // Store it in the array, increment counter&lt;/P&gt;&lt;P&gt;// WaitI2CMasterState(I2C0, I2C_STAT_MSTST_RX); // Wait for the data to be ACK'd&lt;BR /&gt; // NVIC_EnableIRQ(I2C0_IRQn);&lt;BR /&gt; // Send a stop to end the transaction&lt;BR /&gt;//PutTerminalString(LPC_USART0, (uint8_t *)stop_bit);// Print a massage&lt;BR /&gt;//delay_ms(100);&lt;BR /&gt;} // end of while 1&lt;/P&gt;&lt;P&gt;} // end of main&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; void delay_ms(int a)&lt;BR /&gt; {&lt;BR /&gt; int i,j;&lt;BR /&gt; for(i=0;i&amp;lt;a;i++)&lt;BR /&gt; for(j=0;j&amp;lt;a;j++);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;/////////////////////////////////////&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;static void EXAMPLE_USARTInit(void)&lt;BR /&gt; {&lt;BR /&gt; usart_config_t config;&lt;BR /&gt; /* Default config by using USART_GetDefaultConfig():&lt;BR /&gt; * config.baudRate_Bps = 9600U;&lt;BR /&gt; * config.parityMode = kUSART_ParityDisabled;&lt;BR /&gt; * config.stopBitCount = kUSART_OneStopBit;&lt;BR /&gt; * config.bitCountPerChar = kUSART_8BitsPerChar;&lt;BR /&gt; * config.loopback = false;&lt;BR /&gt; * config.enableRx = false;&lt;BR /&gt; * config.enableTx = false;&lt;BR /&gt; * config.syncMode = kUSART_SyncModeDisabled;&lt;BR /&gt; */&lt;BR /&gt; USART_GetDefaultConfig(&amp;amp;config);&lt;BR /&gt; config.enableRx = true;&lt;BR /&gt; config.enableTx = true;&lt;BR /&gt; config.baudRate_Bps = BOARD_DEBUG_USART_BAUDRATE;&lt;/P&gt;&lt;P&gt;/* Initialize the USART with configuration. */&lt;BR /&gt; USART_Init(EXAMPLE_USART, &amp;amp;config, EXAMPLE_USART_CLK_FREQ);&lt;BR /&gt; USART_Init(EXAMPLE_USART1, &amp;amp;config, EXAMPLE_USART_CLK_FREQ);&lt;BR /&gt; /* Send demo info and prompt info out to terminal in blocking way. */&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART, g_demoInfo, (sizeof(g_demoInfo) / sizeof(g_demoInfo[0])) - 1);&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART1, g_demoInfo, (sizeof(g_demoInfo) / sizeof(g_demoInfo[0])) - 1);&lt;/P&gt;&lt;P&gt;EnableIRQ(EXAMPLE_USART_IRQn);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&amp;amp; Regards&lt;/P&gt;&lt;P&gt;Aravind P&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jul 2019 13:27:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/i2c-reading-problem/m-p/909966#M36437</guid>
      <dc:creator>aravindpb5009</dc:creator>
      <dc:date>2019-07-26T13:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: i2c reading problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/i2c-reading-problem/m-p/909967#M36438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My partner is already looking for this in the following thread, she will answer your questions there:&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/thread/508031"&gt;https://community.nxp.com/thread/508031&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Alexis Andalon&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jul 2019 00:14:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/i2c-reading-problem/m-p/909967#M36438</guid>
      <dc:creator>Alexis_A</dc:creator>
      <dc:date>2019-07-31T00:14:41Z</dc:date>
    </item>
  </channel>
</rss>

