AnsweredAssumed Answered

LPC11Uxx I2C repeated start issue

Question asked by Oscari Saariniemi on Jul 25, 2016
Latest reply on Aug 9, 2016 by Oscari Saariniemi

LPC11UXX I2C repeated start and sequental read

 

I have trouble getting the repeated start to work.

I'm trying to write a easy code for reading values from MMA8452 accelerometer.

 

Code i'm an working on:

 

int debug = 0;

while(debug < 5){    //get_data looppi

 

 

  LPC_I2C->CONSET |= (1<<5);            

  do{                                   

  status = LPC_I2C->STAT & 0xF8;    

  }

  while(status != 0x08);               

  //START bit + accelerometer adress + writebit

  LPC_I2C->DAT        = 0x38;            //Device adress + W

  LPC_I2C->CONCLR     = 0x28;           

 

  //Transmit 1:st registry adress to start read from

  while(LPC_I2C->STAT != 0x18);          

  LPC_I2C->DAT        = 0x01;           

  LPC_I2C->CONCLR     = (1<<3);          

 

//start bit + accelerometer adress + readbit

  while(LPC_I2C->STAT != 0x28);

  LPC_I2C->CONSET |= (1<<5);

  LPC_I2C->DAT        = 0x39;           //Device adress + R

  LPC_I2C->CONCLR     = 0x28;         

 

_delay_ms(100);

  debug ++;

}

return 0 ;

 

I've learned from the LPC11U14 manual, that by setting the CONSET registry flag for (bit:5) START to 1, the next datawrite operation should come with repeated start.

It doesn't work.

 

Accelorometer replies with ACK, the communication works. I just can't get the repeated start to work.

 

Code is based on https://eewiki.net/display/microcontroller/Getting+Started+with+NXP

The LPCXpresso provided examples for LPC11Uxx are quite complicated with several headerfiles and extensive implementation of features.

 

What am i doing wrong?

 

Oscari

 

Attached image of datatransmission.

Attachments

Outcomes