Subversion Repositories MK3Mag

Compare Revisions

Ignore whitespace Rev 2 → Rev 3

/trunk/Compass_V0_4.hex
File deleted
/trunk/main.c
15,6 → 15,7
signed int MagnetN,MagnetR,MagnetZ; // Kalibrierte Messerte
unsigned int PwmHeading = 0;
unsigned char PC_Connected = 0;
int Heading;
#include "main.h"
 
 
75,7 → 76,7
// if (FromFlightCtrl.IntegralNick > 0) heading = heading + FromFlightCtrl.IntegralNick/60;
if(heading < 361) DebugOut.Analog[14] = heading;
AnFlightCtrl.Heading = heading;
Heading = heading;
PwmHeading = heading + 10;
// MicroMag.Heading = heading;
// DebugOut.Analog[14] = heading;
100,16 → 101,17
UART_Init();
Timer0_Init();
ADC_Init();
InitIC2_Slave();
sei();//Globale Interrupts Einschalten
Debug_Timer = SetDelay(100); // Sendeintervall
InitIC2_Slave(0x50);
 
OffsetN = (CalTabelleHorizontalN[0] + CalTabelleHorizontalN[1] + CalTabelleHorizontalN[2] + CalTabelleHorizontalN[3]) / 4;
OffsetR = (CalTabelleHorizontalR[0] + CalTabelleHorizontalR[1] + CalTabelleHorizontalR[2] + CalTabelleHorizontalR[3]) / 4;
OffsetZ = (CalTabelleHorizontalZ[0] + CalTabelleHorizontalZ[1] + CalTabelleHorizontalZ[2] + CalTabelleHorizontalZ[3]) / 4;
 
VersionInfo.Hauptversion = 0;
VersionInfo.Nebenversion = 3;
VersionInfo.Hauptversion = VERSION_HAUPTVERSION;
VersionInfo.Nebenversion = VERSION_NEBENVERSION;
VersionInfo.PCKompatibel = 7;
/trunk/main.h
57,6 → 57,8
 
extern unsigned int PwmHeading;
extern unsigned char PC_Connected;
extern int Heading;
extern signed int MagnetN,MagnetR,MagnetZ;
#endif //_MAIN_H
 
 
/trunk/makefile
3,7 → 3,7
MCU = atmega168
#-------------------------------------------------------------------
HAUPT_VERSION = 0
NEBEN_VERSION = 4
NEBEN_VERSION = 5
#-------------------------------------------------------------------
 
# Output format. (can be srec, ihex, binary)
/trunk/twislave.c
1,23 → 1,37
/*############################################################################
Slaveadr = 0x52 = Vorne, 0x54 = Hinten, 0x56 = Rechts, 0x58 = Links
############################################################################*/
 
#include <avr/io.h>
#include <util/twi.h>
#include "main.h"
 
unsigned char I2C_RXBuffer;
unsigned char Byte_Counter=0;
unsigned char I2C_RxBufferSize, I2C_TxBufferSize;
unsigned char *I2C_TxBuffer, *I2C_RxBuffer;
unsigned char Tx_Idx=0, Rx_Idx=0, I2C_Direction;
unsigned char I2C_Command;
unsigned char Tx_Idx, Rx_Idx;
 
struct str_I2C_Heading I2C_Heading;
struct str_I2C_WriteNickRoll I2C_WriteNickRoll;
struct str_I2C_Mag I2C_Mag;
struct str_I2C_EEPROM I2C_ReadEEPROM, I2C_WriteEEPROM;
struct str_I2C_Version I2C_Version;
 
 
 
//############################################################################
//I2C (TWI) Interface Init
void InitIC2_Slave(uint8_t adr)
void InitIC2_Slave(void)
//############################################################################
{
TWAR = adr; // Eigene Adresse setzen
TWAR = I2C_SLAVE_ADDRESS; // Eigene Adresse setzen
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE) | (1<<TWEA);
I2C_Version.Hauptversion = VersionInfo.Hauptversion;
I2C_Version.Nebenversion = VersionInfo.Nebenversion;
I2C_Version.Comp = 1;
}
 
