Exemple #1
0
/*
 * sending one bit
 */
void SkI2cSndBit(
    SK_IOC	IoC,	/* I/O Context */
    SK_U8	Bit)	/* Bit to send */
{
    I2C_DATA_OUT(IoC);
    if (Bit) {
        I2C_DATA_HIGH(IoC);
    } else {
        I2C_DATA_LOW(IoC);
    }
    SkDgWaitTime(IoC, NS2BCLK(T_DATA_IN_SETUP));
    I2C_CLK_HIGH(IoC);
    SkDgWaitTime(IoC, NS2BCLK(T_CLK_HIGH));
    I2C_CLK_LOW(IoC);
}	/* SkI2cSndBit*/
/** \brief This I2C function generates a Wake-up pulse and delays.
 * \return status of the operation
 */
uint8_t ecc108p_wakeup(void)
{
#if !defined(ECC108_GPIO_WAKEUP) && !defined(ECC108_I2C_BITBANG)

	// Generate wakeup pulse by writing a 0 on the I2C bus.
	uint8_t dummy_byte = 0;
	uint8_t i2c_status = i2c_send_start();
	if (i2c_status != I2C_FUNCTION_RETCODE_SUCCESS)
		return ECC108_COMM_FAIL;

	// To send eight zero bits it takes 10E6 / I2C clock * 8 us.
	delay_10us(ECC108_WAKEUP_PULSE_WIDTH - (uint8_t) (1000000.0 / 10.0 / I2C_CLOCK * 8.0));

	// We have to send at least one byte between an I2C Start and an I2C Stop.
	(void) i2c_send_bytes(1, &dummy_byte);
	i2c_status = i2c_send_stop();
	if (i2c_status != I2C_FUNCTION_RETCODE_SUCCESS)
		return ECC108_COMM_FAIL;
#else
#  if defined(ECC108_I2C_BITBANG)
	// Generate wakeup pulse using the GPIO pin that is connected to SDA.
	I2C_DATA_LOW();
	delay_10us(ECC108_WAKEUP_PULSE_WIDTH);
	I2C_DATA_HIGH();
#  else
	// Generate wakeup pulse by disabling the I2C peripheral and
	// pulling SDA low. The I2C peripheral gets automatically
	// re-enabled when calling i2c_send_start().
	// PORTD is used on the Microbase. You might have to use another
	// port for a different target.
	TWCR = 0;           // Disable I2C.
	//DDRD |= _BV(PD1);   // Set SDA as output.
	//PORTD &= ~_BV(PD1); // Set SDA low.
        pinMode(SDA, OUTPUT);
        digitalWrite(SDA, LOW);
	delay_10us(ECC108_WAKEUP_PULSE_WIDTH);
	//PORTD |= _BV(PD1);  // Set SDA high.
        digitalWrite(SDA, HIGH);
#   endif
#endif

	delay_10us(ECC108_WAKEUP_DELAY);

	return ECC108_SUCCESS;
}
Exemple #3
0
/*
 * Signal a start to the I2C Bus.
 *
 * A start is signaled when data goes to low in a high clock cycle.
 *
 * Ends with Clock Low.
 *
 * Status: not tested
 */
void SkI2cStart(
SK_IOC	IoC)	/* I/O Context */
{
	/* Init data and Clock to output lines */
	/* Set Data high */
	I2C_DATA_OUT(IoC);
	I2C_DATA_HIGH(IoC);
	/* Set Clock high */
	I2C_CLK_HIGH(IoC);

	SkDgWaitTime(IoC, NS2BCLK(T_START_SETUP));

	/* Set Data Low */
	I2C_DATA_LOW(IoC);

	SkDgWaitTime(IoC, NS2BCLK(T_START_HOLD));

	/* Clock low without Data to Input */
	I2C_START_COND(IoC);

	SkDgWaitTime(IoC, NS2BCLK(T_CLK_LOW));
}	/* SkI2cStart */