Exemplo n.º 1
0
void
I2c_Transmit(int n)
{
	if (n > I2C_BufferSz)
		return ;

	i2cBuff[0] &= ~0x01; 			// fix address , this is the "write" I2C address now
	i2cm_start();
// TODO: need to check for ack and return false if no ACK
	i2cm_out( i2cBuff, n+1);		// sending device address + data to slave
	i2cm_stop();					// transition bus into idle state
}
Exemplo n.º 2
0
// returns one of I2C_ACK, I2C_NAK, I2C_MISSING_SCL_PULLUP or I2C_MISSING_SDA_PULLUP
uint8_t i2cm_txbyte(const uint8_t slave_address, const uint8_t data)
{
    uint8_t rv;
    rv = i2cm_start();
    if (rv != I2C_OK) {
        return rv;
    }
    rv = i2cm_tx(slave_address, I2C_WRITE);
    if (rv == I2C_ACK) {
        rv = i2cm_tx(data, I2C_NO_ADDR_SHIFT);
    }
    i2cm_stop();
    return rv;
}
Exemplo n.º 3
0
// returns one of I2C_ACK, I2C_NAK, I2C_MISSING_SCL_PULLUP or I2C_MISSING_SDA_PULLUP
uint8_t i2cm_rxfrom(const uint8_t slave_address, uint8_t * data,
                    uint16_t length)
{
    uint8_t rv;
    rv = i2cm_start();
    if (rv != I2C_OK) {
        return rv;
    }
    rv = i2cm_tx(slave_address, I2C_READ);
    if (rv == I2C_ACK) {
        i2cm_rx(data, length, 0);
    }
    i2cm_stop();
    return rv;
}
Exemplo n.º 4
0
void
I2c_Receive(int n)		// Read transaction from slave
{
	if (n > I2C_BufferSz)
		return ;

	i2cBuff[0] &= ~0x01; 		// Write address first
	i2cm_start();				// transition from idle state into start condition
	i2cm_out( i2cBuff, 2);		// device address and command address in write mode
//	i2cm_stop(); // not needed
	i2cBuff[0] |= 0x01; 		// Set Read mode address bit

	i2cm_start();				// restart for read phase
	i2cm_out( i2cBuff, 1);		// Device addressed in read mode now
	i2cm_in ( i2cBuff, n);		// Reads from slave with ACK from master
	i2cm_stop();				// transition bus into idle state
	return;
}