This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C problem

I am trying to read data via I2C0 from SDP600 pressure sensor using the codes below. My demo board is om11032 (lpc1768 cortex m3), the compiler is uvison 4,operating system is win7. My problem is, I can not read any data from the sensor besides on the oscilloscope none of the sda and scl lines are active. I am sure the sensor and the oscilloscope are working properly but no signals appears on the ports (p0.27 sda p0.28 scl)(pull-ups are done,the address of the sensor is 64). If anyone help me I would really appreciate.

/****************************************************************************
 *   $Id:: i2cmst.c 6097 2011-01-07 04:31:25Z nxp12832                      $
 *   Project: NXP LPC17xx I2C example
 *
 *   Description:
 *     This file contains I2C test modules, main entry, to test I2C APIs.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/
#include "lpc17xx.h"
#include "type.h"
#include "i2c.h"

extern volatile uint8_t I2CMasterBuffer[I2C_PORT_NUM][BUFSIZE];
extern volatile uint8_t I2CSlaveBuffer[I2C_PORT_NUM][BUFSIZE];
extern volatile uint32_t I2CReadLength[I2C_PORT_NUM];
extern volatile uint32_t I2CWriteLength[I2C_PORT_NUM];

#define PORT_USED               0

/*******************************************************************************
**   Main Function  main()
*******************************************************************************/
int main (void)
{


  /* SystemClockUpdate() updates the SystemFrequency variable */

  SystemClockUpdate();

  I2C0Init( );                  /* initialize I2c0 */





I2C2Init () ;
I2CReadLength [PORT_USED] = 1;
I2CWriteLength [PORT_USED] = 2;
I2CMasterBuffer [PORT_USED] [0] = PCF8594_ADDR;
I2CMasterBuffer [PORT_USED] [1] = 0xFF;
I2CMasterBuffer [PORT_USED] [2] = PCF8594_ADDR | RD_BIT;

while (1) {

I2CEngine (PORT_USED);




}

}

/******************************************************************************
**                            End Of File
******************************************************************************/
 /****************************************************************************
 *   $Id:: i2c.h 5865 2010-12-08 21:42:21Z usb00423                         $
 *   Project: NXP LPC17xx I2C example
 *
 *   Description:
 *     This file contains I2C code header definition.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/
#ifndef __I2C_H
#define __I2C_H


/* If I2C SEEPROM is tested, make sure FAST_MODE_PLUS is 0. For board to board test, this flag can be turned on. */
#define FAST_MODE_PLUS 0
#define I2C_PORT_NUM 3 #define BUFSIZE 64 #define MAX_TIMEOUT 0x00FFFFFF
static LPC_I2C_TypeDef (* const LPC_I2C[I2C_PORT_NUM]) = { LPC_I2C0, LPC_I2C1, LPC_I2C2 };
#define I2CMASTER 0x01 #define I2CSLAVE 0x02
#define PCF8594_ADDR 0x40 #define READ_WRITE 0x01
#define RD_BIT 0x01
#define I2C_IDLE 0 #define I2C_STARTED 1 #define I2C_RESTARTED 2 #define I2C_REPEATED_START 3 #define DATA_ACK 4 #define DATA_NACK 5 #define I2C_BUSY 6 #define I2C_NO_DATA 7 #define I2C_NACK_ON_ADDRESS 8 #define I2C_NACK_ON_DATA 9 #define I2C_ARBITRATION_LOST 10 #define I2C_TIME_OUT 11 #define I2C_OK 12
#define I2CONSET_I2EN (0x1<<6) /* I2C Control Set Register */ #define I2CONSET_AA (0x1<<2) #define I2CONSET_SI (0x1<<3) #define I2CONSET_STO (0x1<<4) #define I2CONSET_STA (0x1<<5)
#define I2CONCLR_AAC (0x1<<2) /* I2C Control clear Register */ #define I2CONCLR_SIC (0x1<<3) #define I2CONCLR_STAC (0x1<<5) #define I2CONCLR_I2ENC (0x1<<6)
#define I2DAT_I2C 0x00000000 /* I2C Data Reg */ #define I2ADR_I2C 0x00000000 /* I2C Slave Address Reg */ #define I2SCLH_SCLH 0x00000080 /* I2C SCL Duty Cycle High Reg */ #define I2SCLL_SCLL 0x00000080 /* I2C SCL Duty Cycle Low Reg */ #define I2SCLH_HS_SCLH 0x00000008 /* Fast Plus I2C SCL Duty Cycle High Reg */ #define I2SCLL_HS_SCLL 0x00000008 /* Fast Plus I2C SCL Duty Cycle Low Reg */
extern void I2C0_IRQHandler( void ); extern void I2C1_IRQHandler( void ); extern void I2C2_IRQHandler( void ); extern void I2C0Init( void ); extern void I2C1Init( void ); extern void I2C2Init( void ); extern uint32_t I2CStart( uint32_t portNum ); extern uint32_t I2CStop( uint32_t portNum ); extern uint32_t I2CEngine( uint32_t portNum );
#endif /* end __I2C_H */ /**************************************************************************** ** End Of File *****************************************************************************/

  • Why do you initialize I2C for both port 0 and port 2?

    You have a link to the source code you are using?

    Have you looked what the I2C2Init() function actually does?

    How have you verified that the I2C2 device is powered up, and the corresponding I/O pins are mapped from GPIO into dedicated I2C pins?

  • Yea, my guess ist you are missing basic low-level initialization for the I2C-Peripherals.
    Make shure your GPIO and I2C have theyr clocks activated (RCC-Setup) and the GPIO-settings are correctly applied (Mode/Speed/remap/...). That has to be done before you run your I2C0_Init() function.
    If you don't know what to do, look at an example that uses I2C and step thru the initialisation-process to see what the example does with all the configurations and what would be the correct order to get it all set up for transmission.

  • Firstly, thank you all.
    Mr.Vogt can you reccommend a source to look up gpio setting an rcc setup. I am very unexperienced with arm architecture, and its hard me to understand some basic things at first. I really appreciate your help. Thank you again

  • It really doesn't matter what experience you have with ARM architecture, because there are a huge number of ARM chips that only has the processor core in common.

    In short: the datasheet/user manual released by the manufacturer of your specific chip (that would be NXP) contains the relevant information needed to make use of the I2C peripherials.

    It has individual chapters telling about power, I/O mapping, clocking and the specific I2C peripherial.

    And note that after processor reset, some peripherials are already powered up, while other peripherials needs to be specifically powered up. But the processor manual clearly describes the relevant register, where each bit in the register represents power to the different peripherials. Same with I/O - the manual clearly describes which register controls the I/O pins relevant for I2C, and what bit values that are needed for the pins to be used for GPIO or for I2C2. The manual also clearly shows how to specify clocking for the different peripherials.