AnsweredAssumed Answered

LPC824 i2c reading problem

Question asked by Aravind palanisamy on Jul 17, 2019
Latest reply on Jul 22, 2019 by soledad

Hai 

 

         i am using the lpc824  mcuxpresso I need to read the adc in (ADS1115 )  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  READ the adc value  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

 

 

 

 

 

/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2019 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/* Standard C Included Files */
#include <stdio.h>
#include <string.h>
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_i2c.h"
#include "fsl_i2c.h"
#include <stdlib.h>
#include <string.h>
#include "pin_mux.h"
#include "fsl_device_registers.h"
#include "fsl_common.h"
#include"lpc8xx_i2c.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define START_BYTE "startbyte\n\r"
#define SEPERATE_BYTE "-"
#define STOP_BYTE "stopbyte\n\r"

uint8_t F_DEMOCHECK[] = "4096";
uint8_t s_identifier[] = "SPEEDTECH";
uint8_t g_demoInfo[] = " IOT CHECKING............\r\n";
uint8_t A_sensor1[] = " ADC_1 SENSOR_READING:\r\n";
uint8_t A_sensor2[] = " ADC_2 SENSOR_READING:\r\n";
uint8_t A_sensor3[] = " ADC_3 SENSOR_READING:\r\n";
uint8_t A_sensor4[] = " ADC_4 SENSOR_READING:\r\n";
uint8_t g_logInfo[] = "The received characters are:";
uint8_t g_overFlowInfo[] = "\r\nYou have input too many characters, Please try again!\r\n";
uint8_t g_checking[] = "\r\n condition stopped before the while loop ...!\r\n";

#define EXAMPLE_USART USART0
#define EXAMPLE_USART_CLK_SRC kCLOCK_MainClk
#define EXAMPLE_USART_CLK_FREQ CLOCK_GetFreq(EXAMPLE_USART_CLK_SRC)
#define EXAMPLE_USART_IRQn USART0_IRQn

#define EXAMPLE_I2C_MASTER_BASE (I2C0_BASE)
#define I2C_MASTER_CLOCK_FREQUENCY (30000000)
#define WAIT_TIME 10U
#define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE)

#define Self_Slave_address 0x49U
#define ADS1015_REG_POINTER_MASK (0x03)
#define ADS1015_REG_POINTER_CONVERT (0x00)
#define ADS1015_REG_POINTER_CONFIG (0x01)
#define ADS1015_REG_POINTER_LOWTHRESH (0x02)
#define ADS1015_REG_POINTER_HITHRESH (0x03)
#define config_high 0x84
#define config_low 0x83
#define config_line 0x0083

 


