示例#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;
}
示例#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;
}
示例#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;
}
示例#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;
}
示例#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;
}
示例#8
0
文件: i2c_sw.c 项目: ctapang/v0_70b
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;
}
示例#9
0
文件: I2C.c 项目: 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;
}
示例#10
0
文件: mpu6050.cpp 项目: danhil/copter
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;
}
示例#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;
}
示例#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;
}
示例#13
0
文件: main.c 项目: conorpp/school
/*
 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
}