Rev 150 | Rev 171 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 150 | Rev 154 | ||
---|---|---|---|
Line 65... | Line 65... | ||
65 | #include "led.h" |
65 | #include "led.h" |
66 | #include "spi_slave.h" |
66 | #include "spi_slave.h" |
Line 67... | Line 67... | ||
67 | 67 | ||
68 | 68 | ||
Line 69... | Line 69... | ||
69 | volatile I2C_State_t I2C_State = I2C_OFF; |
69 | volatile I2C_State_t I2C_State = I2C_OFF; |
70 | u8 I2C_StopPolling = 1; |
70 | volatile u8 I2C_StopPolling = 1; |
71 | 71 | ||
72 | // rxbuffer |
72 | // rxbuffer |
Line 188... | Line 188... | ||
188 | I2C1_Timeout = SetDelay(2*I2C1_TIMEOUT); |
188 | I2C1_Timeout = SetDelay(2*I2C1_TIMEOUT); |
189 | I2C_Heading.Heading = -1; |
189 | I2C_Heading.Heading = -1; |
190 | I2C_GenerateSTOP(I2C1, ENABLE); |
190 | I2C_GenerateSTOP(I2C1, ENABLE); |
191 | I2C_State = I2C_IDLE; |
191 | I2C_State = I2C_IDLE; |
Line -... | Line 192... | ||
- | 192 | ||
- | 193 | I2C_StopPolling = 0; // start polling |
|
192 | 194 | ||
193 | UART1_PutString("ok"); |
195 | UART1_PutString("ok"); |
Line 194... | Line 196... | ||
194 | } |
196 | } |
195 | 197 | ||
196 | 198 | ||
197 | //-------------------------------------------------------------- |
199 | //-------------------------------------------------------------- |
198 | void I2C1_Deinit(void) |
200 | void I2C1_Deinit(void) |
199 | { |
201 | { |
200 | GPIO_InitTypeDef GPIO_InitStructure; |
202 | GPIO_InitTypeDef GPIO_InitStructure; |
201 | I2C_State = I2C_OFF; |
203 | I2C_StopPolling = 1;// stop polling |
202 | UART1_PutString("\r\n I2C deinit..."); |
204 | UART1_PutString("\r\n I2C deinit..."); |
- | 205 | I2C_GenerateStart(I2C1, DISABLE); |
|
203 | I2C_GenerateStart(I2C1, DISABLE); |
206 | I2C_GenerateSTOP(I2C1, ENABLE); |
204 | I2C_GenerateSTOP(I2C1, ENABLE); |
207 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
205 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
208 | I2C_State = I2C_OFF; |
206 | I2C_ITConfig(I2C1, DISABLE); |
209 | I2C_ITConfig(I2C1, DISABLE); |
Line 463... | Line 466... | ||
463 | 466 | ||
464 | //---------------------------------------------------------------- |
467 | //---------------------------------------------------------------- |
465 | void I2C1_GetMK3MagVersion(void) |
468 | void I2C1_GetMK3MagVersion(void) |
466 | { |
469 | { |
467 | u8 msg[64]; |
470 | u8 msg[64]; |
468 | u8 repeat = 20; |
471 | u8 repeat; |
Line -... | Line 472... | ||
- | 472 | u32 timeout; |
|
- | 473 | ||
469 | u32 timeout; |
474 | UART1_PutString("\r\n Getting Version from MK3MAG"); |
Line 470... | Line 475... | ||
470 | 475 | // stop polling of other commands |
|
471 | I2C_StopPolling = 1; |
476 | I2C_StopPolling = 1; |
472 | 477 | ||
473 | MK3MAG_Version.Major = 0xFF; |
478 | MK3MAG_Version.Major = 0xFF; |
474 | MK3MAG_Version.Minor = 0xFF; |
479 | MK3MAG_Version.Minor = 0xFF; |
475 | MK3MAG_Version.Patch = 0xFF; |
480 | MK3MAG_Version.Patch = 0xFF; |
- | 481 | MK3MAG_Version.Compatible = 0xFF; |
|
476 | MK3MAG_Version.Compatible = 0xFF; |
482 | // polling of version info |
477 | // polling of version info |
483 | repeat = 0; |
478 | while ((MK3MAG_Version.Major == 0xFF) && (repeat != 0)) |
484 | do |
- | 485 | { |
|
- | 486 | I2C1_SendCommand(I2C_CMD_VERSION); |
|
479 | { |
487 | timeout = SetDelay(250); |
- | 488 | do |
|
- | 489 | { |
|
480 | I2C1_SendCommand(I2C_CMD_VERSION); |
490 | if (MK3MAG_Version.Major != 0xFF) break; // break loop on success |
- | 491 | }while (!CheckDelay(timeout)); |
|
481 | timeout = SetDelay(500); |
492 | UART1_PutString("."); |
482 | while (!CheckDelay(timeout)) if (MK3MAG_Version.Major != 0xFF) break; |
- | |
483 | repeat--; |
493 | repeat++; |
484 | } |
494 | }while ((MK3MAG_Version.Major == 0xFF) && (repeat < 12)); // 12*250ms=3s |
485 | 495 | // if we got it |
|
486 | if (MK3MAG_Version.Major != 0xFF) |
496 | if (MK3MAG_Version.Major != 0xFF) |
487 | { |
497 | { |
488 | sprintf(msg, "\n\r MK3Mag V%d.%d%c", MK3MAG_Version.Major, MK3MAG_Version.Minor, 'a' + MK3MAG_Version.Patch); |
498 | sprintf(msg, "\r\n MK3MAG V%d.%d%c", MK3MAG_Version.Major, MK3MAG_Version.Minor, 'a' + MK3MAG_Version.Patch); |
489 | UART1_PutString(msg); |
499 | UART1_PutString(msg); |
490 | sprintf(msg, " Compatible: %d", MK3MAG_Version.Compatible); |
500 | sprintf(msg, " Compatible: %d", MK3MAG_Version.Compatible); |
Line 491... | Line 501... | ||
491 | UART1_PutString(msg); |
501 | UART1_PutString(msg); |
492 | } |
502 | } |
Line 493... | Line 503... | ||
493 | else UART1_PutString("\n\rNo version information from MK3Mag."); |
503 | else UART1_PutString("\n\r No version information from MK3Mag."); |
494 | 504 | ||
495 | I2C_StopPolling = 0; // enable polling of heading |
505 | I2C_StopPolling = 0; // enable polling of heading command |
496 | } |
506 | } |
Line 497... | Line 507... | ||
497 | 507 | ||
Line 498... | Line 508... | ||
498 | 508 | ||
499 | //---------------------------------------------------------------- |
509 | //---------------------------------------------------------------- |
500 | void I2C1_UpdateCompass(void) |
510 | void I2C1_UpdateCompass(void) |
501 | { |
511 | { |