Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 440 → Rev 441

/branches/v0.60_MicroMag3_Nick666/trunc/compass.h
23,7 → 23,7
uint16_t Z_range;
};
 
extern struct MM3_working_struct MM3;
struct MM3_working_struct MM3;
extern struct MM3_calib_struct MM3_calib;
 
void init_MM3(void);
/branches/v0.60_MicroMag3_Nick666/trunc/twimaster.c
3,9 → 3,6
 
#include "main.h"
 
unsigned char twi_state = 0;
unsigned char motor = 0;
unsigned char motorread = 0;
unsigned char motor_rx[8];
 
//############################################################################
19,15 → 16,14
 
//############################################################################
//Start I2C
char i2c_start(void)
void i2c_start(void)
//############################################################################
{
TWCR = (1<<TWSTA) | (1<<TWEN) | (1<<TWINT) | (1<<TWIE);
return(0);
}
 
//############################################################################
//Start I2C
//Stop I2C
void i2c_stop(void)
//############################################################################
{
35,23 → 31,23
}
 
//############################################################################
//Start I2C
char i2c_write_byte(char byte)
//Write to I2C
void i2c_write_byte(char byte)
//############################################################################
{
TWSR = 0x00;
{
TWDR = byte;
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);
return(0);
}
 
//############################################################################
//Start I2C
//ISR
SIGNAL (TWI_vect)
//############################################################################
{
static unsigned char twi_state = 0;
static unsigned char motor = 0;
static unsigned char motorread = 0;
switch (twi_state++)
{
case 0:
75,9 → 71,7
}
break;
case 2:
i2c_stop();
if (motor<4) twi_state = 0;
else motor = 0;
i2c_start();
break;
86,46 → 80,19
i2c_write_byte(0x53+(motorread*2));
break;
case 4:
switch(motorread)
{
case 0:
i2c_write_byte(Motor_Vorne);
break;
case 1:
i2c_write_byte(Motor_Hinten);
break;
case 2:
i2c_write_byte(Motor_Rechts);
break;
case 3:
i2c_write_byte(Motor_Links);
break;
}
i2c_write_byte(0xFF);
break;
case 5: //1 Byte vom Motor lesen
case 5: // 1. Byte vom Motor lesen
motor_rx[motorread] = TWDR;
case 6:
switch(motorread)
{
case 0:
i2c_write_byte(Motor_Vorne);
break;
case 1:
i2c_write_byte(Motor_Hinten);
break;
case 2:
i2c_write_byte(Motor_Rechts);
break;
case 3:
i2c_write_byte(Motor_Links);
break;
}
break;
case 7: //2 Byte vom Motor lesen
i2c_write_byte(0xFF);
break;
case 6: // 2. Byte vom Motor lesen
motor_rx[motorread+4] = TWDR;
motorread++;
if (motorread>3) motorread=0;
default:
i2c_stop();
twi_state = 0;
motor = 0;
}
}
/branches/v0.60_MicroMag3_Nick666/trunc/twimaster.h
18,15 → 18,15
 
//############################################################################
 
extern unsigned char twi_state;
extern unsigned char motor;
extern unsigned char motorread;
volatile unsigned char twi_state;
volatile unsigned char motor;
volatile unsigned char motorread;
extern unsigned char motor_rx[8];
 
 
void i2c_init (void); // I2C initialisieren
char i2c_start (void); // Start I2C
void i2c_start (void); // Start I2C
void i2c_stop (void); // Stop I2C
char i2c_write_byte (char byte); // 1 Byte schreiben
void i2c_write_byte (char byte); // 1 Byte schreiben
 
#endif