Subversion Repositories MK3Mag

Compare Revisions

Ignore whitespace Rev 24 → Rev 25

/branches/MK3Mag V0.14 Code Redesign Killagreg/main.c
197,9 → 197,6
// calibration state machine
switch(cal)
{
case 0: // no calibration
break;
 
case 1: // 1st step of calibration
// initialize ranges
// used to change the orientation of the MK3MAG in the horizontal plane
231,7 → 228,7
 
case 5:
// Save values
if(cal != calold) // avoid continously wrinting of eeprom!
if(cal != calold) // avoid continously writing of eeprom!
{
Calibration.X.Range = Xmax - Xmin;
Calibration.X.Offset = (Xmin + Xmax) / 2;
/branches/MK3Mag V0.14 Code Redesign Killagreg/twislave.c
140,7 → 140,7
ISR (TWI_vect)
{
uint8_t data;
 
static uint8_t crc;
// check event
switch (TW_STATUS)
{
199,6 → 199,7
break;
}
Rx_Idx = 0; // set rx buffer index to start of the buffer
crc = data;
}
else // Rx_Idx != 0xFF
{
206,9 → 207,18
// if buffer exist and there is still some free space
if((I2C_RxBuffer != 0) && (Rx_Idx < I2C_RxBufferSize))
{
I2C_RxBuffer[Rx_Idx++] = data;
I2C_RxBuffer[Rx_Idx] = data;
crc += data;
}
// else ignore the data
else if (Rx_Idx == I2C_RxBufferSize) // crc byte was transferred
{
if(crc == data)
{
// copy primary rx buffer to target
}
}
// else ignore data
Rx_Idx++;
}
TWCR_ACK;
return;
216,15 → 226,20
case TW_ST_SLA_ACK: // slave transmitter selected
// reset index to start of tx buffer
Tx_Idx = 0;
// if tx bufer exist and there is at least ine byte to transfer
crc = 0;
// if tx buffer exist and there is at least one byte to transfer
if((I2C_TxBuffer != 0) && (I2C_TxBufferSize > 1))
{
TWDR = I2C_TxBuffer[Tx_Idx++];
data = I2C_TxBuffer[Tx_Idx];
 
}
else
{ // send 0x00 if no tx buffer exist or all bytes of the tx buffer have been transmitted
TWDR = 0x00;
data = 0x00;
}
crc += data;
Tx_Idx++;
TWDR = data;
TWCR_ACK;
return;
 
232,12 → 247,19
// put next byte from tx buffer to the data register
if((I2C_TxBuffer != 0) && (Tx_Idx < I2C_TxBufferSize))
{
TWDR = I2C_TxBuffer[Tx_Idx++];
data = I2C_TxBuffer[Tx_Idx];
crc += data;
}
else if (Tx_Idx == I2C_TxBufferSize)
{ // send crc byte at the end
data = crc;
}
else
{ // send dummy byte instead
TWDR = 0x00;
{
data = 0x00;
}
Tx_Idx++;
TWDR = data;
TWCR_ACK;
return;