I2C_ReceiveOneByte Function

Appendices: P08

Appendices:

I2C_ReceiveOneByte Function

                /****************************************************************************
                * Function:    I2C_RESULT ReceiveOneByte( I2C_MODULE i2c_port, BYTE data )
                 * Summary:     This transmits one byte to the EEPROM.
                 * Description: This transmits one byte to the EEPROM, and reports errors
                 *              for any bus collisions.
                 * Precondition: The transfer must have been previously started.
                 *
                 * Parameters:  i2c_port    - I2C_MODULE
                 *              data        - Data byte to transmit
                 *              ack         - TRUE - Send ACK
                 *                          - FALSE - SEND NO ACK
                 *
                 * Returns:     TRUE    - Data was sent successfully
                 *              FALSE   - A bus collision occurred
                 *
                 * Remarks:     This is a blocking routine that waits for the transmission
                 *              to complete.
                  ***************************************************************************/
                 I2C_RESULT ReceiveOneByte( I2C_MODULE i2c_port, BYTE *data, BOOL ack )
                 {
                 I2C_RESULT i2c_result = I2C_SUCCESS;
                    if(I2CReceiverEnable(i2c_port, TRUE) == I2C_RECEIVE_OVERFLOW)
                    {
                        printf("Error: I2C Receive Overflow\n");
                        i2c_result =  I2C_RECEIVE_OVERFLOW;
                    }
                    else
                    {
                        while(!I2CReceivedDataIsAvailable(i2c_port));
                /* The "ack" parameter determines if the EEPROM read is acknowledged */
                        I2CAcknowledgeByte(i2c_port, ack);
                        while(!I2CAcknowledgeHasCompleted(i2c_port));
                /* Read the received data byte */
                        *data = I2CGetByte(i2c_port);
                    }
                    return i2c_result;
                 }
                

  • Other product and company names mentioned herein are trademarks or trade names of their respective companies. © 2014 Digilent Inc. All rights reserved.