<?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>LPC Microcontrollers中的主题 Re: LPC824 i2c reading problem</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC824-i2c-reading-problem/m-p/933331#M37169</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, I don't have the exact code because I don't have the external ADC. I suggest taking as base the I2C master&amp;nbsp;polling_b2b_transfer.&lt;/P&gt;&lt;P&gt;The i2c_polling_b2b_transfer_master example shows how to use i2c driver as master to do board to board transfer &lt;BR /&gt;using polling method:&lt;/P&gt;&lt;P&gt;In this example, one i2c instance as master and another i2c instance on the other board as slave. Master sends a &lt;BR /&gt;piece of data to slave, and receive a piece of data from slave. This example checks if the data received from &lt;BR /&gt;slave is correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to consider the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Connect to&amp;nbsp;P0_11 (I2C0_SDA) and&amp;nbsp;P0_10 (I2C0_SCL) the external ADC device.&lt;/P&gt;&lt;P&gt;2. Check the pull-up resistances.&lt;/P&gt;&lt;P&gt;3. Check the correct address from the external ADC&amp;nbsp;&amp;nbsp;&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;/P&gt;&lt;P&gt;#include "pin_mux.h"&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Definitions&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;#define EXAMPLE_I2C_MASTER_BASE (I2C0_BASE)&lt;BR /&gt;#define I2C_MASTER_CLOCK_FREQUENCY (12000000)&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 I2C_MASTER_SLAVE_ADDR_7BIT 0x7EU&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;#define I2C_BAUDRATE 100000U&lt;BR /&gt;#define I2C_DATA_LENGTH 33U&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Prototypes&lt;BR /&gt; ******************************************************************************/&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt; * Variables&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;uint8_t g_master_txBuff[I2C_DATA_LENGTH];&lt;BR /&gt;uint8_t g_master_rxBuff[I2C_DATA_LENGTH];&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt; * Code&lt;/P&gt;&lt;P&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;/*!&lt;BR /&gt; * @brief Main function&lt;BR /&gt; */&lt;BR /&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt; i2c_master_config_t masterConfig;&lt;BR /&gt; status_t reVal = kStatus_Fail;&lt;BR /&gt; uint8_t deviceAddress = 0x01U;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;// Please check the correct address of the external ADC&lt;/STRONG&gt;&lt;/P&gt;&lt;P&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_I2c0);&lt;/P&gt;&lt;P&gt;BOARD_InitPins();&lt;BR /&gt; BOARD_BootClockIRC12M();&lt;BR /&gt; BOARD_InitDebugConsole();&lt;/P&gt;&lt;P&gt;PRINTF("\r\nI2C board2board polling example -- Master transfer.\r\n");&lt;/P&gt;&lt;P&gt;/* Set up i2c master to send data to slave*/&lt;BR /&gt; /* First data in txBuff is data length of the transmiting data. */&lt;BR /&gt; g_master_txBuff[0] = I2C_DATA_LENGTH - 1U;&lt;BR /&gt; for (uint32_t i = 1U; i &amp;lt; I2C_DATA_LENGTH; i++)&lt;BR /&gt; {&lt;BR /&gt; g_master_txBuff[i] = i - 1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;PRINTF("Master will send data :");&lt;BR /&gt; for (uint32_t i = 0U; i &amp;lt; I2C_DATA_LENGTH - 1U; i++)&lt;BR /&gt; {&lt;BR /&gt; if (i % 8 == 0)&lt;BR /&gt; {&lt;BR /&gt; PRINTF("\r\n");&lt;BR /&gt; }&lt;BR /&gt; PRINTF("0x%2x ", g_master_txBuff[i + 1]);&lt;BR /&gt; }&lt;BR /&gt; PRINTF("\r\n\r\n");&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt; * masterConfig.debugEnable = false;&lt;BR /&gt; * masterConfig.ignoreAck = false;&lt;BR /&gt; * masterConfig.pinConfig = kI2C_2PinOpenDrain;&lt;BR /&gt; * masterConfig.baudRate_Bps = 100000U;&lt;BR /&gt; * masterConfig.busIdleTimeout_ns = 0;&lt;BR /&gt; * masterConfig.pinLowTimeout_ns = 0;&lt;BR /&gt; * masterConfig.sdaGlitchFilterWidth_ns = 0;&lt;BR /&gt; * masterConfig.sclGlitchFilterWidth_ns = 0;&lt;BR /&gt; */&lt;BR /&gt; I2C_MasterGetDefaultConfig(&amp;amp;masterConfig);&lt;/P&gt;&lt;P&gt;/* Change the default baudrate configuration */&lt;BR /&gt; masterConfig.baudRate_Bps = I2C_BAUDRATE;&lt;/P&gt;&lt;P&gt;/* Initialize the I2C master peripheral */&lt;BR /&gt; I2C_MasterInit(EXAMPLE_I2C_MASTER, &amp;amp;masterConfig, I2C_MASTER_CLOCK_FREQUENCY);&lt;/P&gt;&lt;P&gt;/* Send master blocking data to slave */&lt;BR /&gt; if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))&lt;BR /&gt; {&lt;BR /&gt; /* subAddress = 0x01, data = g_master_txBuff - write to slave.&lt;BR /&gt; start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/&lt;BR /&gt; reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, &amp;amp;deviceAddress, 1, kI2C_TransferNoStopFlag);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_txBuff, I2C_DATA_LENGTH, kI2C_TransferDefaultFlag);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;/* Wait until the slave is ready for transmit, wait time depend on user's case.&lt;BR /&gt; Slave devices that need some time to process received byte or are not ready yet to&lt;BR /&gt; send the next byte, can pull the clock low to signal to the master that it should wait.*/&lt;BR /&gt; for (uint32_t i = 0U; i &amp;lt; WAIT_TIME; i++)&lt;BR /&gt; {&lt;BR /&gt; __NOP();&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;PRINTF("Receive sent data from slave :");&lt;/P&gt;&lt;P&gt;/* Receive blocking data from slave */&lt;BR /&gt; /* subAddress = 0x01, data = g_master_rxBuff - read from slave.&lt;BR /&gt; start + slaveaddress(w) + subAddress + repeated start + slaveaddress(r) + rx data buffer + stop */&lt;BR /&gt; if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))&lt;BR /&gt; {&lt;BR /&gt; reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, &amp;amp;deviceAddress, 1, kI2C_TransferNoStopFlag);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal = I2C_MasterRepeatedStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Read);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal =&lt;BR /&gt; I2C_MasterReadBlocking(EXAMPLE_I2C_MASTER, g_master_rxBuff, I2C_DATA_LENGTH - 1, kI2C_TransferDefaultFlag);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;for (uint32_t i = 0U; i &amp;lt; I2C_DATA_LENGTH - 1; i++)&lt;BR /&gt; {&lt;BR /&gt; if (i % 8 == 0)&lt;BR /&gt; {&lt;BR /&gt; PRINTF("\r\n");&lt;BR /&gt; }&lt;BR /&gt; PRINTF("0x%2x ", g_master_rxBuff[i]);&lt;BR /&gt; }&lt;BR /&gt; PRINTF("\r\n\r\n");&lt;/P&gt;&lt;P&gt;/* Transfer completed. Check the data.*/&lt;BR /&gt; for (uint32_t i = 0U; i &amp;lt; I2C_DATA_LENGTH - 1; i++)&lt;BR /&gt; {&lt;BR /&gt; if (g_master_rxBuff[i] != g_master_txBuff[i + 1])&lt;BR /&gt; {&lt;BR /&gt; PRINTF("\r\nError occurred in the transfer ! \r\n");&lt;BR /&gt; break;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;PRINTF("\r\nEnd of I2C example .\r\n");&lt;BR /&gt; while (1)&lt;BR /&gt; {&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;Soledad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Jul 2019 14:57:13 GMT</pubDate>
    <dc:creator>soledad</dc:creator>
    <dc:date>2019-07-22T14:57:13Z</dc:date>
    <item>
      <title>LPC824 i2c reading problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC824-i2c-reading-problem/m-p/933330#M37168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i am using the lpc824&amp;nbsp; mcuxpresso I need to read the adc in (ADS1115 )&amp;nbsp; I2C module . when i try to read that it doesn't give any value from the ads1115 , for checking purpose i tried arduino uno in arduino the o/p has got correctly in lpc824 it doesn't&amp;nbsp; READ the adc value&amp;nbsp; plz let me know the solution in below i provide my code plz share me the solution i am asking this 3 weeks but till i didn't get any answer&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;/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;/*******************************************************************************&lt;BR /&gt; * Definitions&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;#define START_BYTE "startbyte\n\r"&lt;BR /&gt;#define SEPERATE_BYTE "-"&lt;BR /&gt;#define STOP_BYTE "stopbyte\n\r"&lt;/P&gt;&lt;P&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_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 0x49U&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 0x84&lt;BR /&gt; #define config_low 0x83&lt;BR /&gt; #define config_line 0x0083&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;/P&gt;&lt;P&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_I2c0);&lt;/P&gt;&lt;P&gt;BOARD_InitPins();&lt;BR /&gt; BOARD_BootClockIRC12M();&lt;BR /&gt; BOARD_InitDebugConsole();&lt;BR /&gt; // LPC_SYSCON-&amp;gt;PRESETCTRL &amp;amp;= (I2C0_RST_N);&lt;BR /&gt; // LPC_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| CFG_SLVENA ;&lt;/P&gt;&lt;P&gt;I2C0-&amp;gt;INTENSET = STAT_MSTPEND|STAT_SLVPEND ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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; I2C0-&amp;gt;MSTDAT = ADS1015_REG_POINTER_CONFIG; // 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; I2C0-&amp;gt;MSTDAT = config_high; // Address with 0 for RWn bit (WRITE) config&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; 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; // I2C0-&amp;gt;MSTDAT = ADS1015_REG_POINTER_CONVERT;&lt;BR /&gt; // WaitI2CMasterState(I2C0, I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd&lt;BR /&gt; // I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// I2C0-&amp;gt;MSTCTL = CTL_MSTSTART;&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);&lt;BR /&gt;// I2C0-&amp;gt;MSTDAT = ADS1015_REG_POINTER_CONVERT;&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;&lt;/P&gt;&lt;P&gt;while(1)&lt;BR /&gt; {&lt;BR /&gt;////////////////// write to ads1115 conversion register/////////////////////////////////////////////&lt;/P&gt;&lt;P&gt;USART_WriteBlocking(EXAMPLE_USART, START_BYTE , (sizeof( START_BYTE ))-1); // SEPERATE BYTE '-&lt;/P&gt;&lt;P&gt;// I2C0-&amp;gt;MSTCTL = CTL_MSTSTART;&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(I2C0, I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd&lt;BR /&gt;// //PutTerminalString(LPC_USART0, start_bit);&lt;BR /&gt;// I2C0-&amp;gt;MSTDAT = ADS1015_REG_POINTER_CONVERT;&lt;BR /&gt;// WaitI2CMasterState(I2C0, I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd&lt;BR /&gt;// PutTerminalString(LPC_USART0, start_bit);&lt;BR /&gt;// I2C0-&amp;gt;MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; I2C0-&amp;gt;MSTCTL = CTL_MSTSTART;&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; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; msb_byte = I2C0-&amp;gt;MSTDAT; // Read the data&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; //USART_WriteBlocking1(EXAMPLE_USART, msb_byte); // SEPERATE BYTE '-&lt;BR /&gt; lsb_byte = I2C0-&amp;gt;MSTDAT; // Read the data&lt;BR /&gt; WaitI2CMasterState( I2C_STAT_MSTST_RX);&lt;BR /&gt; USART_WriteBlocking1(EXAMPLE_USART, msb_byte, lsb_byte ); // SEPERATE BYTE '-&lt;BR /&gt; USART_WriteBlocking(EXAMPLE_USART, STOP_BYTE , (sizeof( STOP_BYTE ))-1); // SEPERATE BYTE '-&lt;BR /&gt;// slave_rx_data[slave_data_counter++] = temp; // Store it in the array, increment counter&lt;BR /&gt;// PutTerminalString1(LPC_USART0, temp1);&lt;BR /&gt; //PutTerminalString1(LPC_USART0, msb_byte);&lt;BR /&gt; // PutTerminalString1(LPC_USART0, lsb_byte);&lt;BR /&gt;// PutTerminalchar0(LPC_USART0, lsb_byte);&lt;BR /&gt;// I2C0-&amp;gt;MSTCTL = CTL_MSTCONTINUE; // ACK the data&lt;BR /&gt; // PutTerminalString(LPC_USART0,temp);&lt;BR /&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;I2C0-&amp;gt;MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction&lt;BR /&gt;//PutTerminalString(LPC_USART0, (uint8_t *)stop_bit);// Print a massage&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2019 09:03:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC824-i2c-reading-problem/m-p/933330#M37168</guid>
      <dc:creator>aravindpb5009</dc:creator>
      <dc:date>2019-07-17T09:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: LPC824 i2c reading problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC824-i2c-reading-problem/m-p/933331#M37169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, I don't have the exact code because I don't have the external ADC. I suggest taking as base the I2C master&amp;nbsp;polling_b2b_transfer.&lt;/P&gt;&lt;P&gt;The i2c_polling_b2b_transfer_master example shows how to use i2c driver as master to do board to board transfer &lt;BR /&gt;using polling method:&lt;/P&gt;&lt;P&gt;In this example, one i2c instance as master and another i2c instance on the other board as slave. Master sends a &lt;BR /&gt;piece of data to slave, and receive a piece of data from slave. This example checks if the data received from &lt;BR /&gt;slave is correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to consider the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Connect to&amp;nbsp;P0_11 (I2C0_SDA) and&amp;nbsp;P0_10 (I2C0_SCL) the external ADC device.&lt;/P&gt;&lt;P&gt;2. Check the pull-up resistances.&lt;/P&gt;&lt;P&gt;3. Check the correct address from the external ADC&amp;nbsp;&amp;nbsp;&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;/P&gt;&lt;P&gt;#include "pin_mux.h"&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Definitions&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;#define EXAMPLE_I2C_MASTER_BASE (I2C0_BASE)&lt;BR /&gt;#define I2C_MASTER_CLOCK_FREQUENCY (12000000)&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 I2C_MASTER_SLAVE_ADDR_7BIT 0x7EU&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;#define I2C_BAUDRATE 100000U&lt;BR /&gt;#define I2C_DATA_LENGTH 33U&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Prototypes&lt;BR /&gt; ******************************************************************************/&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt; * Variables&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;uint8_t g_master_txBuff[I2C_DATA_LENGTH];&lt;BR /&gt;uint8_t g_master_rxBuff[I2C_DATA_LENGTH];&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt; * Code&lt;/P&gt;&lt;P&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;/*!&lt;BR /&gt; * @brief Main function&lt;BR /&gt; */&lt;BR /&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt; i2c_master_config_t masterConfig;&lt;BR /&gt; status_t reVal = kStatus_Fail;&lt;BR /&gt; uint8_t deviceAddress = 0x01U;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;// Please check the correct address of the external ADC&lt;/STRONG&gt;&lt;/P&gt;&lt;P&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_I2c0);&lt;/P&gt;&lt;P&gt;BOARD_InitPins();&lt;BR /&gt; BOARD_BootClockIRC12M();&lt;BR /&gt; BOARD_InitDebugConsole();&lt;/P&gt;&lt;P&gt;PRINTF("\r\nI2C board2board polling example -- Master transfer.\r\n");&lt;/P&gt;&lt;P&gt;/* Set up i2c master to send data to slave*/&lt;BR /&gt; /* First data in txBuff is data length of the transmiting data. */&lt;BR /&gt; g_master_txBuff[0] = I2C_DATA_LENGTH - 1U;&lt;BR /&gt; for (uint32_t i = 1U; i &amp;lt; I2C_DATA_LENGTH; i++)&lt;BR /&gt; {&lt;BR /&gt; g_master_txBuff[i] = i - 1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;PRINTF("Master will send data :");&lt;BR /&gt; for (uint32_t i = 0U; i &amp;lt; I2C_DATA_LENGTH - 1U; i++)&lt;BR /&gt; {&lt;BR /&gt; if (i % 8 == 0)&lt;BR /&gt; {&lt;BR /&gt; PRINTF("\r\n");&lt;BR /&gt; }&lt;BR /&gt; PRINTF("0x%2x ", g_master_txBuff[i + 1]);&lt;BR /&gt; }&lt;BR /&gt; PRINTF("\r\n\r\n");&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt; * masterConfig.debugEnable = false;&lt;BR /&gt; * masterConfig.ignoreAck = false;&lt;BR /&gt; * masterConfig.pinConfig = kI2C_2PinOpenDrain;&lt;BR /&gt; * masterConfig.baudRate_Bps = 100000U;&lt;BR /&gt; * masterConfig.busIdleTimeout_ns = 0;&lt;BR /&gt; * masterConfig.pinLowTimeout_ns = 0;&lt;BR /&gt; * masterConfig.sdaGlitchFilterWidth_ns = 0;&lt;BR /&gt; * masterConfig.sclGlitchFilterWidth_ns = 0;&lt;BR /&gt; */&lt;BR /&gt; I2C_MasterGetDefaultConfig(&amp;amp;masterConfig);&lt;/P&gt;&lt;P&gt;/* Change the default baudrate configuration */&lt;BR /&gt; masterConfig.baudRate_Bps = I2C_BAUDRATE;&lt;/P&gt;&lt;P&gt;/* Initialize the I2C master peripheral */&lt;BR /&gt; I2C_MasterInit(EXAMPLE_I2C_MASTER, &amp;amp;masterConfig, I2C_MASTER_CLOCK_FREQUENCY);&lt;/P&gt;&lt;P&gt;/* Send master blocking data to slave */&lt;BR /&gt; if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))&lt;BR /&gt; {&lt;BR /&gt; /* subAddress = 0x01, data = g_master_txBuff - write to slave.&lt;BR /&gt; start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/&lt;BR /&gt; reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, &amp;amp;deviceAddress, 1, kI2C_TransferNoStopFlag);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_txBuff, I2C_DATA_LENGTH, kI2C_TransferDefaultFlag);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;/* Wait until the slave is ready for transmit, wait time depend on user's case.&lt;BR /&gt; Slave devices that need some time to process received byte or are not ready yet to&lt;BR /&gt; send the next byte, can pull the clock low to signal to the master that it should wait.*/&lt;BR /&gt; for (uint32_t i = 0U; i &amp;lt; WAIT_TIME; i++)&lt;BR /&gt; {&lt;BR /&gt; __NOP();&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;PRINTF("Receive sent data from slave :");&lt;/P&gt;&lt;P&gt;/* Receive blocking data from slave */&lt;BR /&gt; /* subAddress = 0x01, data = g_master_rxBuff - read from slave.&lt;BR /&gt; start + slaveaddress(w) + subAddress + repeated start + slaveaddress(r) + rx data buffer + stop */&lt;BR /&gt; if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))&lt;BR /&gt; {&lt;BR /&gt; reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, &amp;amp;deviceAddress, 1, kI2C_TransferNoStopFlag);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal = I2C_MasterRepeatedStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Read);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal =&lt;BR /&gt; I2C_MasterReadBlocking(EXAMPLE_I2C_MASTER, g_master_rxBuff, I2C_DATA_LENGTH - 1, kI2C_TransferDefaultFlag);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);&lt;BR /&gt; if (reVal != kStatus_Success)&lt;BR /&gt; {&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;for (uint32_t i = 0U; i &amp;lt; I2C_DATA_LENGTH - 1; i++)&lt;BR /&gt; {&lt;BR /&gt; if (i % 8 == 0)&lt;BR /&gt; {&lt;BR /&gt; PRINTF("\r\n");&lt;BR /&gt; }&lt;BR /&gt; PRINTF("0x%2x ", g_master_rxBuff[i]);&lt;BR /&gt; }&lt;BR /&gt; PRINTF("\r\n\r\n");&lt;/P&gt;&lt;P&gt;/* Transfer completed. Check the data.*/&lt;BR /&gt; for (uint32_t i = 0U; i &amp;lt; I2C_DATA_LENGTH - 1; i++)&lt;BR /&gt; {&lt;BR /&gt; if (g_master_rxBuff[i] != g_master_txBuff[i + 1])&lt;BR /&gt; {&lt;BR /&gt; PRINTF("\r\nError occurred in the transfer ! \r\n");&lt;BR /&gt; break;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;PRINTF("\r\nEnd of I2C example .\r\n");&lt;BR /&gt; while (1)&lt;BR /&gt; {&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;Soledad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jul 2019 14:57:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC824-i2c-reading-problem/m-p/933331#M37169</guid>
      <dc:creator>soledad</dc:creator>
      <dc:date>2019-07-22T14:57:13Z</dc:date>
    </item>
  </channel>
</rss>

