68,8 → 68,8 |
volatile uint8_t *I2C_TxBuffer = 0, *I2C_RxBuffer = 0; |
volatile uint8_t Tx_Idx = 0, Rx_Idx = 0; |
|
volatile uint8_t I2C_PrimRxBuffer[10]; |
|
|
struct I2C_Heading_t I2C_Heading; |
struct I2C_WriteAttitude_t I2C_WriteAttitude; |
struct I2C_Mag_t I2C_Mag; |
185,9 → 185,7 |
I2C_TxBufferSize = sizeof(I2C_Heading); |
I2C_RxBuffer = (uint8_t *)&I2C_WriteAttitude; |
I2C_RxBufferSize = sizeof(I2C_WriteAttitude); |
// update heading from global variable |
I2C_Heading.Heading = Heading; |
// copy current attitude from I2C rx buffer to uart rx buffer (this is used for the calulation of the heading) |
ExternData.Attitude[NICK] = I2C_WriteAttitude.Nick; |
ExternData.Attitude[ROLL] = I2C_WriteAttitude.Roll; |
break; |
205,16 → 203,27 |
{ |
// fill receiver buffer with the byte that has been received |
// if buffer exist and there is still some free space |
if((I2C_RxBuffer != 0) && (Rx_Idx < I2C_RxBufferSize)) |
if(Rx_Idx < I2C_RxBufferSize) |
{ |
I2C_RxBuffer[Rx_Idx] = data; |
I2C_PrimRxBuffer[Rx_Idx] = data; |
crc += data; |
} |
else if (Rx_Idx == I2C_RxBufferSize) // crc byte was transferred |
{ |
else if (Rx_Idx == I2C_RxBufferSize) // crc byte was transfered |
{ // if checksum matched |
if(crc == data) |
{ // and RxBuffer exist |
if(I2C_RxBuffer != 0) |
{ // copy data to rx buffer |
for(data = 0; data < I2C_RxBufferSize; data++) |
{ |
I2C_RxBuffer[data] = I2C_PrimRxBuffer[data]; |
} |
} |
DebugOut.Analog[31]++; |
} |
else |
{ |
// copy primary rx buffer to target |
DebugOut.Analog[30]++; |
} |
} |
// else ignore data |