Example #1
0
//*****************************************************************************
//
//! \brief Write one byte to special register
//!
//! \param RegAddr specifies the target register address.
//! \param Data is the data written to target register.
//!
//!  This function is to write one byte to PCF8574 register,one byte will be
//!  writen in appointed address.
//!
//! \note internal function, used in this file only.
//!
//! \return Indicate the status of operation which can be one of the following
//! value \b SUCCESS or  \b FAILURE .
//
//*****************************************************************************
static Result _I2CRegWriteByte(uint8_t RegAddr, uint8_t Data)
{
    Result retv = SUCCESS;

    // Begin to I2C Transfer
    // first send START signal to control I2C bus
    // then send 7-bit address and R/W bit to I2C salve
    // at last send target register address
    retv = xI2CMasterWriteS1(PCF8574_PIN_I2C_PORT, PCF8574_I2C_ADDR,
            RegAddr, I2C_TRAN_NOT_END);
    if(retv != SUCCESS)
    {
        return (FAILURE);
    }

    // Send the wanted data to I2C bus
    // then Send STOP signal to release I2C bus
    retv = xI2CMasterWriteS2(PCF8574_PIN_I2C_PORT, Data, I2C_TRAN_END);
    if(retv != SUCCESS)
    {
        return (FAILURE);
    }

    return(SUCCESS);
}
Example #2
0
//*****************************************************************************
//
//! \brief Write 4-bit data or command to the SPLC780D through PCA8574.
//!
//! \param ucRS determines if the IR or DR to select.
//!
//! \return None.
//
//*****************************************************************************
void 
SPLC780Write4Bit(unsigned char ucDat)
{
    ucDat = ucDat | ucBacklightState | SPLC780_RW_WRITE;

    //
    //! input the 4-bit data 
    //
    xI2CMasterWriteS1(ulMaster, SPLC780_I2C_Addr, ucDat, xfalse);
	
    //
    //! latch the 4-bit data
    //
    xI2CMasterWriteS2(ulMaster, (ucDat | SPLC780_E_ENABLE), xfalse);
    xSysCtlDelay(200);
    xI2CMasterWriteS2(ulMaster, (ucDat | SPLC780_E_DISABLE), xtrue); 
}
Example #3
0
//*****************************************************************************
//
//! \brief Read the state or data from the SPLC780D.
//!
//! \param ucRS determines if the IR or DR to select.
//!
//! The parameter of ucRS can be:
//! - \ref SPLC780_RS_COMMAND - select the IR.
//! - \ref SPLC780_RS_DATA - select the DR.
//!
//! \return None.
//
//*****************************************************************************
unsigned char 
SPLC780Read(unsigned char ucRS)
{
    unsigned char ucTemp, ucData = 0;

    //
    // Check Arguments.
    //
    xASSERT((ucRS == SPLC780_RS_COMMAND) || (ucRS == SPLC780_RS_DATA));

    //
    // RS:Command, RW:Write, E:Enable
    //
    ucTemp = (ucRS | SPLC780_RW_READ | SPLC780_E_DISABLE | ucBacklightState);
    xI2CMasterWriteS1(ulMaster, SPLC780_I2C_Addr, ucTemp, xfalse);
    xSysCtlDelay(20);
    ucTemp = (ucRS | SPLC780_RW_READ | SPLC780_E_ENABLE | ucBacklightState);
    xI2CMasterWriteS2(ulMaster, ucTemp, xfalse);

    //
    // Read the Data
    //
    xI2CMasterReadS2(ulMaster, &ucData, xfalse);

	
    ucTemp = (ucRS | SPLC780_RW_READ | SPLC780_E_DISABLE | ucBacklightState);
    xI2CMasterWriteS2(ulMaster, ucTemp, xfalse);
    xSysCtlDelay(20);
    ucTemp = (ucRS | SPLC780_RW_READ | SPLC780_E_ENABLE | ucBacklightState);
    xI2CMasterWriteS2(ulMaster, ucTemp, xfalse);

    //
    // Read the Data
    //
    xI2CMasterReadS2(ulMaster, &ucTemp, xtrue);
    
    ucData = ((ucData << 4) & 0xf0) | (ucTemp & 0x0f);
	
    return ucData;
}
Example #4
0
//Writes data to the I2C.
size_t WireClass::write(uint8_t data){
    if(transmitting){
        // in master transmitter mode
        // don't bother if buffer is full
        if(txBufferLength >= BUFFER_LENGTH){
            setWriteError();
            return 0;
        }
        // put byte in tx buffer
        txBuffer[txBufferIndex] = data;
        ++txBufferIndex;
        // update amount in buffer   
        txBufferLength = txBufferIndex;
    } else {
        // in slave send mode
        // reply to master
        ulW++;
        if(ulW == 1)
            xI2CMasterWriteS1(i2cPort, (unsigned char)txAddress, data, xfalse);
        else
            xI2CMasterWriteS2(i2cPort, (unsigned char)data, xfalse);
    }
    return 1;  
}