AnsweredAssumed Answered

MPL3115A2 with EK-TM4C123GXL not working properly

Question asked by M Poz on Apr 10, 2014
Latest reply on Apr 16, 2014 by M Poz

Hello,

 

i'm using MPL3115A2 with EK-TM4C123GXL launchpad. I created code to signle read and mulitread to communicate with sensor. My problem is that i can't communicate with sensor when i'm not debugging code - when i download code to launchpad and check everyline in code ( F6 step over) everything works perfect. I'm able to read all registers that i need. - so next in debug mode i run program and it's works fine - i can see received values in terminal. Problem appears when i turn off launchpad and turn it on back (ofcorse programed). I can't see any values in terminal (only 0's), so then i debugg code again - when i press run in debugg mode it also doesn;t work, but when i reset uC, check 1st line where i read sensor ID and then run program, it works again. I will add that i try to read sensor in Timer ISR - timer is trigered 4 times per sec.

 

i'm trying to fix this but i cant find any reason what is going on. Here's osciliscope screen:

1st - when i can't communicate with sensor

T0003.PNG.png

2nd - single read and double read after uC reset, check everyline and then run:

T0004.PNG.png

T0005.PNG.png

 

Hope you will give me some advice, here's how i setup sensor:

k=i2c_write(0x60, 0x26,0x00);

        k=i2c_write(0x60, 0x26,0xB9);

        k=i2c_write(0x60, 0x27,0x02);

        i2c_read(0x60,0x26, &k);

        i2c_read(0x60,0x27, &k);

and here's mu functions

/////////////////////read data from i2c addre - is address of sensor 0x60, data is register

void i2c_read(char addre, unsigned long data,short *receive){

  unsigned long k=0;

  I2CMasterSlaveAddrSet(I2C1_BASE,addre,false); //setup slave address with last bit 0

  I2CMasterDataPut(I2C1_BASE,data); //put data

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_START); // start transmistion

  while(!I2CMasterBusy(I2C1_BASE)); //wait when bus is busy

  while(I2CMasterBusy(I2C1_BASE));

  I2CMasterSlaveAddrSet(I2C1_BASE,addre,true); //setup address again

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE); //start receive data

  k=I2CMasterErr(I2C1_BASE);

  while(I2CMasterBusy(I2C1_BASE));

  while(I2CMasterBusy(I2C1_BASE));

tab[0]=I2CMasterErr(I2C1_BASE); //check errors

  k=I2CMasterDataGet(I2C1_BASE); // take data

  *receive=k;

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);

////////////write to sensor///

}

unsigned long i2c_write(char address, unsigned long reg,unsigned long data){

  unsigned long k=0;

  I2CMasterSlaveAddrSet(I2C1_BASE,address,false); //setup slave address with last bit 0

  I2CMasterDataPut(I2C1_BASE,reg); //put data reg address

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_START); // start transmistion

  while(!I2CMasterBusy(I2C1_BASE));

  while(I2CMasterBusy(I2C1_BASE));

  k=I2CMasterErr(I2C1_BASE);

  I2CMasterDataPut(I2C1_BASE,data); // data to write

  k=I2CMasterErr(I2C1_BASE);

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_FINISH); //finish

  k=I2CMasterErr(I2C1_BASE); //check error

return k;

}

void i2c_multi_read(char address, unsigned data, unsigned repeat, short tab[] ){

  unsigned long k=0,err=0,i=0;

  I2CMasterSlaveAddrSet(I2C1_BASE,address,true); //false

  I2CMasterDataPut(I2C1_BASE,data);

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_START);

 

  while(I2CMasterBusy(I2C1_BASE));

  while(I2CMasterBusy(I2C1_BASE));

  I2CMasterSlaveAddrSet(I2C1_BASE,address,true);

 

 

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START );

  SysCtlDelay(10);

    while(I2CMasterBusy(I2C1_BASE));

  while(I2CMasterBusy(I2C1_BASE));

  tab[0]=I2CMasterDataGet(I2C1_BASE);//no dummy read

  tab[5]=I2CMasterErr(I2C1_BASE);

  for(i=0;i<repeat;i++){

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);

 

  //while(!I2CMasterBusy(I2C1_BASE));

  while(I2CMasterBusy(I2C1_BASE));

  while(I2CMasterBusy(I2C1_BASE));

  SysCtlDelay(10);

  tab[i+1]=I2CMasterDataGet(I2C1_BASE);

  if (I2CMasterErr(I2C1_BASE)!=0){tab[6]=I2CMasterErr(I2C1_BASE);}

  }

 

  I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);

}

Outcomes