コード例 #1
0
ファイル: twi.c プロジェクト: robingreig/raspi-git
void twiShutdown (void)
{
  twiStop           () ;
  twiReleaseBus     () ;
  TWCR &= ~_BV(TWEN) ;
  power_twi_disable () ;
}
コード例 #2
0
ファイル: misc.c プロジェクト: hannes22/xyRobot
uint8_t lcdGetChar(void) {
	uint8_t ret;
	twiStart(LCD_ADDRESS+I2C_READ);
	ret = twiReadAck();
	twiReadNak();
	twiStop();
	return ret;
}
コード例 #3
0
ファイル: gyro.c プロジェクト: xythobuz/xyControl
/** Write a Gyroscope Register.
 * I2C should aready be initialized!
 *
 * \param reg Register Address
 * \param val New Value
 * \returns #TWI_NO_ANSWER, #TWI_WRITE_ERROR or #SUCCESS.
 */
Error gyroWriteByte(uint8_t reg, uint8_t val) {
    if (twiStart(GYRO_ADDRESS | TWI_WRITE)) {
        return TWI_NO_ANSWER;
    }
    if (twiWrite(reg)) {
        return TWI_WRITE_ERROR;
    }
    if (twiWrite(val)) {
        return TWI_WRITE_ERROR;
    }
    twiStop();
    return SUCCESS;
}
コード例 #4
0
ファイル: twi.c プロジェクト: robingreig/raspi-git
static inline uint8_t waitForNextI2Cint (void)
{
  int i = 2000 ;
  while ((TWCR & _BV(TWINT)) == 0)
    if (--i == 0)
    {
      twiStop       () ;			// ack and shutdown
      twiReleaseBus () ;
      return 0 ; // timed out )-:
    }

  return 1 ;
}
コード例 #5
0
ファイル: mag.c プロジェクト: xythobuz/xyControl
/** Write a Magnetometer Register.
 * I2C should aready be initialized!
 *
 * \param reg Register Address
 * \param val New Value
 * \returns #TWI_NO_ANSWER, #TWI_WRITE_ERROR or #SUCCESS.
 */
Error magWriteRegister(uint8_t reg, uint8_t val) {
    if (twiStart(MAG_ADDRESS | TWI_WRITE)) {
        return TWI_NO_ANSWER;
    }
    if (twiWrite(reg)) {
        return TWI_WRITE_ERROR;
    }
    if (twiWrite(val)) {
        return TWI_WRITE_ERROR;
    }
    twiStop();
    return SUCCESS;
}
コード例 #6
0
ファイル: twi.c プロジェクト: robingreig/raspi-git
void twiInit (uint8_t address, uint8_t mask)
{
  power_twi_enable () ; delay (1) ;

  TWSR  = 0 ;
  TWBR  = 0 ;
  TWAR  = address << 1 ;
  TWAMR = mask    << 1 ;
  TWCR  = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) ;

  twiStop       () ;
  twiReleaseBus () ;

#ifdef	DEBUG_TWI_LED
  digitalWrite (DEBUG_TWI_LED, 0) ;
#endif
}
コード例 #7
0
ファイル: arnes_library.cpp プロジェクト: enra64/PKES
uint8_t twiReadFrom(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;
	
	twiReadAck(data);
	
	if(stop)
		twiStop();
	
	return 0;
}
コード例 #8
0
ファイル: misc.c プロジェクト: hannes22/xyRobot
void lcdPutString(char* data) {
	twiStartWait(LCD_ADDRESS+I2C_WRITE);
	while(*data != '\0') {
		lcdCharsSent++;
		if (*data != '\r') {
			if (*data == '\n') {
				twiWrite('\r');
				twiWrite('\n');
				data++;
			} else {
				twiWrite(*data++);
			}
		} else {
			data++;
		}
	}
	twiStop();
	if (lcdCharsSent >= CHARSTOSEND) {
		lcdCharsSent = 0;
		_delay_ms(TIMETOWAIT);
	}
}
コード例 #9
0
ファイル: misc.c プロジェクト: hannes22/xyRobot
void lcdPutChar(char c) {
	twiStartWait(LCD_ADDRESS+I2C_WRITE);
	twiWrite(c);
	twiStop();
}