예제 #1
0
uint16_t getGyroSample(uint16_t index, uint8_t *array){
	startI2C(MPU9150ADDR, WRITE);
		writeI2C(0x43);
	stopI2C();
	startI2C(MPU9150ADDR, READ);
		for(uint8_t k=0; k<6; k++){
			if(index > 54-1) break;
			uint8_t ackType = (k < (6-1))? ACK : NACK ;
			array[index++] = readI2C(ackType);
		}
	stopI2C();
	return index;
}
예제 #2
0
int read2I2C(unsigned char addr) {
  	unsigned char val_high, val_low;
    startI2C(addr, I2C_READ);
    val_high = readI2C(1);
  	val_low = readI2C(0);
    stopI2C();
  	return ((unsigned int)val_high << 8L) | val_low;
}
예제 #3
0
void MPU9150Mode(int8_t mode){
	if(mode == SLEEP){ // || mode == ARMED){
		startI2C(MPU9150ADDR, WRITE);
			writeI2C(0x6B); // PWR_MGMT_1
			writeI2C(1<<6); // SLEEP bit set
		stopI2C();
	}
	else{ //if(mode == ACTIVE){
		startI2C(MPU9150ADDR, WRITE);
			writeI2C(0x6B); // PWR_MGMT_1
			writeI2C(0x03); // Z-Axis Gyro Reference
		stopI2C();
		_delay_ms(1);
		startI2C(MPU9150ADDR, WRITE);
			writeI2C(0x19); // SMPRT_DIV
			writeI2C(0x00); // SMPRT_DIV
			writeI2C(0x00); // CONFIG
			writeI2C(3<<3); // GYRO_CONFIG
			writeI2C((3<<3)|(0)); // ACCEL_CONFIG
		stopI2C();
	}
}
예제 #4
0
void setTime (tTime localTime)
{
    startI2C();
    sendI2C(PCF_ADDR_W);
    sendI2C(PCF_SECONDS);
    /*Auto Inkrement..*/

    sendI2C(ITOBCD(localTime.Sec));
    sendI2C(ITOBCD(localTime.Min));
    sendI2C(ITOBCD(localTime.Hour));

    /*Jahres ID# ermitteln (0..3 wobei 0: Schaltjahr*/
    sendI2C((((localTime.Year-YEAR_ID)%4)<<6) | ITOBCD(localTime.Day));
    sendI2C((localTime.wDay <<5) | ITOBCD(localTime.Month));
    stopI2C();
}
예제 #5
0
void initPCF8583 (void)
{
    startI2C();
    sendI2C(PCF_ADDR_W);
    sendI2C(PCF_CONTROL);
    sendI2C(PCF_SET_CONTROL);
    stopI2C();

    /*Direkt die Uhrzeit aus der RTC beziehen*/
    getTime();
    /*Das Jahr aus dem EEPROM*/
    time.Year = eeprom_read(EEPROM_YEAR);
    time.Year += 2000;

    if(time.Year > 2100)
    {
        time.Year = 2015;
    }
}
예제 #6
0
void write2I2C(unsigned char addr, unsigned char val1, unsigned char val2) {
  	startI2C(addr, I2C_WRITE);
  	writeI2C(val1);
  	writeI2C(val2);
  	stopI2C();
}
예제 #7
0
void write1I2C(unsigned char addr, unsigned char val) {
	startI2C(addr, I2C_WRITE);
  	writeI2C(val);
  	stopI2C();
}
예제 #8
0
tTime getTime (void)
{
    uint8_t tmp;
    tTime localTime;

    /*Default wird davon ausgegeangen, dass es sich
     nicht um ein Schaltjahr handelt*/
    localTime.sYear = false;

    /*Setzten des Adresspointers der RTC*/
    startI2C();
    sendI2C(PCF_ADDR_W);
    sendI2C(PCF_SECONDS);
    startI2C();
    sendI2C(PCF_ADDR_R);

    tmp = reciveI2C_ack();
    localTime.Sec = BCDTOI(tmp);
    tmp = reciveI2C_ack();
    localTime.Min = BCDTOI(tmp);
    tmp = reciveI2C_ack();
    localTime.Hour = BCDTOI(tmp);
    tmp = reciveI2C_ack();
    localTime.Day = BCDTOI((0x3F & tmp));

    /*Jahres ID ermitteln (ist es ein Schaltjahr?)*/
    if( (tmp & 0xC0) == 0x00 )
    {
        localTime.sYear = true;
    }

    tmp = reciveI2C_nack();
    localTime.Month = BCDTOI((0x1F & tmp));
    localTime.wDay = BCDTOI(((0xE0 & tmp))>>5);

    stopI2C();

    /*Anpassung an Sommer-/Winterzeit*/
    if(time.stime == MESZ)
    {
        if( localTime.Month == 10 && localTime.wDay == Sonntag && localTime.Day >= 25 && localTime.Hour == 3 )
        {
            localTime.stime = MEZ;
            localTime.Hour--;
            setTime(localTime);
        }
    }

    if(time.stime == MEZ)
    {
        if( localTime.Month == 3 && localTime.wDay == Sonntag && localTime.Day >= 25 && localTime.Hour == 2 )
        {
            localTime.stime = MESZ;
            localTime.Hour++;
            setTime(localTime);
        }
    }

    /*Jahresinformation wird nicht durch die RTC gespeichert*/
    localTime.Year = time.Year;

    return localTime;
}