/* Write a data buffer to the slave, when the master have obtained 
This function is always used in thread mode. */
unsigned long xI2CMasterWriteBufS2(unsigned long ulBase, const unsigned char *pucDataBuf, unsigned long ulLen, xtBoolean bEndTransmition)
/* Write a data buffer to the slave, when the master have obtained 
This function is always used in thread mode. */
unsigned long xI2CMasterWriteBufS2(unsigned long ulBase, const unsigned char *pucDataBuf, unsigned long ulLen, xtBoolean bEndTransmition)
{
    unsigned long i;
    unsigned long ulStatus;
    xASSERT((ulBase == I2C0_BASE) || (ulBase == I2C1_BASE));
    xASSERT(pucDataBuf);
    for(i = 0; i < ulLen - 1; i++)                              
    {
        ulStatus = I2CByteSend(ulBase, *pucDataBuf++);
        if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK))
        {
            I2CStopSend(ulBase);
            return i;
        }      
    }
    ulStatus = I2CByteSend(ulBase, *pucDataBuf);
    if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK))
    {
        I2CStopSend(ulBase);
        return i;      
    }  
    if(bEndTransmition)
    {
        I2CStopSend(ulBase);
    }    
    return ulLen;
}