Exemplo n.º 1
0
Arquivo: demo.c Projeto: pbomel/hdl
int demo_stop_frame_buffer( demo_t *pdemo )
{
	StopTransfer(pdemo->paxivdma0);
	StopTransfer(pdemo->paxivdma1);

	return 1;
}
Exemplo n.º 2
0
int i2c_read(unsigned char addr, unsigned char reg, unsigned char length, unsigned char *data) {
    StartTransfer(FALSE);
    TransmitOneByte((addr<<1) & 0b11111110);
    TransmitOneByte(reg);
    
    StartTransfer(TRUE);
    TransmitOneByte((addr<<1) | 0b00000001);
    
    int i;
    for(i = 0; i < length; i++) {
        I2CReceiverEnable(I2C2, TRUE);
	while(!I2CReceivedDataIsAvailable(I2C2));
        if(i == length-1) {
            I2CAcknowledgeByte(I2C2, FALSE);
        } else {
            I2CAcknowledgeByte(I2C2, TRUE);
        }

        data[i] = I2CGetByte(I2C2);
        IdleI2C2();

    }
    StopTransfer();
    return 0;
}
Exemplo n.º 3
0
BOOL I2Csend(UINT8 address, int length, const UINT8* buffer)
{
	BOOL success = TRUE;
	
	    // Start the transfer for writing data to the LCD.
	    if (StartTransfer(FALSE)) {
	    	I2C_7_BIT_ADDRESS SlaveAddress;
	    	I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, address, I2C_WRITE);
			if (TransmitOneByte(SlaveAddress.byte)) {
				const char* cp;
	            // Call TransmitOneByte() for each non-null character in the string.
	            // Stop with success set to false if TransmitOneByte() returns failure.
				int index = 0;
				while (index < length) {
					success = TransmitOneByte(*buffer);
					index++;
					buffer++;
				}	
				if (success) {
					StopTransfer();
					}
				}
			else {
				success = FALSE;
	    	}
		}
		else {
			success = FALSE;
		}	
	return success;
}
Exemplo n.º 4
0
CloHttpCurl::~CloHttpCurl(void)
{
	StopTransfer();
	ClearBuffer();
	ClearParam();

	delete m_pAssoc;
	m_pAssoc = NULL;
}
Exemplo n.º 5
0
int i2c_write(unsigned char addr, unsigned char reg, unsigned char length, unsigned char *data) {
    while( !I2CBusIsIdle(I2C2) );
    StartTransfer(FALSE);
    TransmitOneByte((addr<<1) & 0b11111110);
    TransmitOneByte(reg);

    int i;
    for(i = 0; i < length; i++) {
        TransmitOneByte(data[i]);
    }
    StopTransfer();

    return 0;
}
Exemplo n.º 6
0
void CFileManager::OnReceive(LPBYTE lpBuffer, UINT nSize)
{
	switch (lpBuffer[0])
	{
	case COMMAND_LIST_FILES:// 获取文件列表
		SendFilesList((char *)lpBuffer + 1);
		break;
	case COMMAND_DELETE_FILE:// 删除文件
		DeleteFile((char *)lpBuffer + 1);
		SendToken(TOKEN_DELETE_FINISH);
		break;
	case COMMAND_DELETE_DIRECTORY:// 删除文件
		////printf("删除目录 %s\n", (char *)(bPacket + 1));
		DeleteDirectory((char *)lpBuffer + 1);
		SendToken(TOKEN_DELETE_FINISH);
		break;
	case COMMAND_DOWN_FILES: // 上传文件
		UploadToRemote(lpBuffer + 1);
		break;
	case COMMAND_CONTINUE: // 上传文件
		SendFileData(lpBuffer + 1);
		break;
	case COMMAND_CREATE_FOLDER:
		CreateFolder(lpBuffer + 1);
		break;
	case COMMAND_RENAME_FILE:
		Rename(lpBuffer + 1);
		break;
	case COMMAND_STOP:
		StopTransfer();
		break;
	case COMMAND_SET_TRANSFER_MODE:
		SetTransferMode(lpBuffer + 1);
		break;
	case COMMAND_FILE_SIZE:
		CreateLocalRecvFile(lpBuffer + 1);
		break;
	case COMMAND_FILE_DATA:
		WriteLocalRecvFile(lpBuffer + 1, nSize -1);
		break;
	case COMMAND_OPEN_FILE_SHOW:
		OpenFile((char *)lpBuffer + 1, SW_SHOW);
		break;
	case COMMAND_OPEN_FILE_HIDE:
		OpenFile((char *)lpBuffer + 1, SW_HIDE);
		break;
	default:
		break;
	}
}
Exemplo n.º 7
0
//------------------------------------------------------------------------------
// Function: I2C_WriteBlock
// Description: Write a block of bytes to the spacifed I2C slave address at the specified offset.
//              The offset address is one byte (8 bit offset only).
//              The return code is always 0.  There is no indication in case of error.
//------------------------------------------------------------------------------
BYTE I2C_WriteBlock(BYTE deviceID, BYTE offset, BYTE buffer, WORD length)
{
	BYTE write_buffer[256];
    //    memset(write_buffer, 0, sizeof(write_buffer));
	WORD count;
        BOOL Success = TRUE;

    write_buffer[0] = deviceID;
    write_buffer[1] = offset;
    write_buffer[2] = buffer;
    write_buffer[3] = 0x06;

    // Start the transfer to write data to the EEPROM
    if( !StartTransfer(FALSE) )
    {
        while(1);
    }

    // Transmit all data
    count = 0;

    while( Success && (count < (length + 2)) )
    {

             // Transmit a byte
            TransmitOneByte(write_buffer[count]);
        
            // Advance to the next byte
            count++;

            // Verify that the byte was acknowledged
            if(!I2CByteWasAcknowledged(OVM7690_I2C_BUS))
            {
                Success = FALSE;
            }

    }

    // End the transfer (hang here if an error occured)
    StopTransfer();

    if(!Success)
    {
        while(1);
    }

    return(0);
}
void i2c_write(I2C_MODULE i2c_id, uint8_t address, uint8_t *data, int len)
{
    uint8_t i2cBuffer[len+1];
    int i;
    
    i2cBuffer[0] = address | 0x00;
    memcpy(&i2cBuffer[1], data, len);
    
    if (!StartTransfer(i2c_id, FALSE))
    {
        return;
    }
    for (i = 0; i < len+1; i++)
    {
        if (!TransmitOneByte(i2c_id, i2cBuffer[i]))
        {
            break;
        }
    }
    StopTransfer(i2c_id);
}
Exemplo n.º 9
0
bool CFileManager::UploadToRemote(LPBYTE lpBuffer)
{

	if (lpBuffer[lstrlen((char *)lpBuffer) - 1] == '\\')
	{
		FixedUploadList((char *)lpBuffer);
		if (m_UploadList.empty())
		{
			StopTransfer();
			return true;
		}
	}
	else
	{
		m_UploadList.push_back((char *)lpBuffer);
	}

	list <string>::iterator it = m_UploadList.begin();
	// 发送第一个文件
	SendFileSize((*it).c_str());

	return true;
}
Exemplo n.º 10
0
int BadEndOfTransfer (const char *szFmt, ...)
{
char     szBuf [512];
va_list  marker;
struct  tftphdr *tp;

 // send NAK to server
   tp = (struct  tftphdr *) sTC.BufSnd;
   tp->th_opcode = htons((u_short)TFTP_ERROR);
   tp->th_code = htons(EUNDEF);
   send (sTC.s, (char *) tp, TFTP_DATA_HEADERSIZE, 0);

    StopTransfer ();
    // display message
    va_start( marker, szFmt );     /* Initialize variable arguments. */
    wvsprintf (szBuf, szFmt, marker);
    CMsgBox (hTftpClientWnd, szBuf, APPLICATION, MB_OK | MB_ICONERROR);

   // Semaphore released
    ReleaseSemaphore (hTftpClientSemaphore, 1, NULL);

   if (sTC.opcode==TFTP_RRQ  &&  sTC.nRcvd!=0)   DeleteFile (sTC.szFile);
return FALSE;
} // BadEndOfTransfer
Exemplo n.º 11
0
void i2c_read(I2C_MODULE i2c_id, uint8_t address, uint8_t *data, uint16_t len)
{
    uint16_t i;
    
    if (!StartTransfer(i2c_id, FALSE))
    {
        return;
    }
    
    if (!TransmitOneByte(i2c_id, (address | 0x01)))
    {
        return;
    }
    
    for (i = 0; i < len; i++)
    {
        if (i < len-1)  // send ACK
            data[i] = ReceiveOneByte(i2c_id, TRUE);
        else            // send NACK
            data[i] = ReceiveOneByte(i2c_id, FALSE);
    }
    
    StopTransfer(i2c_id);
}
Exemplo n.º 12
0
int TransferOK (time_t dNow)
{
char     szBuf [256];
    StopTransfer ();    // free resources

     // close MD5 computation
     MD5Final (sTC.m.ident, & sTC.m.ctx);

    // Semaphore released
    ReleaseSemaphore (hTftpClientSemaphore, 1, NULL);

    if (! sTC.bMultiFile)  
    {char szMD5 [33];
     int Ark;
     for (Ark=0 ; Ark<16; Ark++)
         wsprintf (szMD5 + 2*Ark, "%02x", sTC.m.ident[Ark]);
      wsprintf (szBuf, "%d block%s transferred in %d second%s\n %d block%s retransmitted\nMD5: %s",
                       sTC.nCount, // + (sTC.opcode==TFTP_RRQ ? 1 : 0),
                       PLURAL (sTC.nCount), // + (sTC.opcode==TFTP_RRQ ? 1 : 0)),
                       (int) (dNow-sTC.StartTime),
                       PLURAL (dNow-sTC.StartTime),
                       sTC.nTotRetrans,
                       PLURAL (sTC.nTotRetrans),
                       szMD5
            );
        CMsgBox (hTftpClientWnd, szBuf, APPLICATION, MB_OK | MB_ICONINFORMATION);
   } // one transfer --> display stats
 else 
  {
      sTC.dwMultiFileBlk += sTC.nCount;
      sTC.dwMultiFile++;
 }


return TRUE;
} // TransferOK
Exemplo n.º 13
0
//------------------------------------------------------------------------------
// Function: I2C_ReadBlock
// Description: Read a block of bytes from the spacifed I2C slave address at the specified offset.
//              The offset address is one byte (8 bit offset only).
//              The return code is always 0.  There is no indication in case of error.
//------------------------------------------------------------------------------
uint8_t I2C_ReadBlock(uint8_t deviceID, uint8_t offset, uint8_t *buffer, uint16_t length)
{
    uint8_t write_buffer[2] = {0x00};
    uint8_t count =0;
    bool Success = true;

    write_buffer[0] = deviceID;
    write_buffer[1] = offset;

    I2C1CONbits.ACKDT = 0;

    // Start the transfer to write data to the EEPROM
    if(!StartTransfer(false) )
    {
        return(1);
    }

   // Transmit the address with the READ bit set
   deviceID |= 0x01;

   TransmitOneByte(deviceID);
   
    // Verify that the byte was acknowledged
    if(!I2CByteWasAcknowledged(OVM7690_I2C_BUS))
    {
        Success = false;
        return(1);
    }

    for(count=0;count<length;count++)
    {

        // Read the data from the desired address
        if(I2CReceiverEnable(OVM7690_I2C_BUS, true) == I2C_RECEIVE_OVERFLOW)
        {
            Success = false;
            return(1);
        }
        else
        {
            while(!I2CReceivedDataIsAvailable(OVM7690_I2C_BUS));
            *buffer  = I2C1RCV;
            buffer++;

          if(count == (length-1))
          {
           // I2C1CONbits.ACKDT = 1;
            I2C1CONSET = 0x20;
          }

            I2C1CONbits.ACKEN = 1;		// initiate bus acknowledge sequence

            while(I2C1CONbits.ACKEN == 1);
        }

    }

    // End the transfer (stop here if an error occured)
    StopTransfer();

    return(0);
}
Exemplo n.º 14
0
//------------------------------------------------------------------------------
// Function: I2C_ReadBlock
// Description: Read a block of bytes from the spacifed I2C slave address at the specified offset.
//              The offset address is one byte (8 bit offset only).
//              The return code is always 0.  There is no indication in case of error.
//------------------------------------------------------------------------------
BYTE I2C_ReadBlock(BYTE deviceID, BYTE offset, BYTE *buffer, WORD length)
{
    BYTE write_buffer[2] = {0x00};
    BYTE count =0;
    BOOL                Success = TRUE;

    write_buffer[0] = deviceID;
    write_buffer[1] = offset;

    // Start the transfer to write data to the EEPROM
    if(!StartTransfer(FALSE) )
    {
        while(1);
    }

    // Transmit all data
    count = 0;

    while( Success && (count < (2)) )
    {
        // Transmit a byte
        TransmitOneByte(write_buffer[count]);

            // Advance to the next byte
            count++;

            // Verify that the byte was acknowledged
            if(!I2CByteWasAcknowledged(OVM7690_I2C_BUS))
            {
                Success = FALSE;
            }
    }

    // Start the transfer to read data
    StartTransfer(TRUE);

   // Transmit the address with the READ bit set
   deviceID |= 0x01;

   TransmitOneByte(deviceID);

    // Verify that the byte was acknowledged
    if(!I2CByteWasAcknowledged(OVM7690_I2C_BUS))
    {
        Success = FALSE;
    }

    for(count=0;count<length;count++)
    {

    // Read the data from the desired address
    if(Success)
    {
        if(I2CReceiverEnable(OVM7690_I2C_BUS, TRUE) == I2C_RECEIVE_OVERFLOW)
        {
            Success = FALSE;
        }
        else
        {
//            while(!I2CReceivedDataIsAvailable(OVM7690_I2C_BUS));
            *buffer++ = I2CGetByte(OVM7690_I2C_BUS);
        }

    }
    }
    // End the transfer (stop here if an error occured)
    StopTransfer();

    return(0);
}
Exemplo n.º 15
0
BOOL MPU6050::writeReg(UINT8 regAddress, UINT8 data)
{
    UINT8               i2cData[10];
    I2C_7_BIT_ADDRESS   SlaveAddress;
    int                 Index;
    int                 DataSz;
    BOOL                Acknowledged = FALSE;
    BOOL                Success = TRUE;    

    //sprintf(filename, "Starting writeReg().\n");
    //putsUART1( filename );

    // Initialize the data buffer
    I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, this->deviceAddress, I2C_WRITE);
    i2cData[0] = SlaveAddress.byte;
    i2cData[1] = regAddress;        // Register Address to write
    i2cData[2] = data;              // Data to write
    DataSz = 3;

    

    // Start the transfer
    if( !StartTransfer(FALSE) )
    {
        Success = FALSE;
        sprintf( filename, "Error in #1 StartTransfer(): when writing address %u.\n", (unsigned)regAddress );
        putsUART1( filename );
    }

    // Transmit all data
    Index = 0;
    while( Success && (Index < DataSz) )
    {
        // Transmit a byte
        if (TransmitOneByte(i2cData[Index++]))
        {   
            // Verify that the byte was acknowledged
            if(!I2CByteWasAcknowledged( this->i2cBusId ))
            {               
                Success = FALSE;

                sprintf( filename, "Error in #1 I2CByteWasAcknowledged(): when writing address %u.\n", (unsigned)regAddress );
                putsUART1( filename );
            }
        }
        else
        {
            Success = FALSE;

            sprintf( filename, "Error in #1 TransmitOneByte(): when writing address %u.\n", (unsigned)regAddress );
            putsUART1( filename );
        }
    }    

    //sprintf(filename, "Before StopTransfer()\n");
    //putsUART1( filename );

    // End the transfer
    StopTransfer();

    //sprintf(filename, "After StopTransfer()\n");
    //putsUART1( filename );

    // Wait for device to complete write process, by polling the ack status.
    while(Acknowledged != TRUE && Success != FALSE)
    {
        //sprintf(filename, "Inside the loop\n");
        //putsUART1( filename );

        // Start the transfer
        if( StartTransfer(FALSE) )
        {            
            // Transmit just the device's address
            if (TransmitOneByte(SlaveAddress.byte))
            {
                // Check to see if the byte was acknowledged
                Acknowledged = I2CByteWasAcknowledged( this->i2cBusId );

                /*if( !Acknowledged )
                {
                    sprintf( filename, "!Acknowledged %u.\n", (unsigned)regAddress );
                    putsUART1( filename );
                }*/
            }
            else
            {
                Success = FALSE;

                sprintf( filename, "Error in #2 TransmitOneByte() - !starttranfer : when writing address %u.\n", (unsigned)regAddress );
                putsUART1( filename );


            }
                // End the transfer
            StopTransfer();
        }
        else
        {
            Success = FALSE;

            sprintf( filename, "Error in #2 StartTransfer(): when writing address %u.\n", (unsigned)regAddress );
            putsUART1( filename );
        }
    }

    //sprintf(filename, "After the loop\n");
    //putsUART1( filename );

    if( !Success )
    {
        sprintf( filename, "Error in writeReg(): when writing to address %u.\n", (unsigned)regAddress );
        putsUART1( filename );
    }
   
    return Success;
}
Exemplo n.º 16
0
void SendPacket( UINT8* i2cData, int DataSz )
{
    int                 Index;
    UINT32              actualClock;
    BOOL                Acknowledged;
    BOOL                Success = TRUE;
    UINT8               i2cbyte;

    // Start the transfer to write data to the EEPROM
    if( !StartTransfer(FALSE) )
    {
        while(1);
    }

    // Transmit all data
    Index = 0;
    while( Success && (Index < DataSz) )
    {
        // Transmit a byte
        if (TransmitOneByte(i2cData[Index]))
        {
            // Advance to the next byte
            Index++;

            // Verify that the byte was acknowledged
            if(!I2CByteWasAcknowledged(EEPROM_I2C_BUS))
            {
                DBPRINTF("Error: Sent byte was not acknowledged\n");
                Success = FALSE;
            }
        }
        else
        {
            Success = FALSE;
        }
    }

    // End the transfer (hang here if an error occured)
    StopTransfer();
    if(!Success)
    {
        ErrorHalt();
    }

    // Wait for EEPROM to complete write process, by polling the ack status.
    Acknowledged = FALSE;
    do
    {
        // Start the transfer to address the EEPROM
        if( !StartTransfer(FALSE) )
        {
            while(1);
        }

        // Transmit just the EEPROM's address
        if (TransmitOneByte(i2cData[0]))
        {
            // Check to see if the byte was acknowledged
            Acknowledged = I2CByteWasAcknowledged(EEPROM_I2C_BUS);
        }
        else
        {
            Success = FALSE;
        }

        // End the transfer (stop here if an error occured)
        StopTransfer();
        if(!Success)
        {
            ErrorHalt();
        }

    } while (Acknowledged != TRUE);

    // End the transfer (stop here if an error occured)
    StopTransfer();
    if(!Success)
    {
        ErrorHalt();
    }
}
Exemplo n.º 17
0
int main(void)
{
    UINT8               i2cData[10];
    I2C_7_BIT_ADDRESS   SlaveAddress;
    int                 Index;
    int                 DataSz;
    UINT32              actualClock;
    BOOL                Acknowledged;
    BOOL                Success = TRUE;
    UINT8               i2cbyte;


    // Initialize debug messages (when supported)
    DBINIT();

    // Set the I2C baudrate
    actualClock = I2CSetFrequency(EEPROM_I2C_BUS, GetPeripheralClock(), I2C_CLOCK_FREQ);
    if ( abs(actualClock-I2C_CLOCK_FREQ) > I2C_CLOCK_FREQ/10 )
    {
        DBPRINTF("Error: I2C1 clock frequency (%u) error exceeds 10%%.\n", (unsigned)actualClock);
    }

    // Enable the I2C bus
    I2CEnable(EEPROM_I2C_BUS, TRUE);
    

    //
    // Send the data to EEPROM to program one location
    //

    // Initialize the data buffer
    I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, EEPROM_ADDRESS, I2C_WRITE);
    i2cData[0] = SlaveAddress.byte;
    i2cData[1] = 0x05;              // EEPROM location to program (high address byte)
    i2cData[2] = 0x40;              // EEPROM location to program (low address byte)
    i2cData[3] = 0xAA;              // Data to write
    DataSz = 4;

    // Start the transfer to write data to the EEPROM
    if( !StartTransfer(FALSE) )
    {
        while(1);
    }

    // Transmit all data
    Index = 0;
    while( Success && (Index < DataSz) )
    {
        // Transmit a byte
        if (TransmitOneByte(i2cData[Index]))
        {
            // Advance to the next byte
            Index++;

            // Verify that the byte was acknowledged
            if(!I2CByteWasAcknowledged(EEPROM_I2C_BUS))
            {
                DBPRINTF("Error: Sent byte was not acknowledged\n");
                Success = FALSE;
            }
        }
        else
        {
            Success = FALSE;
        }
    }

    // End the transfer (hang here if an error occured)
    StopTransfer();
    if(!Success)
    {
        while(1);
    }


    // Wait for EEPROM to complete write process, by polling the ack status.
    Acknowledged = FALSE;
    do
    {
        // Start the transfer to address the EEPROM
        if( !StartTransfer(FALSE) )
        {
            while(1);
        }
        
        // Transmit just the EEPROM's address
        if (TransmitOneByte(SlaveAddress.byte))
        {
            // Check to see if the byte was acknowledged
            Acknowledged = I2CByteWasAcknowledged(EEPROM_I2C_BUS);
        }
        else
        {
            Success = FALSE;
        }

        // End the transfer (stop here if an error occured)
        StopTransfer();
        if(!Success)
        {
            while(1);
        }

    } while (Acknowledged != TRUE);


    //
    // Read the data back from the EEPROM.
    //

    // Initialize the data buffer
    I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, EEPROM_ADDRESS, I2C_WRITE);
    i2cData[0] = SlaveAddress.byte;
    i2cData[1] = 0x05;              // EEPROM location to read (high address byte)
    i2cData[2] = 0x40;              // EEPROM location to read (low address byte)
    DataSz = 3;
    
    // Start the transfer to read the EEPROM.
    if( !StartTransfer(FALSE) )
    {
        while(1);
    }
    
    // Address the EEPROM.
    Index = 0;
    while( Success & (Index < DataSz) )
    {
        // Transmit a byte
        if (TransmitOneByte(i2cData[Index]))
        {
            // Advance to the next byte
            Index++;
        }
        else
        {
            Success = FALSE;
        }

        // Verify that the byte was acknowledged
        if(!I2CByteWasAcknowledged(EEPROM_I2C_BUS))
        {
            DBPRINTF("Error: Sent byte was not acknowledged\n");
            Success = FALSE;
        }
    }

    // Restart and send the EEPROM's internal address to switch to a read transfer
    if(Success)
    {
        // Send a Repeated Started condition
        if( !StartTransfer(TRUE) )
        {
            while(1);
        }

        // Transmit the address with the READ bit set
        I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, EEPROM_ADDRESS, I2C_READ);
        if (TransmitOneByte(SlaveAddress.byte))
        {
            // Verify that the byte was acknowledged
            if(!I2CByteWasAcknowledged(EEPROM_I2C_BUS))
            {
                DBPRINTF("Error: Sent byte was not acknowledged\n");
                Success = FALSE;
            }
        }
        else
        {
            Success = FALSE;
        }
    }

    // Read the data from the desired address
    if(Success)
    {
        if(I2CReceiverEnable(EEPROM_I2C_BUS, TRUE) == I2C_RECEIVE_OVERFLOW)
        {
            DBPRINTF("Error: I2C Receive Overflow\n");
            Success = FALSE;
        }
        else
        {
            while(!I2CReceivedDataIsAvailable(EEPROM_I2C_BUS));
            i2cbyte = I2CGetByte(EEPROM_I2C_BUS);
        }

    }

    // End the transfer (stop here if an error occured)
    StopTransfer();
    if(!Success)
    {
        while(1);
    }


    // Validate the data read
    if( i2cbyte != 0xAA )
    {
        DBPRINTF("Error: Verify failed\n");
    }
    else
    {
        DBPRINTF("Success\n");
    }

    // Example complete
    while(1);
}
Exemplo n.º 18
0
void CloHttpCurl::CancelRequest()
{
	return StopTransfer();
}
Exemplo n.º 19
0
BOOL MPU6050::readReg( UINT8 regAddress, UINT8 &data )
{
    // Variable declarations
    UINT8               i2cData[10];
    I2C_7_BIT_ADDRESS   SlaveAddress;
    int                 Index;
    int                 DataSz;
    BOOL                Acknowledged;
    BOOL                Success = TRUE;
    UINT8               i2cbyte;


    // Initialize the data buffer
    I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, this->deviceAddress, I2C_WRITE);
    i2cData[0] = SlaveAddress.byte;
    i2cData[1] = regAddress;                 // MPU6050 data address to read (0x75 = WHO_AM_I which contains 0x68)
    DataSz = 2;


    // Start the transfer
    if( !StartTransfer(FALSE) )
    {
        //while(1);
        Success = FALSE;

        sprintf( filename, "Error in #1 StartTransfer(): when reading address %u.\n", (unsigned)regAddress );
        putsUART1( filename );
    }

    // Address the device.
    Index = 0;
    while( Success & (Index < DataSz) )
    {
        // Transmit a byte
        if (TransmitOneByte(i2cData[Index]))
            Index++;
        else
        {
            Success = FALSE;

            sprintf( filename, "Error in #1 TransmitOneByte(): when reading address %u.\n", (unsigned)regAddress );
            putsUART1( filename );
        }
        // Verify that the byte was acknowledged
        if(!I2CByteWasAcknowledged( this->i2cBusId ))
        {
            //DBPRINTF("Error: Sent byte was not acknowledged\n");
            Success = FALSE;

            sprintf( filename, "Error in #1 I2CByteWasAcknowledged(): when reading address %u.\n", (unsigned)regAddress );
            putsUART1( filename );
        }
    }

    // Restart and send the device's internal address to switch to a read transfer
    if(Success)
    {
        // Send a Repeated Started condition
        if( !StartTransfer(TRUE) )
        {
            //while(1);
            Success = FALSE;

            sprintf( filename, "Error in #2 StartTransfer(): when reading address %u.\n", (unsigned)regAddress );
            putsUART1( filename );
        }

        // Transmit the address with the READ bit set
        I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, this->deviceAddress, I2C_READ);
        if (TransmitOneByte(SlaveAddress.byte))
        {
            // Verify that the byte was acknowledged
            if(!I2CByteWasAcknowledged( this->i2cBusId ))
            {
                //DBPRINTF("Error: Sent byte was not acknowledged\n");
                Success = FALSE;

                sprintf( filename, "Error in #2 I2CByteWasAcknowledged(): when reading address %u.\n", (unsigned)regAddress );
                putsUART1( filename );
            }
        }
        else
        {
            Success = FALSE;

            sprintf( filename, "Error in #2 TransmitOneByte(): when reading address %u.\n", (unsigned)regAddress );
            putsUART1( filename );
        }
    }

    //i2cbyte = 9;

    // Read the data from the desired address
    if(Success)
    {
        if(I2CReceiverEnable( this->i2cBusId , TRUE) == I2C_RECEIVE_OVERFLOW)
        {
            //DBPRINTF("Error: I2C Receive Overflow\n");
            Success = FALSE;

            sprintf( filename, "Error I2CReceiverEnable(): when reading address %u. I2C Receive Overflow.\n", (unsigned)regAddress );
            putsUART1( filename );
        }
        else
        {
            while(!I2CReceivedDataIsAvailable( this->i2cBusId ));
            i2cbyte = I2CGetByte( this->i2cBusId );
        }
    }

    // End the transfer
    StopTransfer();

    data = i2cbyte;

    if(!Success)
    {

        //mPORTBSetBits(BIT_2);
        //mPORTBClearBits(BIT_3);

        sprintf( filename, "Error in readReg(): when reading address %u.\n", (unsigned)regAddress );
        putsUART1( filename );
    }    

    return Success;
}