Ejemplo n.º 1
0
void EEPROM_ByteWrite(u16 Address, u08 Data)
// Description:
//   Byte Write Operation. The communication via the I2C bus with an EEPROM
//   (2465) is realized. A data byte is written into a user defined address.
{

	/* i2c por SW */
#if (defined I2C_SW &&  I2C_SW == 1)
	sw_i2c_start();							// Send start signal
	sw_i2c_write(EEPROMAddress & 0b11111110);// Send identifier I2C address     0xA0 = 10100000b
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char)(high_byte(Address)));// Send address to EEPROM (high byte address)
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) Address);// Send address to EEPROM  (low byte address) 
	delay_time(I2C_DELAY);
	sw_i2c_write(Data);// Send low byte to EEPROM  (data to write)
	delay_time(I2C_DELAY);// Delay a period of time to write   
	sw_i2c_stop();	   // Send I2C Stop Transfer
	delay_time(20);	   // Delay a period of time to write
	DelayTask(WRITE_CYCLE_TIME);
#else
	/* i2c por HW */

	IIC_transmite(EEPROMAddress, Address, &Data);

#endif
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*/
INT8U RTC_RandomRead(INT8U Address)
// Description:
//   Random Read Operation. Data is read from the RTC. The RTC
//   address is defined with the parameter Address.
{

	INT8U data_in;
#if (defined I2C_SW &&  I2C_SW == 1)
	CRITICAL_SECTION_START();
	sw_i2c_start();							// Send start signal

	sw_i2c_write(DS1307Address);		// Send identifer I2C address  (10100000b)
	delay_time(I2C_DELAY);
	sw_i2c_write((INT8U) Address);			// Send address to EEPROM
	delay_time(I2C_DELAY);
	sw_i2c_start();							// Send I2C Start Transfer
	sw_i2c_write(DS1307Address | 1);	// Send identifer I2C address  (10100001b)
	delay_time(I2C_DELAY);
	data_in = sw_i2c_read(0);			// Read byte
	sw_i2c_stop();			 // Send I2C Stop Transfer
	
	CRITICAL_SECTION_END();
#else
	IIC_transmite(DS1307Address, Address, NULL);
	IIC_recebe(DS1307Address, &data_in);
#endif
	return data_in;

}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
u08 EEPROM_RandomRead(u16 Address)
// Description:
//   Random Read Operation. Data is read from the EEPROM. The EEPROM
//   address is defined with the parameter Address.
{

	char data_in;
#if (defined I2C_SW &&  I2C_SW == 1)
	sw_i2c_start();							// Send start signal

	sw_i2c_write(EEPROMAddress);// Send identifer I2C address  (10100000b)
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) (high_byte(Address)));// Send address to EEPROM
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) Address);// Send address to EEPROM
	delay_time(I2C_DELAY);
	sw_i2c_start();// Send I2C Start Transfer
	sw_i2c_write(EEPROMAddress + 1);// Send identifer I2C address  (10100001b)
	delay_time(I2C_DELAY);
	data_in = sw_i2c_read(0);// Read byte
	sw_i2c_stop();			 // Send I2C Stop Transfer
#else

	/* Dummy write: Transmite NULL depois gera um sinal de start repeated */
	IIC_transmite(EEPROMAddress, Address, NULL);
	IIC_recebe(EEPROMAddress, &data_in);
	

#endif
	return data_in;

}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------------*/
u08 EEPROM_CurrentAddressRead(void)
// Description:
//   Current Address Read Operation. Data is read from the EEPROM. The current
//   address from the EEPROM is used.
{

	u08 data_in;

#if (defined I2C_SW &&  I2C_SW == 1)
	sw_i2c_start();							// Send start signal
	sw_i2c_write(EEPROMAddress);// Send identifer I2C address  (10100000b)
	sw_i2c_start();			   // Send I2C Start Transfer
	sw_i2c_write(EEPROMAddress + 1);// Send identifer I2C address  (10100001b)
	data_in = sw_i2c_read(0);// Read byte
	sw_i2c_stop();			 // Send I2C Stop Transfer

#else
	IIC_recebe(EEPROMAddress, &data_in);
#endif
	return data_in;
}
Ejemplo n.º 5
0
void RTC_ByteWrite(INT8U Address, INT8U Data)
// Description:
//   Byte Write Operation. The communication via the I2C bus with an EEPROM
//   (2465) is realized. A data byte is written into a user defined address.
{

#if (defined I2C_SW &&  I2C_SW == 1)
	CRITICAL_SECTION_START();
	sw_i2c_start();							// Send start signal
	sw_i2c_write(DS1307Address & 0b11111110);// Send identifier I2C address     0xA0 = 10100000b
	delay_time(I2C_DELAY);
	sw_i2c_write((INT8U) Address);// Send address to RTC  (byte address) 
	delay_time(I2C_DELAY);
	sw_i2c_write(Data);					// Send low byte to RTC  (data to write)
	delay_time(I2C_DELAY); // Delay a period of time to write   
	sw_i2c_stop();	   // Send I2C Stop Transfer
	delay_time(20);	   // Delay a period of time to write
	CRITICAL_SECTION_END();
#else
	IIC_transmite(DS1307Address, Address, &Data);
#endif
}
Ejemplo n.º 6
0
/*---------------------------------------------------------------------------*/
void RTC_AckPolling(void)
// Description:
//   Acknowledge Polling. The RTC will not acknowledge if a write cycle is
//   in progress. It can be used to determine when a write cycle is completed.
{

	volatile INT32U count = 0x03FF, ack = 0;
	while ((count != 0))
	{

		count--;
		sw_i2c_start();
		if (sw_i2c_write(DS1307Address))
			count = 0;
		sw_i2c_stop();

	}
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*/
void EEPROM_AckPolling(void)
// Description:
//   Acknowledge Polling. The EEPROM will not acknowledge if a write cycle is
//   in progress. It can be used to determine when a write cycle is completed.
{

	volatile unsigned int count = 0x03FF, ack = 0;
	while ((count != 0))
	{

		count--;
		sw_i2c_start();
		if (sw_i2c_write(EEPROMAddress))
			count = 0;
		sw_i2c_stop();

	}
}
Ejemplo n.º 8
0
INT8U RTC_DS1307_Init(void)
{
#if (defined I2C_SW &&  I2C_SW == 1)
	INT8U ret = NO_I2C_ACK;
	CRITICAL_SECTION_START();
		sw_i2c_init();
	CRITICAL_SECTION_END();
	
	sw_i2c_start();							// Send start signal
	ret = sw_i2c_write(DS1307Address);		// Send identifer I2C address  (10100000b)
	delay_time(I2C_DELAY);
	sw_i2c_stop();	
	
	return ((ret == OK_I2C_ACK) ? TRUE : FALSE);
	
#else
	IIC_init();
#endif

}
Ejemplo n.º 9
0
/*---------------------------------------------------------------------------*/
INT8U RTC_CurrentAddressRead(void)
// Description:
//   Current Address Read Operation. Data is read from the RTC. The current
//   address from the RTC is used.
{

	INT8U data_in;

#if (defined I2C_SW &&  I2C_SW == 1)
	CRITICAL_SECTION_START();
	sw_i2c_start();				// Send I2C Start Transfer        				
	sw_i2c_write(DS1307Address | 1);	// Send identifer I2C address  (10100001b)
	data_in = sw_i2c_read(0);				// Read byte
	sw_i2c_stop();				// Send I2C Stop Transfer
	CRITICAL_SECTION_END();
#else
	IIC_recebe(DS1307Address, &data_in);
#endif
	return data_in;

}