예제 #1
0
//==============================================================================
BOOL i2c_Start(UINT8 restart )
{
    I2C_STATUS  status;

    // Send the Start (or Restart) signal
    if(restart)
    {
        //I2CRepeatStart(EEPROM_I2C_BUS);
        I2C1CONbits.RSEN = 1;
    }
    else
    {
        // Wait for the bus to be idle, then start the transfer
        while( !I2CBusIsIdle(EEPROM_I2C_BUS) );

        if(I2CStart(EEPROM_I2C_BUS) != I2C_SUCCESS)
        {
            DBPRINTF("Error: Bus collision during transfer Start\n");
            return FALSE;
        }
    }

    // Wait for the signal to complete
    do
    {
        status = I2CGetStatus(EEPROM_I2C_BUS);
    } while ( !(status & I2C_START) );


    return TRUE;
}
예제 #2
0
파일: I2C.c 프로젝트: sdajani/sdp
BOOL I2C_startTransfer(I2C_MODULE I2C_ID, BOOL restart){
    I2C_STATUS  status;

// Send the Start (or Restart) signal
    if(restart){
        if(I2CRepeatStart(I2C_ID) != I2C_SUCCESS){
            #ifdef DEBUG
            printf("Error: Bus collision during transfer Start at Read\n");
            #endif
            return FALSE;
        }
    }
    else{
    // Wait for the bus to be idle, then start the transfer
        while( !I2CBusIsIdle(I2C_ID) );
        if(I2CStart(I2C_ID) != I2C_SUCCESS){
            #ifdef DEBUG
            printf("Error: Bus collision during transfer Start at Write\n");
            #endif
            return FALSE;
        }
    }
    // Wait for the signal to complete
    do{
        status = I2CGetStatus(I2C_ID);
    }
    while (!(status & I2C_START) );

    return TRUE;
}
/****** I2C Driver implementation *******/
static bool StartTransfer(I2C_MODULE i2c_id, bool restart)
{
    I2C_STATUS status;

    // Send the Start (or Restart) signal
    if (restart)
    {
        I2CRepeatStart(i2c_id);
    }
    else
    {
        // Wait for the bus to be idle, then start the transfer
        while (!I2CBusIsIdle(i2c_id));

        if (I2CStart(i2c_id) != I2C_SUCCESS)
        {
            //DBPRINTF("Error: Bus collision during transfer Start\n");
            return FALSE;
        }
    }

    // Wait for the signal to complete
    do
    {
        status = I2CGetStatus(i2c_id);

    } while (!(status & I2C_START));

    return TRUE;
}
예제 #4
0
파일: main.c 프로젝트: conorpp/school
/*
 Sends a start to begin i2c transaction (with no strings attached)
 */
void sendStart(I2C_MODULE i2c){
        while( ! I2CBusIsIdle(i2c));
        DelayMs(2);                     // timing for ADXL345
        I2CStart(i2c);
        while( ! (I2CGetStatus(i2c) & I2C_START) );
        I2CClearStatus(i2c, I2C_START);
}
int transfer_start(I2C_MODULE port, I2C_7_BIT_ADDRESS address, UINT8 rw)
{
    I2C_STATUS status;
    int result = 0;

    while(!I2CBusIsIdle(port));

    if(I2CStart(port) != I2C_SUCCESS)
        return -1;

    do {
        status = I2CGetStatus(port);
    } while(!(status & I2C_START));

    /* Send address */
    address.rw = rw;
    result = transmit_byte(port, address.byte);
    if(result < 0)
        return result;

    if(!I2CByteWasAcknowledged(port))
        return -1;
    
    return result;
}
예제 #6
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;
}
예제 #7
0
파일: i2c_sw.c 프로젝트: ctapang/v0_70_01b
BOOL StartTransfer( BOOL restart )
{
    I2C_STATUS  status;

    // Wait for the bus to be idle, then start the transfer
    while( !I2CBusIsIdle(OVM7690_I2C_BUS) );

    if(I2CStart(OVM7690_I2C_BUS) != I2C_SUCCESS)
    {
         return FALSE;
    }

    // Wait for the signal to complete
    while(I2C3STATbits.S == 0);
    
    return TRUE;
}
예제 #8
0
/**
 * Invokes an I2C start condition
 * 
 * @param restart invoke a restart condition if true
 */
