Exemplo n.º 1
0
void wrReg(uint8_t reg,uint8_t dat){
	//send start condition
	twiStart();
	twiWriteByte(OV7670_I2C_ADDRESS<<1,TW_MT_SLA_ACK);
	twiWriteByte(reg,TW_MT_DATA_ACK);
	twiWriteByte(dat,TW_MT_DATA_ACK);
	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);//send stop
	_delay_ms(1);
}
Exemplo n.º 2
0
void wrReg(uint8_t reg,uint8_t dat){
	//send start condition
	PORTG|=1<<5;
	twiStart();
	twiAddr(camAddr_WR,TW_MT_SLA_ACK);
	twiWriteByte(reg,TW_MT_DATA_ACK);
	twiWriteByte(dat,TW_MT_DATA_ACK);
	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);//send stop
	_delay_ms(1);
	PORTG&=~(1<<5);
}
Exemplo n.º 3
0
uint8_t rdReg(uint8_t reg){
	uint8_t dat;
	twiStart();
	twiWriteByte(OV7670_I2C_ADDRESS<<1,TW_MT_SLA_ACK);
	twiWriteByte(reg,TW_MT_DATA_ACK);
	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);//send stop
	_delay_ms(1);
	twiStart();
	twiWriteByte((OV7670_I2C_ADDRESS<<1)|1,TW_MR_SLA_ACK);
	dat=twiRd(1);
	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);//send stop
	_delay_ms(1);
	return dat;
}
Exemplo n.º 4
0
/*
 * Desc		Create a START condition, send slave address, send data byte, send stop
 *			ALWAYS BEGIN with start, then ALWAYS an address, then data.
 * Input	repeated: whether we are in a repeated phase
 * Output	0: success
 *			1: start error
 *			2: address send error
 *			3: data send error
 */
uint8_t twiWriteTo(uint8_t address, uint8_t data, bool repeated, bool stop){
	//send START condition, abort if error
	if(!twiStart(repeated))
		return 1;
		
	//send ADDRESS
	//shift the address to the left and add write bit, send.
	twiWriteByte((MPU9150_ADDRESS << 1) + TW_WRITE);
	//check for address send f**k-up
	if(TW_STATUS != TW_MT_SLA_ACK)
		return 2;
		
	//send first DATA byte
	twiWriteByte(data);
	//check for data send f**k-up
	if(TW_STATUS != TW_MT_DATA_ACK)
		return 3;
	
	if(stop)
		twiStop();
		
	return 0;
}
Exemplo n.º 5
0
uint8_t rdReg(uint8_t reg){
	PORTG|=1<<5;
	uint16_t dat;
	twiStart();
	twiAddr(camAddr_WR,TW_MT_SLA_ACK);
	twiWriteByte(reg,TW_MT_DATA_ACK);
	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);//send stop
	_delay_ms(1);
	twiStart();
	twiAddr(camAddr_RD,TW_MR_SLA_ACK);
	dat=twiRd(1);
	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);//send stop
	_delay_ms(1);
	PORTG&=~(1<<5);
	return dat;
}