Exemplo n.º 1
0
void readEeprom(void){
    BOOL success = FALSE;
    int index;

    do {
        if(!I2C_startTransfer(THERMAL_I2C_ID, FALSE)){
            #ifdef DEBUG
            printf("FAILED initial transfer!\n");
            #endif
            break;
        }
        // Transmit the slave's address to notify it
        if (!I2C_sendData(THERMAL_I2C_ID,EEPROM_WRITE_ADDRESS))
            break;

        // Tranmit the read address module
        if(!I2C_sendData(THERMAL_I2C_ID,EEPROM_READ_COMMAND)){
            #ifdef DEBUG
            printf("Error: Sent byte was not acknowledged\n");
            #endif
            break;
        }

        // Send a Repeated Started condition
        if(!I2C_startTransfer(THERMAL_I2C_ID,TRUE)){
            #ifdef DEBUG
                printf("FAILED Repeated start!\n");
            #endif
            break;
        }
        // Transmit the address with the READ bit set
        if (!I2C_sendData(THERMAL_I2C_ID,EEPROM_READ_ADDRESS))
            break;

        // Read the I2C bus most significant byte and send an acknowledge bit
        for(index = 0; index <=0xFF; index++){
            eepromData[index] = I2C_getData(THERMAL_I2C_ID);
            if(index < 0xFF)
                I2CAcknowledgeByte(I2C1, TRUE);
            else
                I2CAcknowledgeByte(I2C1, FALSE);
            while(!I2CAcknowledgeHasCompleted(I2C1));
        }
        success = TRUE;
    } while(0);
    // Send the stop bit to finish the transfer
    I2C_stopTransfer(THERMAL_I2C_ID);
    if(!success){
        printf("Data transfer unsuccessful.\n");
        return;
    }
    // Stop transfer twice?
    I2C_stopTransfer(THERMAL_I2C_ID);
    int Index;
    for(Index = 0; Index <=255; Index++){
        while(!Serial_isTransmitEmpty());
        //printf("EEPROM %x / %d: %x\n", Index, Index, eepromData[Index]);
    }
     
}
Exemplo n.º 2
0
void readPixelValue(void){
    int Index = 0;
    BOOL Success = TRUE;
    UINT8 pixelMSB, pixelLSB;
    if(!I2C_startTransfer(THERMAL_I2C_ID, FALSE)){
        printf("FAILED initial transfer!\n");
        Success = FALSE;
    }
// Transmit the slave's address to notify it
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_WRITE_ADDRESS)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_READ_COMMAND)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x00)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x01)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x40)){
        Success = FALSE;
    }
    if(Success){
    // Send a Repeated Started condition
        if(!I2C_startTransfer(THERMAL_I2C_ID,TRUE)){
            printf("FAILED Repeated start!\n");
            Success = FALSE;
        }
    // Transmit the address with the READ bit set
        if (!I2C_sendData(THERMAL_I2C_ID,CAMERA_READ_ADDRESS)){
            Success = FALSE;
        }
    }
    if(Success){
    // Read the I2C bus most significan byte and send an acknowledge bit
        for(Index = 0; Index <=63; Index++){
            pixelLSB = I2C_getData(THERMAL_I2C_ID);
            I2CAcknowledgeByte(I2C1, TRUE);
            while(!I2CAcknowledgeHasCompleted(THERMAL_I2C_ID));
            pixelMSB = I2C_getData(THERMAL_I2C_ID);
            I2CAcknowledgeByte(I2C1, TRUE);
            while(!I2CAcknowledgeHasCompleted(THERMAL_I2C_ID));
            pixelData[Index] = (pixelMSB << 8) + pixelLSB;
            if(pixelData[Index] > 32767)
                pixelData[Index] = pixelData[Index] - 65536;
        }
    }
    I2C_stopTransfer(THERMAL_I2C_ID);
}
Exemplo n.º 3
0
Arquivo: Encoder.c Projeto: ddeo/sdp
uint16_t readSensor(int SLAVE_READ_ADDRESS,int SLAVE_WRITE_ADDRESS) {
    int8_t success = FALSE;
    uint16_t data = 0;

    do {
        // Send the start bit with the restart flag low
        if(!I2C_startTransfer(ENCODER_I2C_ID, I2C_WRITE )){
            #ifdef DEBUG
            printf("FAILED initial transfer!\n");
            #endif
            break;
        }
        // Transmit the slave's address to notify it
        if (!I2C_sendData(ENCODER_I2C_ID, SLAVE_WRITE_ADDRESS))
            break;

        // Tranmit the read address module
        if(!I2C_sendData(ENCODER_I2C_ID,SLAVE_ANGLE_ADDRESS)){
            #ifdef DEBUG
            printf("Error: Sent byte was not acknowledged\n");
            #endif
            break;
        }

        // Send a Repeated Started condition
        if(!I2C_startTransfer(ENCODER_I2C_ID,I2C_READ)){
            #ifdef DEBUG
            printf("FAILED Repeated start!\n");
            #endif
            break;
        }
        // Transmit the address with the READ bit set
        if (!I2C_sendData(ENCODER_I2C_ID, SLAVE_READ_ADDRESS))
            break;
        
        // Read the I2C bus twice
        data = (I2C_getData(ENCODER_I2C_ID) << 6);
        I2C_acknowledgeRead(ENCODER_I2C_ID, TRUE);
        while(!I2C_hasAcknowledged(ENCODER_I2C_ID));
        data |= (I2C_getData(ENCODER_I2C_ID) & 0x3F);

        // Send the stop bit to finish the transfer
        I2C_stopTransfer(ENCODER_I2C_ID);

        success = TRUE;
    } while(0);
    if (!success) {
        #ifdef DEBUG
        printf("Data transfer unsuccessful.\n");
        #endif
        return FALSE;
    }
    return data;
}
Exemplo n.º 4
0
void readCPixelValue(void){
    BOOL Success = TRUE;
    UINT8 CPixelMSB, CPixelLSB;
    if(!I2C_startTransfer(THERMAL_I2C_ID, FALSE)){
        printf("FAILED initial transfer!\n");
        Success = FALSE;
    }
// Transmit the slave's address to notify it
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_WRITE_ADDRESS)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_READ_COMMAND)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x91)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x00)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x01)){
        Success = FALSE;
    }
    if(Success){
    // Send a Repeated Started condition
        if(!I2C_startTransfer(THERMAL_I2C_ID,TRUE)){
            printf("FAILED Repeated start!\n");
            Success = FALSE;
        }
    // Transmit the address with the READ bit set
        if (!I2C_sendData(THERMAL_I2C_ID,CAMERA_READ_ADDRESS)){
            Success = FALSE;
        }
    }
    if(Success){
    // Read the I2C bus most significan byte and send an acknowledge bit
        CPixelLSB = I2C_getData(THERMAL_I2C_ID);
        I2CAcknowledgeByte(I2C1, TRUE);
        while(!I2CAcknowledgeHasCompleted(THERMAL_I2C_ID));
        CPixelMSB = I2C_getData(THERMAL_I2C_ID);
        I2CAcknowledgeByte(I2C1, TRUE);
        while(!I2CAcknowledgeHasCompleted(THERMAL_I2C_ID));
        CPixel = (CPixelMSB << 8) + CPixelLSB;
    }
    I2C_stopTransfer(THERMAL_I2C_ID);
    if(CPixel > 32767){
        CPixel = CPixel - 65536;
    }
}
Exemplo n.º 5
0
void readChipTemp(void){
    BOOL Success = TRUE;
    UINT8 tempMSB, tempLSB;
    if(!I2C_startTransfer(THERMAL_I2C_ID, FALSE)){
        printf("FAILED initial transfer!\n");
        Success = FALSE;
    }
// Transmit the slave's address to notify it
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_WRITE_ADDRESS)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_READ_COMMAND)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x90)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x00)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x01)){
        Success = FALSE;
    }
    if(Success){
    // Send a Repeated Started condition
        if(!I2C_startTransfer(THERMAL_I2C_ID,TRUE)){
            printf("FAILED Repeated start!\n");
            Success = FALSE;
        }
    // Transmit the address with the READ bit set
        if (!I2C_sendData(THERMAL_I2C_ID,CAMERA_READ_ADDRESS)){
            Success = FALSE;
        }
    }
    if(Success){
    // Read the I2C bus most significan byte and send an acknowledge bit
        tempLSB = I2C_getData(THERMAL_I2C_ID);
        I2CAcknowledgeByte(THERMAL_I2C_ID, TRUE);
        while(!I2CAcknowledgeHasCompleted(THERMAL_I2C_ID));
        tempMSB = I2C_getData(THERMAL_I2C_ID);
        I2CAcknowledgeByte(THERMAL_I2C_ID, TRUE);
        while(!I2CAcknowledgeHasCompleted(THERMAL_I2C_ID));
        }
    I2C_stopTransfer(THERMAL_I2C_ID);
        rawTemp = (tempMSB << 8) + tempLSB;
}
Exemplo n.º 6
0
void readConfigReg(void){
    BOOL Success = TRUE;
    UINT8 configMSB, configLSB;
    if(!I2C_startTransfer(THERMAL_I2C_ID, FALSE)){
        printf("FAILED initial transfer!\n");
        Success = FALSE;
    }
// Transmit the slave's address to notify it
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_WRITE_ADDRESS)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_READ_COMMAND)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x92)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x00)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,0x01)){
        Success = FALSE;
    }
    if(Success){
    // Send a Repeated Started condition
        if(!I2C_startTransfer(THERMAL_I2C_ID,TRUE)){
            printf("FAILED Repeated start!\n");
            Success = FALSE;
        }
    // Transmit the address with the READ bit set
        if (!I2C_sendData(THERMAL_I2C_ID,CAMERA_READ_ADDRESS)){
            Success = FALSE;
        }
    }
    if(Success){
    // Read the I2C bus most significan byte and send an acknowledge bit
        configLSB = I2C_getData(THERMAL_I2C_ID);
        I2CAcknowledgeByte(I2C1, TRUE);
        while(!I2CAcknowledgeHasCompleted(THERMAL_I2C_ID));
        configMSB = I2C_getData(THERMAL_I2C_ID);
        }
    I2C_stopTransfer(THERMAL_I2C_ID);
        //while(!IsTransmitEmpty());
        //printf("Config Data %x %x\n", configMSB, configLSB);
}
Exemplo n.º 7
0
static uint16_t readDevice(uint8_t deviceReadAddress, uint8_t deviceWriteAddress, uint8_t dataAddress) {
    char success = FALSE;
    uint16_t data = 0;

    do {
        // Send the start bit with the restart flag low
        if(!I2C_startTransfer(ENCODER_I2C_ID, I2C_WRITE )){
            DBPRINT("Encoder: FAILED initial transfer!\n");
            break;
        }
        // Transmit the slave's address to notify it
        if (!I2C_sendData(ENCODER_I2C_ID, deviceWriteAddress))
            break;

        // Tranmit the read address module
        if(!I2C_sendData(ENCODER_I2C_ID, dataAddress)){
            DBPRINT("Encoder: Error: Sent byte was not acknowledged\n");
            break;
        }

        // Send a Repeated Started condition
        if(!I2C_startTransfer(ENCODER_I2C_ID,I2C_READ)){
            DBPRINT("Encoder: FAILED Repeated start!\n");
            break;
        }
        // Transmit the address with the READ bit set
        if (!I2C_sendData(ENCODER_I2C_ID, deviceReadAddress))
            break;
        
        // Read the I2C bus twice
        data = (I2C_getData(ENCODER_I2C_ID) << 6);
        I2C_acknowledgeRead(ENCODER_I2C_ID, TRUE);
        while(!I2C_hasAcknowledged(ENCODER_I2C_ID));
        data |= (I2C_getData(ENCODER_I2C_ID) & 0x3F);

        // Send the stop bit to finish the transfer
        I2C_stopTransfer(ENCODER_I2C_ID);

        success = TRUE;
    } while(0);
    if (!success) {
        DBPRINT("Encoder: Data transfer unsuccessful.\n");
        return FALSE;
    }
    return data;
}
Exemplo n.º 8
0
void writeConfigReg(void){
    BOOL Success = TRUE;
    UINT8 MSByte, LSByte, MSByteCheck, LSByteCheck;
    LSByte = eepromData[245];
    LSByte &= 0xF0;
    LSByte |= 0x0C;
    LSByteCheck = LSByte - 0x55;
    MSByte = eepromData[246];
    MSByteCheck = MSByte - 0x55;
    if(!I2C_startTransfer(THERMAL_I2C_ID, FALSE)){
        printf("FAILED initial transfer!\n");
        Success = FALSE;
    }
// Transmit the slave's address to notify it
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_WRITE_ADDRESS)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_WRITE_CONFIG_COMMAND)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,LSByteCheck)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,LSByte)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,MSByteCheck)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,MSByte)){
        Success = FALSE;
    }
    I2C_stopTransfer(THERMAL_I2C_ID);
}
Exemplo n.º 9
0
void writeTrimmingValue(void){
    BOOL Success = TRUE;
    UINT8 MSByte, LSByte, MSByteCheck, LSByteCheck;
    LSByte = eepromData[247];
    LSByteCheck = LSByte - 0xAA;
    MSByte = 0x00;
    MSByteCheck = 0x56;
    if(!I2C_startTransfer(THERMAL_I2C_ID, FALSE)){
        printf("FAILED initial transfer!\n");
        Success = FALSE;
    }
// Transmit the slave's address to notify it
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_WRITE_ADDRESS)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,CAMERA_WRITE_TRIM_COMMAND)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,LSByteCheck)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,LSByte)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,MSByteCheck)){
        Success = FALSE;
    }
// Tranmit the read address module
    if(!I2C_sendData(THERMAL_I2C_ID,MSByte)){
        Success = FALSE;
    }
    I2C_stopTransfer(THERMAL_I2C_ID);
}