#define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC)
//############################################################################
//ISR, die bei einem Ereignis auf dem Bus ausgelöst wird. Im Register TWSR befindet
//sich dann ein Statuscode, anhand dessen die Situation festgestellt werden kann.
27,40 → 41,85
switch (TWSR & 0xF8)
{
case SR_SLA_ACK:
TWCR |= (1<<TWINT);
Byte_Counter=0;
//TWCR |= (1<<TWINT);
Rx_Idx = 0;
TWCR_ACK;
return;
// Daten Empfangen
case SR_PREV_ACK:
I2C_RXBuffer = TWDR;
if (Rx_Idx == 0)
{ I2C_Command = TWDR;
switch(I2C_Command)
{
case I2C_CMD_VERSION:
I2C_TxBuffer = (unsigned char *)&I2C_Version;
I2C_TxBufferSize = sizeof(I2C_Version);
I2C_RxBufferSize = 0;
break;
case I2C_CMD_WRITE_EEPROM:
I2C_TxBufferSize = 0;
I2C_RxBuffer = (unsigned char *)&I2C_WriteEEPROM;
I2C_RxBufferSize = sizeof(I2C_WriteEEPROM);
break;
case I2C_CMD_READ_EEPROM:
I2C_TxBuffer = (unsigned char *)&I2C_ReadEEPROM.Inhalt;
I2C_TxBufferSize = 2;
I2C_RxBuffer = (unsigned char *)&I2C_ReadEEPROM;
I2C_RxBufferSize = 1;
break;
case I2C_CMD_READ_MAG:
I2C_TxBuffer = (unsigned char *)&I2C_Mag;
I2C_TxBufferSize = sizeof(I2C_Mag);
I2C_RxBufferSize = 0;
I2C_Mag.MagX = MagnetN;
I2C_Mag.MagY = MagnetR;
I2C_Mag.MagZ = MagnetZ;
break;
case I2C_CMD_READ_HEADING:
I2C_TxBuffer = (unsigned char *)&I2C_Heading;
I2C_TxBufferSize = sizeof(I2C_Heading);
I2C_RxBuffer = (unsigned char *)&I2C_WriteNickRoll;
I2C_RxBufferSize = sizeof(I2C_WriteNickRoll);
I2C_Heading.Heading = Heading;
WinkelOut.Winkel[NICK] = I2C_WriteNickRoll.Nick;
WinkelOut.Winkel[ROLL] = I2C_WriteNickRoll.Roll;
break;
}
}
else
{
if (Rx_Idx < I2C_RxBufferSize) I2C_RxBuffer[Rx_Idx] = TWDR;
}
Rx_Idx++;
I2C_Timeout = 500;
TWCR |= (1<<TWINT);
//TWCR |= (1<<TWINT);
TWCR_ACK;
return;
// Daten Senden
case SW_SLA_ACK:
if (Byte_Counter==0)
{
TWDR = 0;//Mittelstrom;
Byte_Counter++;
}
else
{
TWDR = 0;//MaxPWM;
}
TWCR |= (1<<TWINT);
Tx_Idx = 0;
if (I2C_TxBufferSize > 0) TWDR = I2C_TxBuffer[Tx_Idx++];
// TWCR |= (1<<TWINT) | (1<< TWEA);
TWCR_ACK;
return;
// Daten Senden
case SW_DATA_ACK:
if (Byte_Counter==0)
{
TWDR = 0;//Mittelstrom;
Byte_Counter++;
}
else
{
TWDR = 0;//MaxPWM;
}
TWCR |= (1<<TWINT);
case SW_DATA_ACK:
if (Tx_Idx < I2C_TxBufferSize) TWDR = I2C_TxBuffer[Tx_Idx++];
else TWDR = 0x00;
//TWCR |= (1<<TWINT) | (1<< TWEA);
TWCR_ACK;
return;
// Bus-Fehler zurücksetzen
case TWI_BUS_ERR_2:
/trunk/twislave.h
1,11 → 1,56
#ifndef _TWI_SLAVE_H_
#define _TWI_SLAVE_H_
 
extern unsigned char I2C_RXBuffer;
extern unsigned char Byte_Counter;
#define I2C_SLAVE_ADDRESS 0x50
 
extern void InitIC2_Slave (uint8_t adr);
#define I2C_CMD_VERSION 0x01
struct str_I2C_Version
{
unsigned char Hauptversion;
unsigned char Nebenversion;
unsigned char Comp;
} ;
 
#define I2C_CMD_WRITE_EEPROM 0x0A
#define I2C_CMD_READ_EEPROM 0x0B
struct str_I2C_EEPROM
{
unsigned char Adresse;
unsigned int Inhalt;
} ;
 
#define I2C_CMD_READ_MAG 0x02
struct str_I2C_Mag
{
int MagX;
int MagY;
int MagZ;
} ;
 
#define I2C_CMD_READ_HEADING 0x03
struct str_I2C_WriteNickRoll
{
int Nick;
int Roll;
} ;
 
struct str_I2C_Heading
{
unsigned int Heading;
} ;
 
 
extern unsigned char Tx_Idx, Rx_Idx, I2C_Direction;
 
extern struct str_I2C_Heading I2C_Heading;
extern struct str_I2C_WriteNickRoll I2C_WriteNickRoll;
extern struct str_I2C_Mag I2C_Mag;
extern struct str_I2C_EEPROM I2C_ReadEEPROM, I2C_WriteEEPROM;
extern struct str_I2C_Version I2C_Version;
 
 
extern void InitIC2_Slave (void);
 
#define TWI_BUS_ERR_1 0x00
#define TWI_BUS_ERR_2 0xF8
 
/trunk/uart.c
31,9 → 31,9
struct str_WinkelOut WinkelOut;
struct str_ExternControl ExternControl;
struct str_VersionInfo VersionInfo;
struct str_AnFlightCtrl AnFlightCtrl;
 
 
 
int Debug_Timer;
 
const unsigned char ANALOG_TEXT[32][16] =
420,7 → 420,7
}
if(KompassAntwort && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
{
SendOutData('K',MeineSlaveAdresse,(unsigned char *) &AnFlightCtrl,sizeof(AnFlightCtrl));
SendOutData('K',MeineSlaveAdresse,(unsigned char *) &I2C_Heading,sizeof(I2C_Heading));
KompassAntwort = 0;
}
}
/trunk/uart.h
24,12 → 24,9
signed int Winkel[2];
};
extern struct str_WinkelOut WinkelOut;
#define NICK 0
#define ROLL 1
 
struct str_AnFlightCtrl
{
int Heading;
};
extern struct str_AnFlightCtrl AnFlightCtrl;
 
struct str_ExternControl
{