Beispiel #1
0
/* Single Write DAC Input Register (EEPROM not updated) */
uint8_t MCP4728_FastWriteDAC(uint8_t channel, uint16_t val) {
  uint8_t res;
  uint8_t data[3];

  /* 01000|DAC1|DAC0|UDAC VREF|PD1|PD0|Gx|D11-D0 */
  if (channel>3) {
    return ERR_FAILED; /* only channel 0-3 allowed */
  }
  data[0] = 0x40|((channel&0x3)<<1); /* UDAC zero */
  data[1] = (uint8_t)((val>>8)&0x0F); /* VREF, PD1, PD2 and Gx zero */
  data[2] = (uint8_t)(val&0xff); /* low byte */
  res = GI2C1_SelectSlave(MCP4728_I2C_ADDRESS);
  if (res!=ERR_OK) {
    return res;
  }
  res = GI2C1_WriteBlock(&data[0], sizeof(data), GI2C1_SEND_STOP);
  if (res!=ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  res = GI2C1_UnselectSlave();
  if (res!=ERR_OK) {
    return res;
  }
  return ERR_OK;
}
Beispiel #2
0
/*
** ===================================================================
**     Method      :  GI2C1_ScanDevice (component GenericI2C)
**     Description :
**         Checks if a device responds on the bus with an ACK.
**     Parameters  :
**         NAME            - DESCRIPTION
**         i2cAddr         - 7bit I2C device address
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
byte GI2C1_ScanDevice(byte i2cAddr)
{
  byte res = ERR_OK;
  LDD_I2C_TErrorMask errMask;
  byte dummy;

  if (GI2C1_SelectSlave(i2cAddr)!=ERR_OK) {
    return ERR_FAILED;
  }
  for(;;) { /* breaks */
    /* send device address */
    GI2C1_deviceData.dataTransmittedFlg = FALSE;
    res = CI2C1_MasterReceiveBlock(GI2C1_deviceData.handle, &dummy, 1, LDD_I2C_SEND_STOP);
    if (res!=ERR_OK) {
      break; /* break for(;;) */
    }
    do { /* Wait until data is sent */
    } while (!GI2C1_deviceData.dataTransmittedFlg);
    errMask = 0;
    (void)CI2C1_GetError(GI2C1_deviceData.handle, &errMask);
    if (errMask&LDD_I2C_MASTER_NACK) { /* master did not receive ACK from slave */
      res = ERR_NOTAVAIL; /* device did not respond with ACK */
    }
    break; /* break for(;;) */
  } /* for(;;) */
  if (GI2C1_UnselectSlave()!=ERR_OK) {
    return ERR_FAILED;
  }
  return res;
}
Beispiel #3
0
/*
** ===================================================================
**     Method      :  GI2C1_ReadAddress (component GenericI2C)
**     Description :
**         Read from the device. This writes (S+i2cAddr+0), (memAddr),
**         (Sr+i2cAddr+1), (data)...(data+P)
**     Parameters  :
**         NAME            - DESCRIPTION
**         i2cAddr         - I2C Address of device
**       * memAddr         - Pointer to device memory address
**         memAddrSize     - number of address bytes
**       * data            - Pointer to read buffer
**         dataSize        - Size of read buffer
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
byte GI2C1_ReadAddress(byte i2cAddr, byte *memAddr, byte memAddrSize, byte *data, word dataSize)
{
  byte res = ERR_OK;

  if (GI2C1_SelectSlave(i2cAddr)!=ERR_OK) {
    return ERR_FAILED;
  }
  for(;;) { /* breaks */
    /* send device address and memory address */
    GI2C1_deviceData.dataTransmittedFlg = FALSE;
    res = CI2C1_MasterSendBlock(GI2C1_deviceData.handle, memAddr, memAddrSize, LDD_I2C_NO_SEND_STOP);
    if (res!=ERR_OK) {
      break; /* break for(;;) */
    }
    do { /* Wait until data is sent */
    } while (!GI2C1_deviceData.dataTransmittedFlg);
    /* receive data */
    GI2C1_deviceData.dataReceivedFlg = FALSE;
    res = CI2C1_MasterReceiveBlock(GI2C1_deviceData.handle, data, dataSize, LDD_I2C_SEND_STOP);
    if (res!=ERR_OK) {
      break; /* break for(;;) */
    }
    do { /* Wait until data is received */
    } while (!GI2C1_deviceData.dataReceivedFlg);
    break; /* break for(;;) */
  } /* for(;;) */
  if (GI2C1_UnselectSlave()!=ERR_OK) {
    return ERR_FAILED;
  }
  return res;
}
Beispiel #4
0
/* Fast Mode Write: updates all 4 channels, but does not update EEPROM */
uint8_t MCP4728_FastWriteAllDAC(uint16_t dac[4], size_t dacSize, uint8_t pd[4], size_t pdSize) {
  uint8_t res;
  uint8_t data[4*2], *p;
  int i;

  /* DAC contains PD1|PD0|D11..D0 */
  if (dacSize!=4*sizeof(uint16_t) || pdSize!=4) {
    return ERR_FAILED;
  }
  p = &data[0];
  for(i=0;i<4;i++) {
    *p = (pd[i]&0x3)<<4;
    *p |= (dac[i]>>8)&0x0F;
    p++;
    *p = (uint8_t)(dac[i]&0xFF);
    p++;
  }
  res = GI2C1_SelectSlave(MCP4728_I2C_ADDRESS);
  if (res!=ERR_OK) {
    return res;
  }
  res = GI2C1_WriteBlock(data, sizeof(data), GI2C1_SEND_STOP);
  if (res!=ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  res = GI2C1_UnselectSlave();
  if (res!=ERR_OK) {
    return res;
  }
  return ERR_OK;
}
Beispiel #5
0
/* Single Write DAC Input Register and EEPROM */
uint8_t MCP4728_WriteDACandEE(uint8_t channel, uint16_t val) {
  uint8_t res;
  uint8_t data[3];

  /* 01011|DAC1|DAC0|UDAC VREF|PD1|PD0|Gx|D11-D0 */
  if (channel>3) {
    return ERR_FAILED; /* only channel 0-3 allowed */
  }
  data[0] = 0x58|((channel&0x3)<<1); /* UDAC zero */
  data[1] = (uint8_t)((val>>8)&0x0F); /* VREF, PD1, PD2 and Gx zero */
  data[2] = (uint8_t)(val&0xff); /* low byte */
  res = GI2C1_SelectSlave(MCP4728_I2C_ADDRESS);
  if (res!=ERR_OK) {
    return res;
  }
  res = GI2C1_WriteBlock(&data[0], sizeof(data), GI2C1_SEND_STOP);
  if (res!=ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  res = GI2C1_UnselectSlave();
  if (res!=ERR_OK) {
    return res;
  }
#if PL_CONFIG_HAS_MCP4728_RDY
  while(MCP4728_IsBusy()) {
    WAIT1_WaitOSms(10); /* wait until data is written */
  }
#else
  WAIT1_WaitOSms(500); /* give EEPROM time to write data */
#endif
  return ERR_OK;
}
Beispiel #6
0
/*
** ===================================================================
**     Method      :  EE241_ReadBlock (component 24AA_EEPROM)
**     Description :
**         Read a block of memory.
**     Parameters  :
**         NAME            - DESCRIPTION
**         addr            - Address where to read the memory
**       * data            - Pointer to a buffer where to store the
**                           data
**         dataSize        - Size of buffer the data pointer
**                           is pointing to
**     Returns     :
**         ---             - Error code, possible values
**                           ERR_OK - OK
**                           otherwise it can return an error code of
**                           the underlying communication protocol.
** ===================================================================
*/
byte EE241_ReadBlock(EE241_Address addr, byte *data, word dataSize)
{
  uint8_t res;
  #if EE241_DEVICE_ID==EE241_DEVICE_ID_8
    uint8_t addr8;
    addr8 = (uint8_t)(addr&0xff);
  #else  
    uint8_t addr16[2];                  /* big endian address on I2C bus needs to be 16bit */
    addr16[0] = (uint8_t)(addr>>8); /* 16 bit address must be in big endian format */
    addr16[1] = (uint8_t)(addr&0xff);
  #endif

  res = GI2C1_SelectSlave(EE241_DEVICE_ADDR(addr));
  if (res != ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  #if EE241_DEVICE_ID==EE241_DEVICE_ID_8
    res = GI2C1_WriteBlock(&addr8, 1, GI2C1_DO_NOT_SEND_STOP); /* send 8bit address */
  #else
    res = GI2C1_WriteBlock(addr16, 2, GI2C1_DO_NOT_SEND_STOP); /* send 16bit address */
  #endif
  if (res != ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  res = GI2C1_ReadBlock(data, dataSize, GI2C1_SEND_STOP);
  if (res != ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  return GI2C1_UnselectSlave();
}
Beispiel #7
0
/*!
 * \brief General Call to reset, wake-up, sofware update or read address bits.
 */
static uint8_t MCP4728_GeneralCall(uint8_t cmd) {
  uint8_t res;

  res = GI2C1_SelectSlave(MCP4728_I2C_ADDRESS);
  if (res!=ERR_OK) {
    return res;
  }
  res = GI2C1_WriteBlock(&cmd, sizeof(cmd), GI2C1_SEND_STOP);
  if (res!=ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  res = GI2C1_UnselectSlave();
  if (res!=ERR_OK) {
    return res;
  }
  return ERR_OK;
}
Beispiel #8
0
uint8_t MCP4728_Read(uint8_t buf[3*8], size_t bufSize) {
  uint8_t res;

  if (bufSize!=2*3*4) {
    return ERR_FAILED;
  }
  res = GI2C1_SelectSlave(MCP4728_I2C_ADDRESS);
  if (res!=ERR_OK) {
    return res;
  }
  res = GI2C1_ReadBlock(buf, bufSize, GI2C1_SEND_STOP);
  if (res!=ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  res = GI2C1_UnselectSlave();
  if (res!=ERR_OK) {
    return res;
  }
  return ERR_OK;
}
Beispiel #9
0
/*
** ===================================================================
**     Method      :  GI2C1_WriteAddress (component GenericI2C)
**     Description :
**         Write to the device: (S+i2cAddr+0), (memAddr), (data)...
**         (data+P)
**     Parameters  :
**         NAME            - DESCRIPTION
**         i2cAddr         - I2C address of device
**       * memAddr         - Pointer to device memory address
**         memAddrSize     - number of address bytes
**       * data            - Pointer to data write buffer
**         dataSize        - Size of data buffer in bytes
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
byte GI2C1_WriteAddress(byte i2cAddr, byte *memAddr, byte memAddrSize, byte *data, word dataSize)
{
  static byte writeBuf[GI2C1_WRITE_BUFFER_SIZE];
  byte *p;
  word i;
  byte res = ERR_OK;

  if (GI2C1_SelectSlave(i2cAddr)!=ERR_OK) {
    return ERR_FAILED;
  }
  if (memAddrSize+dataSize>GI2C1_WRITE_BUFFER_SIZE) {
    return ERR_FAILED;
  }
  i = 0; p = memAddr;
  while(i<GI2C1_WRITE_BUFFER_SIZE && memAddrSize>0) {
    writeBuf[i++] = *p++;
    memAddrSize--;
  }
  p = data;
  while(i<GI2C1_WRITE_BUFFER_SIZE && dataSize>0) {
    writeBuf[i++] = *p++;
    dataSize--;
  }
  for(;;) { /* breaks */
    /* send device address, memory address and data */
    GI2C1_deviceData.dataTransmittedFlg = FALSE;
    if (CI2C1_MasterSendBlock(GI2C1_deviceData.handle, writeBuf, i, LDD_I2C_SEND_STOP)!=ERR_OK) {
      break; /* break for(;;) */
    }
    do { /* Wait until data is sent */
    } while (!GI2C1_deviceData.dataTransmittedFlg);
    break; /* break for(;;) */
  } /* for(;;) */
  if (GI2C1_UnselectSlave()!=ERR_OK) {
    return ERR_FAILED;
  }
  return res;
}
Beispiel #10
0
uint8_t MPC4728_SingleWrite(uint8_t channel, uint16_t val) {
  uint8_t res;
  uint8_t data[3];
  
  /* 01011|DAC1|DAC0|UDAC VREF|PD1|PD0|Gx|D11-D0 */
  data[0] = 0xB0|((channel&0x3)<<1);
  data[1] = (uint8_t)(val>>8);
  data[2] = (uint8_t)(val&0xff);
  res = GI2C1_SelectSlave(MPC4728_I2C_ADDRESS);
  if (res!=ERR_OK) {
    return res;
  }
  res = GI2C1_WriteBlock(&data[0], sizeof(data), GI2C1_SEND_STOP);
  if (res!=ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  res = GI2C1_UnselectSlave();
  if (res!=ERR_OK) {
    return res;
  }
  return ERR_OK;
}
Beispiel #11
0
/*
** ===================================================================
**     Method      :  EE241_WriteByte (component 24AA_EEPROM)
**     Description :
**         Writes a single byte to specified address
**     Parameters  :
**         NAME            - DESCRIPTION
**         addr            - The address inside the EEPROM
**         data            - The data value to write
**     Returns     :
**         ---             - Error code, possible values
**                           ERR_OK - OK
**                           otherwise it can return an error code of
**                           the underlying communication protocol.
** ===================================================================
*/
byte EE241_WriteByte(EE241_Address addr, byte data)
{
  uint8_t res, block[3];

  res = GI2C1_SelectSlave(EE241_DEVICE_ADDR(addr));
  if (res != ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  #if EE241_DEVICE_ID==EE241_DEVICE_ID_8  
    block[0] = (uint8_t)(addr&0xff);    /* low byte of address */
    block[1] = data; /* switch to read mode */
    res = GI2C1_WriteBlock(block, 2, GI2C1_SEND_STOP); /* send address and data */
  #else
    block[0] = (uint8_t)(addr>>8);      /* high byte of address */
    block[1] = (uint8_t)(addr&0xff);    /* low byte of address */
    block[2] = data; /* switch to read mode */
    res = GI2C1_WriteBlock(block, sizeof(block), GI2C1_SEND_STOP); /* send address and data */
  #endif
  if (res != ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
#if EE241_DO_ACKNOWLEDGE_POLLING
  /* do acknowledge polling */
  block[0] = 0xff; /* dummy value */
  do {
    WAIT1_WaitOSms(EE241_PAGE_WRITE_TIME_MS);
    res = GI2C1_ProbeACK(block, 1, GI2C1_SEND_STOP, EE241_ACK_POLLING_TIME_US); /* send address and data */
  } while(res!=ERR_OK); /* wait until we get an ACK */
#endif /* EE241_DO_ACKNOWLEDGE_POLLING */
  if (res != ERR_OK) {
    (void)GI2C1_UnselectSlave();
    return res;
  }
  return GI2C1_UnselectSlave();
}
Beispiel #12
0
byte EE241_WriteBlockPage(EE241_Address addr, byte *data, word dataSize)
{
  uint8_t res, i, *p, block[EE241_BLOCK_BUF_SIZE+2]; /* additional 2 bytes for the address */
  uint16_t eepromPage = (uint16_t)(addr/EE241_PAGE_SIZE);
  uint8_t offset = (uint8_t)(addr%EE241_PAGE_SIZE);

  if (dataSize==0 || dataSize>EE241_BLOCK_BUF_SIZE) {
    return ERR_OVERFLOW;                /* you may increase the buffer size in the properties? */
  }
  if (dataSize>EE241_PAGE_SIZE) {
    uint16_t size;

    size = (uint16_t)(EE241_PAGE_SIZE-offset);
    if (size!=0) {
      res = EE241_WriteBlock(addr, data, size); /* first page write */
      if (res != ERR_OK) {
        return res;
      }
      data += size; /* increment data pointer */
      addr += size; /* increment address */
      dataSize -= size; /* reduce size */
    }
    /* write multiple block of PAGE_SIZE */
    while (dataSize>EE241_PAGE_SIZE) {
      res = EE241_WriteBlock(addr, data, EE241_PAGE_SIZE);
      if (res != ERR_OK) {
        return res;
      }
      data += EE241_PAGE_SIZE; /* increment data pointer */
      addr += EE241_PAGE_SIZE; /* increment address */
      dataSize -= EE241_PAGE_SIZE; /* reduce size */
    }
    /* write remainder (if any) */
    if (dataSize>0) {
      return EE241_WriteBlock(addr, data, dataSize);
    }
    return ERR_OK;
  }
  if (offset+dataSize <= EE241_PAGE_SIZE) { /* no page boundary crossing */
    res = GI2C1_SelectSlave(EE241_DEVICE_ADDR(addr));
    if (res != ERR_OK) {
      (void)GI2C1_UnselectSlave();
      return res;
    }
    #if EE241_DEVICE_ID==EE241_DEVICE_ID_8 
      /* 8 bit address byte, high byte of address have been place in SelectSlave(addr) */
      block[0] = (uint8_t)(addr&0xff);  /* low byte of address */
      p = &block[1]; i = (uint8_t)dataSize;
    #else /* 16 bit address byte */
      block[0] = (uint8_t)(addr>>8);    /* high byte of address */
      block[1] = (uint8_t)(addr&0xff);  /* low byte of address */
      p = &block[2]; i = (uint8_t)dataSize;
    #endif

    /* copy block */
    while(i>0) {
      *p++ = *data++;
      i--;
    }
    res = GI2C1_WriteBlock(block, 
        dataSize+((EE241_DEVICE_ID==EE241_DEVICE_ID_8)? 1:2), GI2C1_SEND_STOP); /* send address and data */
    if (res != ERR_OK) {
      (void)GI2C1_UnselectSlave();
      return res;
    }
#if EE241_DO_ACKNOWLEDGE_POLLING
    /* do acknowledge polling */
    block[0] = 0xff; /* dummy value */
    do {
      WAIT1_WaitOSms(EE241_PAGE_WRITE_TIME_MS);
      res = GI2C1_ProbeACK(block, 1, GI2C1_SEND_STOP, EE241_ACK_POLLING_TIME_US); /* send address and data */
    } while(res!=ERR_OK); /* wait until we get an ACK */
    if (res != ERR_OK) {
      (void)GI2C1_UnselectSlave();
      return res;
    }
#endif /* EE241_DO_ACKNOWLEDGE_POLLING */
    return GI2C1_UnselectSlave();
  } else { /* crossing page boundaries: make two page writes */
Beispiel #13
0
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  //printf("HOLA MUNDO");
  /* Write your code here */
  /* For example: for(;;) { } */
  byte MPU_PWR=0x6B;
  int16_t AcX,AcY,AcZ,GcX,GcY,GcZ,temp;
  char buffer[15];
  uint8_t aux[15];
  //Inicializando la comunicacion I2C
  GI2C1_Init();
  GI2C1_SelectSlave(MPU);
  GI2C1_WriteByteAddress8(MPU,MPU_PWR,0);
  //Inicializando la comunicacion LCD
  LCD1_UseDisplay(1);
  LCD1_Clear();

    for(;;) {
      //Lectura de los Valores del Acelerometro
	  GI2C1_ReadByteAddress8(MPU,0x3B,&buffer[1]);
	  mywait_Waitms(2);
	  GI2C1_ReadByteAddress8(MPU,0x3C,&buffer[2]);
	  mywait_Waitms(2);
	  AcX=buffer[1];
	  AcX=AcX<<8;
	  AcX=AcX | buffer[2];

	  GI2C1_ReadByteAddress8(MPU,0x3D,&buffer[3]);
	  mywait_Waitms(2);
	  GI2C1_ReadByteAddress8(MPU,0x3E,&buffer[4]);
	  mywait_Waitms(2);
	  AcY=buffer[3];
	  AcY=AcY<<8;
	  AcY=AcY | buffer[4];

      GI2C1_ReadByteAddress8(MPU,0x3F,&buffer[5]);
	  mywait_Waitms(2);
	  GI2C1_ReadByteAddress8(MPU,0x40,&buffer[6]);
	  mywait_Waitms(2);
	  AcZ=buffer[5];
	  AcZ=AcZ<<8;
	  AcZ=AcZ | buffer[6];
	  printf("Acelerometro\nX=%d\tY=%d\tZ=%d\n", AcX,AcY,AcZ);
	  LCD1_WriteLineStr(1,"Acelerometro:   ");
	  UTIL1_Num16sToStr(aux, sizeof(aux), AcX);
	  LCD1_WriteLineStr(2,"                ");
	  LCD1_GotoXY(2,1);
	  LCD1_WriteString("X=");
	  LCD1_GotoXY(2,4);
	  LCD1_WriteString((char*)aux);
	  mywait_Waitms(2000);
	  UTIL1_Num16sToStr(aux, sizeof(aux), AcY);
	  LCD1_WriteLineStr(2,"                ");
	  LCD1_GotoXY(2,1);
	  LCD1_WriteString("Y=");
	  LCD1_GotoXY(2,4);
	  LCD1_WriteString((char*)aux);
	  mywait_Waitms(2000);
	  UTIL1_Num16sToStr(aux, sizeof(aux), AcZ);
	  LCD1_WriteLineStr(2,"                ");
	  LCD1_GotoXY(2,1);
	  LCD1_WriteString("Z=");
	  LCD1_GotoXY(2,4);
	  LCD1_WriteString((char*)aux);
	  mywait_Waitms(2000);

	  //Capturando los valores del Giroscopio
	  GI2C1_ReadByteAddress8(MPU,0x43,&buffer[7]);
	  mywait_Waitms(10);
	  GI2C1_ReadByteAddress8(MPU,0x44,&buffer[8]);
	  mywait_Waitms(10);
	  GcX=buffer[7];
	  GcX=GcX<<8;
	  GcX=GcX | buffer[8];

	  GI2C1_ReadByteAddress8(MPU,0x45,&buffer[9]);
	  mywait_Waitms(10);
	  GI2C1_ReadByteAddress8(MPU,0x46,&buffer[10]);
	  mywait_Waitms(10);
	  GcY=buffer[9];
	  GcY=GcY<<8;
	  GcY=GcY | buffer[10];

	  GI2C1_ReadByteAddress8(MPU,0x47,&buffer[11]);
	  mywait_Waitms(10);
	  GI2C1_ReadByteAddress8(MPU,0x48,&buffer[12]);
	  mywait_Waitms(10);
	  GcZ=buffer[11];
	  GcZ=GcZ<<8;
	  GcZ=GcZ | buffer[12];
	  printf("Giroscopio\nGX=%d\tGY=%d\tGZ=%d\n", GcX,GcY,GcZ);
	  LCD1_WriteLineStr(1,"Giroscopio:     ");
	  UTIL1_Num16sToStr(aux, sizeof(aux), GcX);
	  LCD1_WriteLineStr(2,"                ");
	  LCD1_GotoXY(2,1);
	  LCD1_WriteString("Gx=");
	  LCD1_GotoXY(2,5);
	  LCD1_WriteString((char*)aux);
	  mywait_Waitms(2000);
	  UTIL1_Num16sToStr(aux, sizeof(aux), GcY);
	  LCD1_WriteLineStr(2,"                ");
	  LCD1_GotoXY(2,1);
	  LCD1_WriteString("Gy=");
	  LCD1_GotoXY(2,5);
	  LCD1_WriteString((char*)aux);
	  mywait_Waitms(2000);
	  UTIL1_Num16sToStr(aux, sizeof(aux), GcZ);
	  LCD1_WriteLineStr(2,"                ");
	  LCD1_GotoXY(2,1);
	  LCD1_WriteString("Gz=");
	  LCD1_GotoXY(2,5);
	  LCD1_WriteString((char*)aux);
	  mywait_Waitms(2000);

	  //Capturando los valores de temperatura
	  GI2C1_ReadByteAddress8(MPU,0x41,&buffer[13]);
	  mywait_Waitms(10);
	  GI2C1_ReadByteAddress8(MPU,0x42,&buffer[14]);
	  mywait_Waitms(10);
	  temp=buffer[13];
	  temp=temp<<8;
	  temp=temp | buffer[14];
	  temp=(temp/340)+37;
	  printf("Temperatura = %d\n", temp);
	  LCD1_WriteLineStr(1,"Temperatura:   ");
	  UTIL1_Num16sToStr(aux, sizeof(aux), temp);
	  LCD1_WriteLineStr(2,"                ");
	  LCD1_GotoXY(2,5);
	  LCD1_WriteString((char*)aux);
	  mywait_Waitms(2000);


	  //Recibiendo los datos de GPS del Bluetooth
	  myserial_RecvBlock(btbuffer,sizeof(btbuffer),&rx);
	  strcpy(auxbuffer, btbuffer);
	  char *token;
	  token = strtok(auxbuffer, ",");
	  int i = 0;
	  while(token != NULL)
	  {
		  if(i==0)
		  {
			  if(token==99)
			  {
				  token = NULL;
			  }
		  }
		  if(i == 2){
			printf( "Latitud: %s\n", token );
			LCD1_WriteLineStr(1,"Latitud:   ");
			LCD1_WriteLineStr(2,"                ");
			LCD1_WriteLineStr(2,token);
			mywait_Waitms(2000);
		  }
		  if(i == 3){
			printf( "Longitud: %s\n", token );
			LCD1_WriteLineStr(1,"Longitud:  ");
			LCD1_WriteLineStr(2,"                ");
			LCD1_WriteLineStr(2,token);
			mywait_Waitms(2000);
		  }
		  if(i == 4){
			token=strtok(token,">");
			printf( "Altura: %s\n", token );
			LCD1_WriteLineStr(1,"Altura:    ");
			LCD1_WriteLineStr(2,"                ");
			LCD1_WriteLineStr(2,token);
			mywait_Waitms(2000);
		  }
		  token = strtok(NULL, ",");
		  i++;
	  }
  	  WAIT1_Waitms(1000);
    }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/