/*--------------------------------------------------------------------------------------------------*/
unsigned char GLAM_EEPROMReadBytes(unsigned char reg_start, unsigned char bytes, unsigned char *buffer){
	unsigned char data, i;
	signed char error=0;
	
	if( reg_start+bytes >128 )
		return (2);

	cli();
	error += I2cStartWait();						/* send I2C start with deley					*/
	error += I2cWriteWait(GLAM_EEPROM_ADDRESS);		/* send 24AA01 address byte						*/
	error += I2cWriteWait(reg_start);				/* write first address byte for miltiple read	*/
	error += I2cStartWait();						/* send I2C start with deley					*/
    error += I2cWriteWait(GLAM_EEPROM_ADDRESS|0x01);/* send 24AA01 address byte and ¸read bit		*/
	
    for(i=0 ; i<bytes ; i++){						/* read number of bytes							*/
		error += I2cRead(&data);					/* read one byte								*/
		*(buffer+i) = data;							/* store one byte								*/
		if((i+1) == bytes){
			error += I2cSendNak();					/* send NAK to 24AA01 to finish read			*/
            I2cStop();								/* send stop to 24AA01							*/
			break;									/* break for									*/
		}
		else
			error += I2cSendAck();					/* send ACK to 24AA01 slave to read next byte	*/
	}
	sei();
	
	if(error)										/* error occurred?								*/
		return (1);									/* return error (1) -> communication failed		*/
	return (0);										/* return successfully							*/
}
Esempio n. 2
0
/**
  * @brief  This function receive multiple bytes to I2C slave.
  * @param  Buf: Buffer pointer to hold the received data.
  * @param  Len: Data Length to be received
  * @return None
  */
void I2cReadBytes(void* I2cMasterHandle, uint8_t* Buf, uint8_t Len)
{
	while(Len--)
	{
		*(Buf++) = I2cReadByte(I2cMasterHandle);
		if(Len == 0)
		{
			I2cSendNoAck(I2cMasterHandle);
		}
		else
		{
			I2cSendAck(I2cMasterHandle);
		}
	}
}