Subversion Repositories FlightCtrl

Compare Revisions

Regard whitespace Rev 475 → Rev 476

/branches/v0.60_MicroMag3_Nick666/trunc/twimaster.c
3,10 → 3,9
 
#include "main.h"
 
unsigned char twi_state = 0;
unsigned char motor = 0;
unsigned char motorread = 0;
unsigned char motor_rx[8];
volatile unsigned char twi_state = 0;
volatile unsigned char motor = 0;
volatile unsigned char motor_rx[8];
 
//############################################################################
//Initzialisieren der I2C (TWI) Schnittstelle
43,10 → 42,28
}
 
//############################################################################
// I2C receive byte and send ACK
void i2c_receive_byte(void)
//############################################################################
{
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE) | (1<<TWEA);
}
 
//############################################################################
// I2C receive last byte and send NOT ACK
void i2c_receive_last_byte(void)
//############################################################################
{
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);
}
 
//############################################################################
//Start I2C
SIGNAL (TWI_vect)
//############################################################################
{
static unsigned char motorread = 0;
 
switch (twi_state++) // First i2c_start from SendMotorData()
{
// Master Transmit
72,7 → 89,7
break;
case 2: // Repeat case 0+1 for all Slaves
if (motor < 4) twi_state = 0;
i2c_start(); // Repeated start -> switch salve and switch Master Transmit <-> Master Receive respectively
i2c_start(); // Repeated start -> switch salve or switch Master Transmit -> Master Receive
break;
// Master Receive
79,11 → 96,14
case 3: // Address Slave SL+R
i2c_write_byte(0x53+(motorread*2));
break;
case 4: //1. Byte vom Motor lesen
case 4: //1. Byte vom Motor übertragen
i2c_receive_byte();
break;
case 5: // 1. Byte lesen und 2. Byte übertragen
motor_rx[motorread] = TWDR;
TWCR |= (1<<TWINT);
i2c_receive_last_byte();
break;
case 5: //2. Byte vom Motor lesen
case 6: //2. Byte lesen
motor_rx[motorread+4] = TWDR;
motorread++;
if (motorread > 3) motorread=0;