Rev 141 | Rev 149 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 141 | Rev 146 | ||
---|---|---|---|
Line 86... | Line 86... | ||
86 | volatile I2C_Version_t MK3MAG_Version; |
86 | volatile I2C_Version_t MK3MAG_Version; |
87 | volatile I2C_Cal_t I2C_WriteCal; |
87 | volatile I2C_Cal_t I2C_WriteCal; |
88 | volatile I2C_Cal_t I2C_ReadCal; |
88 | volatile I2C_Cal_t I2C_ReadCal; |
Line 89... | Line 89... | ||
89 | 89 | ||
- | 90 | volatile u8 I2C_ReadRequest = 0; |
|
90 | volatile u8 I2C_ReadRequest = 0; |
91 | #define I2C1_TIMEOUT 500 // 500 ms |
91 | volatile u32 I2C1_Timeout = 0; |
- | |
92 | volatile u32 CheckI2COkay = 0; |
92 | volatile u32 I2C1_Timeout = 0; |
Line 93... | Line 93... | ||
93 | volatile u8 I2C_PrimRxBuffer[10]; // must be larger than any of the secondary rx buffers |
93 | volatile u8 I2C_PrimRxBuffer[10]; // must be larger than any of the secondary rx buffers |
94 | 94 | ||
Line 182... | Line 182... | ||
182 | I2C_ITConfig(I2C1, ENABLE); |
182 | I2C_ITConfig(I2C1, ENABLE); |
Line 183... | Line 183... | ||
183 | 183 | ||
184 | VIC_Config(I2C1_ITLine, VIC_IRQ , PRIORITY_I2C1); |
184 | VIC_Config(I2C1_ITLine, VIC_IRQ , PRIORITY_I2C1); |
Line 185... | Line 185... | ||
185 | VIC_ITCmd(I2C1_ITLine, ENABLE); |
185 | VIC_ITCmd(I2C1_ITLine, ENABLE); |
186 | 186 | ||
187 | I2C1_Timeout = SetDelay(1000); |
187 | I2C1_Timeout = SetDelay(2*I2C1_TIMEOUT); |
188 | I2C_Heading.Heading = -1; |
188 | I2C_Heading.Heading = -1; |
Line 189... | Line 189... | ||
189 | I2C_GenerateSTOP(I2C1, ENABLE); |
189 | I2C_GenerateSTOP(I2C1, ENABLE); |
Line 380... | Line 380... | ||
380 | { |
380 | { |
381 | memcpy((u8 *)I2C_RxBuffer, (u8 *)I2C_PrimRxBuffer, I2C_RxBufferSize); |
381 | memcpy((u8 *)I2C_RxBuffer, (u8 *)I2C_PrimRxBuffer, I2C_RxBufferSize); |
382 | } |
382 | } |
383 | I2C1_Timeout = SetDelay(500); |
383 | I2C1_Timeout = SetDelay(500); |
384 | DebugOut.Analog[15]++; |
384 | DebugOut.Analog[15]++; |
385 | CheckI2COkay++; |
- | |
386 | } |
385 | } |
387 | else // checksum error detected |
386 | else // checksum error detected |
388 | { |
387 | { |
389 | DebugOut.Analog[14]++; |
388 | DebugOut.Analog[14]++; |
390 | } |
389 | } |
Line 488... | Line 487... | ||
488 | UART1_PutString(msg); |
487 | UART1_PutString(msg); |
489 | sprintf(msg, " Compatible: %d", MK3MAG_Version.Compatible); |
488 | sprintf(msg, " Compatible: %d", MK3MAG_Version.Compatible); |
490 | UART1_PutString(msg); |
489 | UART1_PutString(msg); |
491 | } |
490 | } |
492 | else UART1_PutString("\n\rNo version information from MK3Mag."); |
491 | else UART1_PutString("\n\rNo version information from MK3Mag."); |
- | 492 | } |
|
- | 493 | ||
Line -... | Line 494... | ||
- | 494 | ||
- | 495 | //---------------------------------------------------------------- |
|
- | 496 | void I2C1_UpdateCompass(void) |
|
- | 497 | { |
|
- | 498 | static u32 TimerCompassUpdate = 0; |
|
- | 499 | ||
- | 500 | if(I2C_State != I2C_OFF) |
|
- | 501 | { |
|
- | 502 | if (CheckDelay(TimerCompassUpdate)) |
|
- | 503 | { |
|
- | 504 | if(CheckDelay(I2C1_Timeout)) |
|
- | 505 | { |
|
- | 506 | // reset I2C |
|
- | 507 | I2C1_Deinit(); |
|
- | 508 | I2C1_Init(); |
|
- | 509 | } |
|
- | 510 | else |
|
- | 511 | { |
|
- | 512 | // check for incomming compass calibration request |
|
- | 513 | // update CalByte from spi input queue |
|
- | 514 | fifo_get(&CompassCalcStateFiFo, (u8 *)&(I2C_WriteCal.CalByte)); |
|
- | 515 | // send new calstate |
|
- | 516 | if(I2C_ReadCal.CalByte != I2C_WriteCal.CalByte) |
|
- | 517 | { |
|
- | 518 | I2C1_SendCommand(I2C_CMD_WRITE_CAL); |
|
- | 519 | } |
|
- | 520 | else // request current heading |
|
- | 521 | { |
|
- | 522 | I2C1_SendCommand(I2C_CMD_READ_HEADING); |
|
- | 523 | } |
|
- | 524 | } |
|
- | 525 | TimerCompassUpdate = SetDelay(25); // every 25 ms |
|
- | 526 | } |
|
493 | 527 | } |