AnsweredAssumed Answered

LPC1343FBD48 I2C setting

Question asked by 浩 岩崎 on Feb 7, 2016
Latest reply on Feb 10, 2016 by vicentegomez

Hello My name is Hiroshi Iwasaki and one of our customer is using LPC1343 and faced I2C problem now.

Customer is testing  I2C by using LPCXpresso Board OM13045 now.

Problem

They set I2C Pin configuration and De-assert as below.

       LPC_IOCON->PIO0_4 = 0x01; // PIO0_4 as SCL

       LPC_IOCON->PIO0_5 = 0x01; // PIO0_5 as SDA

       LPC_SYSCON->PRESETCTRL |= 0x02; // De-asset I2C reset

And waiting for I2C interrupt but no interrupt was occurred.

Read back pin data is always ZERO this mean GPIO not I2C Pin.

IOCON (LPC1434) 0X40044030 = All Zero

0x40004404C= All Zero

 

Test

include "LPC13xx.h"
#include "SC16IS740I2C.h"
#include "GPIO.h"
#include "IF.h"

 

#include <cr_section_macros.h>
#include <NXP/crp.h>

// __CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

int main(void) {

volatile static int i = 0;
volatile unsigned l, j, k ;
volatile unsigned char sw;

LPC_SYSCON->PRESETCTRL |= 0x02; // De-asset I2C reset

LPC_IOCON->PIO0_4 = 0x01; // PIO0_4 as SCL
LPC_IOCON->PIO0_5 = 0x01; // PIO0_5 as SDA

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<5);// Enable for I2C clock
LPC_SYSCON->PRESETCTRL |= 0x02; // De-asset I2C reset

LPC_I2C->SCLL = 350; // SCL Low
LPC_I2C->SCLH = 350; // SCL High

NVIC_EnableIRQ(I2C_IRQn); // Enable I2C interrupt

LPC_I2C->CONCLR = 0x6c; // I2C flagClear
LPC_I2C->CONSET = 0x40; // I2C enable

LPC_I2C->CONSET = 0x20; // assert Start

// Enter an infinite loop, just incrementing a counter

while(1) {i++ ;}
  return 0 ;
}

void I2C_IRQHandler(void)
{
uint8_t StatValue;
int adrs=SC16IS740_LCR_ADR;
int dat =SC16IS740_LCR_DATA;
static int t=1;

StatValue= LPC_I2C->STAT;
switch ( StatValue )
{
  case 0x08: //Now Status is Start
    LPC_I2C->DAT =SC16IS740_ADDR; //Device address 1010 000 + Write
    LPC_I2C->CONCLR = 0x28; //clear interrupt flag + set next action
    break;
  case 0x18: //Now Status is SLA+W and Receive ACK
    LPC_I2C->DAT =adrs; //Address
    LPC_I2C->CONCLR = 0x08; //clear interrupt flag
    break;
  case 0x28: //Now Status is sending Data byte and Receive ACK
    if(t==1){ // 1st : Data byte is address
     LPC_I2C->DAT = dat; // write data
     LPC_I2C->CONCLR = 0x08;
    } else { // 2nd : Data byte is write data
     LPC_I2C->CONSET = 0x10; //send stop command
     LPC_I2C->CONCLR = 0x08; //Clear interrupt
     while(LPC_I2C->CONSET & 0x00000010); //waiting STOP flag
     LPC_I2C->CONCLR = 0x48; //Clear interrupt & Disable I2c
    }
    ++t;
    break;
  default:
    break;
}
}

 

Please advice to clear this problem

 

Best Regards

Outcomes