Example #1
0
/**
 * Send out a single byte of data over the I2C
 * 
 * @param data The byte of data to send
 */
bool I2C_TransmitOneByte(unsigned char data)
{
    // Wait for the transmitter to be ready
    while (!I2CTransmitterIsReady(I2C1));

    // Transmit the byte
    if (I2CSendByte(I2C1, data) == I2C_MASTER_BUS_COLLISION) {
        //serialPrint("Error: I2C Master Bus Collision\r\n");
        while (1);
    }

    // Wait for the transmission to finish
    while (!I2CTransmissionHasCompleted(I2C1));

    unsigned int i;
    for (i = 0; i < I2C_Timeout; i++) {
        if (I2CByteWasAcknowledged(I2C1)) {
            break;
        } else if (i == I2C_Timeout - 1) {
            //serialPrint("Error: I2C Slave Did Not Acknowledge\r\n");
            return FALSE;
        }
    }
    return TRUE;
}
Example #2
0
/************************************************************************************************** 
  Function: 
    static BOOL I2CShared_TransmitOneByte(const I2C_MODULE i2c, const UINT8 data)
    
  Author(s): 
    mkobit
  
  Summary: 
    Transmits one byte of data to (i2c)
  
  Description: 
    Waits until transmitter is ready and sends the byte of data
    Static function, used by internal library
  
  Preconditions: 
    Transaction started
    I2C module configured
  
  Parameters: 
    const I2C_MODULE i2c - I2C module to be used for this transaction
    const UINT8 data - to be transmitted
  
  Returns: 
    TRUE - If successful
    FALSE - If unsuccessful
  
  Example: 
    <code>
    I2CShared_TransmitOneByte(I2C1, 0x43)
    </code>
  
  Conditions at Exit: 
    Transmission of byte complete
    I2C bus waiting for next action
  
**************************************************************************************************/
static BOOL I2CShared_TransmitOneByte(const I2C_MODULE i2c, const UINT8 data) {
  int fault_count = 0;
  
  // Wait for the transmitter to be ready
  while(!I2CTransmitterIsReady(i2c)) {
    if (fault_count++ == TIMEOUT) {
      //printf("I2CShared_TransmitOneByte: Timeout waiting for I2CTransmitterIsReady\n");
      return FALSE;
    }
  }

  // Transmit the byte
  if(I2CSendByte(i2c, data) == I2C_MASTER_BUS_COLLISION)
  {
    //printf("I2CShared_TransmitOneByte: Error, I2C Master Bus Collision , status = 0x%x\n", I2CGetStatus(i2c));
    return FALSE;
  }

  fault_count = 0;
  // Wait for the transmission to finish
  while(!I2CTransmissionHasCompleted(i2c)) {
    if (fault_count++ == TIMEOUT) {
      //printf("I2CShared_TransmitOneByte: Timeout waiting for I2CTransmissionHasCompleted\n");
      return FALSE;
    }
  }

  if(!I2CByteWasAcknowledged(i2c))
  {
    //printf("I2CShared_TransmitOneByte: Error, sent byte was not acknowledged, status = 0x%x\n", I2CGetStatus(i2c));
    //I2CShared_DebugStatus(i2c);
      return FALSE;
  }
  return TRUE;
}
Example #3
0
}void i2cSendByte(I2C_MODULE id, BYTE data){
    while(!I2CTransmitterIsReady(id));//maybe comment this out
    I2CSendByte(id, data);
    //I2C_RESULT temp = I2CSendByte(id, data);
    //temp;
    while(!I2CTransmissionHasCompleted(id));
    while(!I2CByteWasAcknowledged(id));
}
static int transmit_byte(I2C_MODULE port, UINT8 data)
{
    while(!I2CTransmitterIsReady(port));

    if(I2CSendByte(port, data) == I2C_MASTER_BUS_COLLISION)
        return -1;

    while(!I2CTransmissionHasCompleted(port));

    return 0;
}
static bool TransmitOneByte(I2C_MODULE i2c_id, uint8_t data)
{
    // Wait for the transmitter to be ready
    while (!I2CTransmitterIsReady(i2c_id));

    // Transmit the byte
    if (I2CSendByte(i2c_id, data) == I2C_MASTER_BUS_COLLISION)
    {
        //DBPRINTF("Error: I2C Master Bus Collision\n");
        return FALSE;
    }

    // Wait for the transmission to finish
    while (!I2CTransmissionHasCompleted(i2c_id));

    return TRUE;
}
Example #6
0
BOOL TransmitOneByte( UINT8 data )
{
 
    // Wait for the transmitter to be ready
    while(!I2CTransmitterIsReady(OVM7690_I2C_BUS));

    // Transmit the byte
    if(I2CSendByte(OVM7690_I2C_BUS, data) == I2C_MASTER_BUS_COLLISION)
    {
        return FALSE;
    }

   // Wait for the transmission to finish
    while(!I2CTransmissionHasCompleted(OVM7690_I2C_BUS));
 
    return TRUE;
}
Example #7
0
BOOL TransmitOneByte( UINT8 data )
{
    // Wait for the transmitter to be ready
    while(!I2CTransmitterIsReady(EEPROM_I2C_BUS));

    // Transmit the byte
    if(I2CSendByte(EEPROM_I2C_BUS, data) == I2C_MASTER_BUS_COLLISION)
    {
        DBPRINTF("Error: I2C Master Bus Collision\n");
        return FALSE;
    }

    // Wait for the transmission to finish
    while(!I2CTransmissionHasCompleted(EEPROM_I2C_BUS));

    return TRUE;
}
Example #8
0
bool TransmitOneByte( uint8_t data )
{
 
    // Wait for the transmitter to be ready
    while(!I2CTransmitterIsReady(OVM7690_I2C_BUS));

    // Transmit the byte
    if(I2CSendByte(OVM7690_I2C_BUS, data) == I2C_MASTER_BUS_COLLISION)
    {
        return false;
    }

   // Wait for the transmission to finish
    while(!I2CTransmissionHasCompleted(OVM7690_I2C_BUS));
 
    return true;
}
Example #9
0
File: I2C.c Project: sdajani/sdp
BOOL I2C_transmitOneByte(I2C_MODULE I2C_ID, uint8_t data) {

    // Wait for the transmitter to be ready
    while(!I2CTransmitterIsReady(I2C_ID));

    // Transmit the byte and check for bus collision
    if(I2CSendByte(I2C_ID, data) == I2C_MASTER_BUS_COLLISION){
        #ifdef DEBUG
        printf("Error: I2C Master Bus Collision\n");
        #endif
        return FALSE;
    }

// Wait for the transmission to finish
    while(!I2CTransmissionHasCompleted(I2C_ID));
    
    return TRUE;
}
Example #10
0
BOOL MPU6050::TransmitOneByte( UINT8 data )
{
    UINT16 count = 0;

    // Wait for the transmitter to be ready
    while( !I2CTransmitterIsReady( this->i2cBusId ) && count < 64000 )
    {
        count++;
    }

    if( count < 64000 )
    {
        // Transmit the byte
        if(I2CSendByte( this->i2cBusId, data) == I2C_MASTER_BUS_COLLISION)
        {
            sprintf( filename, "Error in TransmitOneByte(). I2C Master Bus Collision.\n" );
            putsUART1( filename );

            //DBPRINTF("Error: I2C Master Bus Collision\n");
            return FALSE;
        }

        count = 0;
        // Wait for the transmission to finish
        while( !I2CTransmissionHasCompleted( this->i2cBusId ) && count < 64000 )
        {
            count++;
        }

        if( count >= 64000 )
        {
            sprintf( filename, "Error: TransmitOneByte(). Loop timeout for I2CTransmissionHasCompleted().\n" );
            putsUART1( filename );
            return FALSE;
        }
    }
    else
    {
        sprintf( filename, "Error: TransmitOneByte(). Loop timeout for I2CTransmitterIsReady().\n" );
        putsUART1( filename );
        return FALSE;
    }
    return TRUE;
}
Example #11
0
//==============================================================================
BOOL i2c_Tx( UINT8 data )
{
    // Wait for the transmitter to be ready
    while(!I2CTransmitterIsReady(EEPROM_I2C_BUS));
    //while ( !I2C1STATbits.TBF ) ;

    // Transmit the byte
    if(I2CSendByte(EEPROM_I2C_BUS, data) == I2C_MASTER_BUS_COLLISION)
    {
        putsUART1("Error: I2C Master Bus Collision\n");
        return FALSE;
    }
    //I2C1TRN = data;

    // Wait for the transmission to finish
    while(!I2CTransmissionHasCompleted(EEPROM_I2C_BUS));
    //while ( I2C1STATbits.TRSTAT );

    return TRUE;
}
Example #12
0
BOOL TransmitOneByte( UINT8 data )
{
    char Success = TRUE;
    // Wait for the transmitter to be ready
    while(!I2CTransmitterIsReady(PIC24_I2C_BUS));

    // Transmit the byte
    if(I2CSendByte(PIC24_I2C_BUS, data) == I2C_MASTER_BUS_COLLISION)
    {
        DBPRINTF("Error: I2C Master Bus Collision\n");
        printf("bus coll\n");
        goto END2;
        Success = FALSE;
    }

    // Wait for the transmission to finish
    while(!I2CTransmissionHasCompleted(PIC24_I2C_BUS));
END2:
    if(Success == FALSE){return FALSE;}
    else return TRUE;
}
Example #13
0
/*
 Sends a byte on an i2c channel (with no strings attached)
 */
void sendByte(I2C_MODULE i2c, BYTE byte){
    I2CSendByte(i2c, byte);                     // Send and wait for finish
    while( ! I2CTransmissionHasCompleted(i2c));
    while( ! (I2CByteWasAcknowledged(i2c)));    // wait for ack
}