void I2C_StartTransfer(bool restart)
{
    // Send the Start (or Restart) signal
    if (restart) {
        I2CRepeatStart(I2C1);
    } else {
        // Wait for the bus to be idle, then start the transfer
        while (!I2CBusIsIdle(I2C1));

        if (I2CStart(I2C1) != I2C_SUCCESS) {
            //serialPrint("Error: Bus collision during transfer Start\r\n");
            while (1);
        }
    }
    // Wait for the signal to complete
    while (!(I2CGetStatus(I2C1) & I2C_START));
}
예제 #9
0
파일: i2c_sw.c 프로젝트: ctapang/v0_70b
bool StartTransfer( bool restart )
{

    // Wait for the bus to be idle, then start the transfer
      while(!I2CBusIsIdle(OVM7690_I2C_BUS));


    if(I2CStart(OVM7690_I2C_BUS) != I2C_SUCCESS)
    {
         return false;
    }

    // Wait for the signal to complete
    while(I2C1STATbits.S == 0);
    
    return true;
}
예제 #10
0
/************************************************************************************************** 
  Function: 
    static BOOL I2CShared_StartTransfer(const I2C_MODULE i2c, const BOOL restart)
  
  Author(s):
    mkobit
  
  Summary: 
    Starts or restarts a transaction
  
  Description: 
    Blocks until transaction has been started, restarts the transaction if (restart) is TRUE
    Static function, used by internal library
  
  Preconditions: 
    I2C module configured
    *Transaction started  - *only if (restart) is TRUE
  
  Parameters: 
    const I2C_MODULE i2c - I2C module to be used for this transaction
    const BOOL restart - restart transaction when TRUE, just start when FALSE
  
  Returns: 
    TRUE - If successful
    FALSE - If unsuccessful
  
  Example: 
    <code>
    I2CShared_StartTransfer(i2c, FALSE)
    </code>
  
  Conditions at Exit: 
    Bus transaction started
    I2C waiting for next action
  
**************************************************************************************************/
static BOOL I2CShared_StartTransfer(const I2C_MODULE i2c, const BOOL restart) {
  I2C_STATUS status;
  int fault_count = 0;

  // Send the start/restart signal
  if(restart) {
    I2CRepeatStart(i2c);
  }
  else {
    // Wait for the bus to be idle, then start the transfer
    while(!I2CBusIsIdle(i2c)){
      if (fault_count++ == TIMEOUT) {
        //printf("I2CShared_StartTransfer: Timeout waiting for bus to be idle\n");
        return FALSE;
      }
    }

    if(I2CStart(i2c) == I2C_ARBITRATION_LOSS)
    {
      //printf("I2CShared_StartTransfer: I2CStart experienced I2C_ARBITRATION_LOSS\n");
      //I2CShared_DebugStatus(i2c);
      return FALSE;
    }
  }

  fault_count = 0;
  // Wait for the signal to complete
  do {
    status = I2CGetStatus(i2c);
    if (status & I2C_ARBITRATION_LOSS) {
      //printf("I2CShared_StartTransfer: lost arbitration on i2c bus\n");
      return FALSE;
    }
    if (fault_count++ == TIMEOUT) {
      //printf("I2CShared_StartTransfer: Timeout waiting for bus to start\n");
      return FALSE;
    }
  } while (!(status & I2C_START));

  return TRUE;
}
예제 #11
0
BOOL StartTransfer( BOOL restart )
{
    I2C_STATUS  status;

    // Send the Start (or Restart) signal
    if(restart)
    {
        I2CRepeatStart(PIC24_I2C_BUS);
    }
    else
    {
        // Wait for the bus to be idle, then start the transfer
        while( !I2CBusIsIdle(PIC24_I2C_BUS) );

        if(I2CStart(PIC24_I2C_BUS) != I2C_SUCCESS)
        {
            DBPRINTF("Error: Bus collision during transfer Start\n");
            printf("bus coll\n");
            //Succ = FALSE;
            //goto RECOVER;
        }
    }

    // Wait for the signal to complete
    do
    {
        status = I2CGetStatus(PIC24_I2C_BUS);
        //printf("waiting for signal\n");

    } while ( !(status & I2C_START) );

RECOVER:
    //if(!Succ) return FALSE;
    //else return TRUE;
return TRUE;
}
예제 #12
0
void i2cStart(I2C_MODULE id){
    while( !I2CBusIsIdle(id) );
    I2CStart(id);
    while ( !(I2CGetStatus(id) & I2C_START) );
}void i2cSendByte(I2C_MODULE id, BYTE data){
예제 #13
0
파일: mpu6050.cpp 프로젝트: danhil/copter
BOOL MPU6050::StartTransfer( BOOL restart )
{
    I2C_STATUS status = I2C_START;
    //UINT16 count = 0;

    //sprintf(filename, "Starting StartTransfer(), status = %d.\n", status);
    //putsUART1( filename );

    // Send the Start (or Restart) signal
    if(restart)
    {
        I2C_RESULT res = I2C_SUCCESS;
        if((res = I2CRepeatStart( this->i2cBusId )) != I2C_SUCCESS)
        {
            sprintf(filename, "Repeat start, status = %d.\n",res);
            putsUART1( filename );
            // Do not return, try to connect anyway and fail
        }
    }
    else
    {
        // Wait for the bus to be idle, then start the transfer
        //while( !I2CBusIsIdle(MPU6050_I2C_BUS) );

        // Checks if the bus is idle, and starts the transfer if so
        if( I2CBusIsIdle( this->i2cBusId ) )
        {
            if(I2CStart( this->i2cBusId ) != I2C_SUCCESS)
            {
                //DBPRINTF("Error: Bus collision during transfer Start\n");

                sprintf( filename, "Error in I2CStart(). Bus collision on bus %u during transfer Start.\n", (unsigned)this->i2cBusId );
                putsUART1( filename );

                return FALSE;
            }
        }
        else
        {
            sprintf( filename, "Error in I2CBusIsIdle(). Bus %u is not idle.\n", (unsigned)this->i2cBusId );
            putsUART1( filename );

            return FALSE;
        }
    }

    //sprintf( filename, "StartTransfer(). Checking for Start response...\n" );
    //putsUART1( filename );
    UINT16 max_tries = 64000, count = 0;
    // Wait for the signal to complete or until tries are out
    do
    {
        status = I2CGetStatus( this->i2cBusId );
        //sprintf( filename, "StartTransfer(). Status is %u \n", status & I2C_START );
        //putsUART1( filename );
    } while (!(status & I2C_START) && ++count < max_tries);
    
    if( count >= max_tries )
    {
        sprintf( filename, "Error in StartTransfer(). Timeout!\n" );
        putsUART1( filename );  

        return FALSE;
    }

    //sprintf( filename, "StartTransfer(). Function successfully completed!\n" );
    //putsUART1( filename );

    return TRUE;
}