int main(void)
{
unsigned int msb_byte,lsb_byte,msb=5,lsb=9;
unsigned char * tx_ptr;
unsigned int temp1=5009;

// i2c_master_config_t masterConfig;


/* Enable clock of uart0. */
CLOCK_EnableClock(kCLOCK_Uart0);
/* Ser DIV of uart0. */
CLOCK_SetClkDivider(kCLOCK_DivUsartClk, 1U);
/* Enable clock of i2c0. */
CLOCK_EnableClock(kCLOCK_I2c0);

BOARD_InitPins();
BOARD_BootClockIRC12M();
BOARD_InitDebugConsole();
// LPC_SYSCON->PRESETCTRL &= (I2C0_RST_N);
// LPC_SYSCON->PRESETCTRL |= ~(I2C0_RST_N);


// Configure the I2C0 clock divider
// Desired bit rate = Fscl = 100,000 Hz (1/Fscl = 10 us, 5 us low and 5 us high)
// Use default clock high and clock low times (= 2 clocks each)
// So 4 I2C_PCLKs = 100,000/second, or 1 I2C_PCLK = 400,000/second
// I2C_PCLK = SystemClock = 30,000,000/second, so we divide by 30/.4 = 75
// Remember, value written to DIV divides by value+1

I2C0->CLKDIV = (75-1);
I2C0->CFG = CFG_MSTENA| CFG_SLVENA ;

I2C0->INTENSET = STAT_MSTPEND|STAT_SLVPEND ;

 

I2C0->MSTCTL = CTL_MSTSTART; // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.
I2C0->MSTDAT = (Self_Slave_address<<1) | 0; // Address with 0 for RWn bit (WRITE)
WaitI2CMasterState(I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd
I2C0->MSTDAT = ADS1015_REG_POINTER_CONFIG; // Address with 0 for RWn bit (WRITE)
WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd
I2C0->MSTDAT = config_high; // Address with 0 for RWn bit (WRITE) config
WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd
I2C0->MSTDAT =config_low; // Address with 0 for RWn bit (WRITE) config
WaitI2CMasterState( I2C_STAT_MSTST_TX ); // Wait for the address to be ACK'd
I2C0->MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction
// I2C0->MSTDAT = ADS1015_REG_POINTER_CONVERT;
// WaitI2CMasterState(I2C0, I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd
// I2C0->MSTCTL = CTL_MSTCONTINUE;


// I2C0->MSTCTL = CTL_MSTSTART;
// I2C0->MSTDAT = (Self_Slave_address<<1) | 0; // Address with 0 for RWn bit (write)
// WaitI2CMasterState( I2C_STAT_MSTST_TX);
// I2C0->MSTDAT = ADS1015_REG_POINTER_CONVERT;
// WaitI2CMasterState( I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd
// I2C0->MSTCTL = CTL_MSTSTOP;

while(1)
{
////////////////// write to ads1115 conversion register/////////////////////////////////////////////

USART_WriteBlocking(EXAMPLE_USART, START_BYTE , (sizeof( START_BYTE ))-1); // SEPERATE BYTE '-

// I2C0->MSTCTL = CTL_MSTSTART;
// I2C0->MSTDAT = (Self_Slave_address<<1) | 0; // Address with 0 for RWn bit (write)
// WaitI2CMasterState(I2C0, I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd
// //PutTerminalString(LPC_USART0, start_bit);
// I2C0->MSTDAT = ADS1015_REG_POINTER_CONVERT;
// WaitI2CMasterState(I2C0, I2C_STAT_MSTST_TX); // Wait for the address to be ACK'd
// PutTerminalString(LPC_USART0, start_bit);
// I2C0->MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction
// // I2C0->MSTCTL = CTL_MSTSTART; // Start the transaction by setting the MSTSTART bit to 1 in the Master control register.

 


I2C0->MSTCTL = CTL_MSTSTART;
I2C0->MSTDAT = (Self_Slave_address<<1) | 1; // Address with 0 for RWn bit (read)
WaitI2CMasterState( I2C_STAT_MSTST_RX);
msb_byte = I2C0->MSTDAT; // Read the data
WaitI2CMasterState( I2C_STAT_MSTST_RX);
//USART_WriteBlocking1(EXAMPLE_USART, msb_byte); // SEPERATE BYTE '-
lsb_byte = I2C0->MSTDAT; // Read the data
WaitI2CMasterState( I2C_STAT_MSTST_RX);
USART_WriteBlocking1(EXAMPLE_USART, msb_byte, lsb_byte ); // SEPERATE BYTE '-
USART_WriteBlocking(EXAMPLE_USART, STOP_BYTE , (sizeof( STOP_BYTE ))-1); // SEPERATE BYTE '-
// slave_rx_data[slave_data_counter++] = temp; // Store it in the array, increment counter
// PutTerminalString1(LPC_USART0, temp1);
//PutTerminalString1(LPC_USART0, msb_byte);
// PutTerminalString1(LPC_USART0, lsb_byte);
// PutTerminalchar0(LPC_USART0, lsb_byte);
// I2C0->MSTCTL = CTL_MSTCONTINUE; // ACK the data
// PutTerminalString(LPC_USART0,temp);
// WaitI2CMasterState(I2C0, I2C_STAT_MSTST_RX); // Wait for the data to be ACK'd
// NVIC_EnableIRQ(I2C0_IRQn);
I2C0->MSTCTL = CTL_MSTSTOP; // Send a stop to end the transaction
//PutTerminalString(LPC_USART0, (uint8_t *)stop_bit);// Print a massage
} // end of while 1

} // end of main

 

/////////////////////////////////////

Outcomes