Subversion Repositories NaviCtrl

Rev

Rev 326 | Rev 330 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 326 Rev 329
Line 111... Line 111...
111
#define REG_MAG_DATAY_MSB       0x05
111
#define REG_MAG_DATAY_MSB       0x05
112
#define REG_MAG_DATAY_LSB       0x06
112
#define REG_MAG_DATAY_LSB       0x06
113
#define REG_MAG_DATAZ_MSB       0x07
113
#define REG_MAG_DATAZ_MSB       0x07
114
#define REG_MAG_DATAZ_LSB       0x08
114
#define REG_MAG_DATAZ_LSB       0x08
115
#define REG_MAG_STATUS          0x09
115
#define REG_MAG_STATUS          0x09
-
 
116
 
116
#define REG_MAG_IDA                     0x0A
117
#define REG_MAG_IDA                     0x0A
117
#define REG_MAG_IDB                     0x0B
118
#define REG_MAG_IDB                     0x0B
118
#define REG_MAG_IDC                     0x0C
119
#define REG_MAG_IDC                     0x0C
-
 
120
#define REG_MAG_IDF                     0x0F
Line 119... Line 121...
119
 
121
 
120
// bit mask for configuration mode
122
// bit mask for configuration mode
121
#define CRA_MODE_MASK           0x03
123
#define CRA_MODE_MASK           0x03
122
#define CRA_MODE_NORMAL         0x00    //default
124
#define CRA_MODE_NORMAL         0x00    //default
Line 213... Line 215...
213
{
215
{
214
        u8 A;
216
        u8 A;
215
        u8 B;
217
        u8 B;
216
        u8 C;
218
        u8 C;
217
} __attribute__((packed)) Identification_t;
219
} __attribute__((packed)) Identification_t;
218
 
-
 
219
volatile Identification_t NCMAG_Identification;
220
volatile Identification_t NCMAG_Identification;
Line 220... Line 221...
220
 
221
 
221
typedef struct
222
typedef struct
-
 
223
{
-
 
224
        u8 Sub;
-
 
225
} __attribute__((packed)) Identification2_t;
-
 
226
volatile Identification2_t NCMAG_Identification2;
-
 
227
 
-
 
228
typedef struct
222
{
229
{
223
        u8 cra;
230
        u8 cra;
224
        u8 crb;
231
        u8 crb;
225
        u8 mode;
232
        u8 mode;
Line 364... Line 371...
364
        if(RxBufferSize == sizeof(NCMAG_Identification) )
371
        if(RxBufferSize == sizeof(NCMAG_Identification) )
365
        {
372
        {
366
                memcpy((u8 *)&NCMAG_Identification, pRxBuffer, sizeof(NCMAG_Identification));
373
                memcpy((u8 *)&NCMAG_Identification, pRxBuffer, sizeof(NCMAG_Identification));
367
        }
374
        }
368
}
375
}
-
 
376
 
-
 
377
void NCMAG_UpdateIdentification_Sub(u8* pRxBuffer, u8 RxBufferSize)
-
 
378
{       // if number of bytes are matching
-
 
379
        if(RxBufferSize == sizeof(NCMAG_Identification2))
-
 
380
        {
-
 
381
                memcpy((u8 *)&NCMAG_Identification2, pRxBuffer, sizeof(NCMAG_Identification2));
-
 
382
        }
-
 
383
}
-
 
384
 
369
// rx data handler for magnetic sensor raw data
385
// rx data handler for magnetic sensor raw data
370
void NCMAG_UpdateMagVector(u8* pRxBuffer, u8 RxBufferSize)
386
void NCMAG_UpdateMagVector(u8* pRxBuffer, u8 RxBufferSize)
371
{       // if number of bytes are matching
387
{       // if number of bytes are matching
372
        if(RxBufferSize == sizeof(MagRawVector) )
388
        if(RxBufferSize == sizeof(MagRawVector) )
373
        {       // byte order from big to little endian
389
        {       // byte order from big to little endian
Line 531... Line 547...
531
                }
547
                }
532
        }
548
        }
533
        return(retval);
549
        return(retval);
534
}
550
}
Line -... Line 551...
-
 
551
 
-
 
552
u8 NCMAG_GetIdentification_Sub(void)
-
 
553
{
-
 
554
        u8 retval = 0;
-
 
555
        // try to catch the i2c buffer within 100 ms timeout
-
 
556
        if(I2C_LockBuffer(100))
-
 
557
        {
-
 
558
                u16 TxBytes = 0;
-
 
559
                NCMAG_Identification2.Sub = 0xFF;
-
 
560
                I2C_Buffer[TxBytes++] = REG_MAG_IDF;
-
 
561
                // initiate transmission
-
 
562
                if(I2C_Transmission(MAG_SLAVE_ADDRESS, TxBytes, &NCMAG_UpdateIdentification_Sub, sizeof(NCMAG_Identification2)))
-
 
563
                {
-
 
564
                        if(I2C_WaitForEndOfTransmission(100))
-
 
565
                        {
-
 
566
                                if(I2C_Error == I2C_ERROR_NONE) retval = 1;
-
 
567
                        }
-
 
568
                }
-
 
569
        }
-
 
570
        return(retval);
-
 
571
}
-
 
572
 
535
 
573
 
536
// ----------------------------------------------------------------------------------------
574
// ----------------------------------------------------------------------------------------
537
void NCMAG_GetMagVector(void)
575
void NCMAG_GetMagVector(void)
538
{
576
{
539
        // try to catch the I2C buffer within 0 ms
577
        // try to catch the I2C buffer within 0 ms
Line 724... Line 762...
724
        if(retval) NCMAG_MagType = MAG_TYPE_LSM303DLH; // must be a LSM303DLH
762
        if(retval) NCMAG_MagType = MAG_TYPE_LSM303DLH; // must be a LSM303DLH
725
        // polling of identification
763
        // polling of identification
726
        repeat = 0;
764
        repeat = 0;
727
        do
765
        do
728
        {
766
        {
-
 
767
                retval = NCMAG_GetIdentification_Sub();
-
 
768
                if(retval) break; // break loop on success
-
 
769
                UART1_PutString(".");
-
 
770
                repeat++;
-
 
771
        }while(repeat < 12);
-
 
772
        retval = 0;
-
 
773
        do
-
 
774
        {
729
                retval = NCMAG_GetIdentification();
775
                retval = NCMAG_GetIdentification();
730
                if(retval) break; // break loop on success
776
                if(retval) break; // break loop on success
731
                UART1_PutString(".");
777
                UART1_PutString(".");
732
                repeat++;
778
                repeat++;
733
        }while(repeat < 12);
779
        }while(repeat < 12);
-
 
780
 
734
        // if we got an answer to id request
781
        // if we got an answer to id request
735
        if(retval)
782
        if(retval)
736
        {
783
        {
737
                u8 n1[] = "HMC5843";
784
                u8 n1[] = "\n\r HMC5843";
738
                u8 n2[] = "LSM303DLH";
785
                u8 n2[] = "\n\r LSM303DLH";
-
 
786
                u8 n3[] = "\n\r LSM303DLM";
739
                u8* pn;
787
                u8* pn;
-
 
788
               
-
 
789
                pn = n1;
740
                if(NCMAG_MagType == MAG_TYPE_LSM303DLH) pn = n2;
790
                if(NCMAG_MagType == MAG_TYPE_LSM303DLH)
-
 
791
                {
-
 
792
                 if(NCMAG_Identification2.Sub == 0x3c) pn = n3;
741
                else pn = n1;
793
                 else pn = n2;
-
 
794
                }
-
 
795
 
742
                sprintf(msg, " %s ID%d/%d/%d", pn, NCMAG_Identification.A, NCMAG_Identification.B, NCMAG_Identification.C);
796
                sprintf(msg, " %s ID 0x%02x/%02x/%02x-%02x", pn, NCMAG_Identification.A, NCMAG_Identification.B, NCMAG_Identification.C,NCMAG_Identification2.Sub);
743
                UART1_PutString(msg);
797
                UART1_PutString(msg);
744
                if (    (NCMAG_Identification.A == MAG_IDA)
798
                if (    (NCMAG_Identification.A == MAG_IDA)
745
                     && (NCMAG_Identification.B == MAG_IDB)
799
                     && (NCMAG_Identification.B == MAG_IDB)
746
                         && (NCMAG_Identification.C == MAG_IDC))
800
                         && (NCMAG_Identification.C == MAG_IDC))
747
                {
801
                {
748
                        NCMAG_Present = 1;
802
                        NCMAG_Present = 1;
749
                        if(!NCMAG_SelfTest())
-
 
750
                        {
-
 
751
                                UART1_PutString(" Selftest failed!!!!!!!!!!!!!!!!!!!!");
-
 
752
                                LED_RED_ON;
-
 
753
                                NCMAG_IsCalibrated = 0;
-
 
754
                        }
-
 
755
                        else
-
 
756
                        {
803
 
757
                                if(EEPROM_Init())
804
                        if(EEPROM_Init())
758
                                {
805
                                {
759
                                        NCMAG_IsCalibrated = NCMag_CalibrationRead();
806
                                        NCMAG_IsCalibrated = NCMag_CalibrationRead();
760
                                        if(!NCMAG_IsCalibrated) UART1_PutString("\r\n Not calibrated!");
807
                                        if(!NCMAG_IsCalibrated) UART1_PutString("\r\n Not calibrated!");
761
                                }
808
                                }
762
                                else UART1_PutString("\r\n Calibration data not available!!!!!!!!!!!!!!!");
809
                        else UART1_PutString("\r\n EEPROM data not available!!!!!!!!!!!!!!!");
-
 
810
                       
-
 
811
                        if(NCMAG_Identification2.Sub == 0x00)
-
 
812
                        {
-
 
813
                         if(!NCMAG_SelfTest())
-
 
814
                         {
-
 
815
                                UART1_PutString("\r\n Selftest failed!!!!!!!!!!!!!!!!!!!!\r\n");
-
 
816
                                LED_RED_ON;
-
 
817
                                NCMAG_IsCalibrated = 0;
-
 
818
                         }      else UART1_PutString("\r\n Selftest ok");
763
                        }
819
                        }
-
 
820
 
764
                }
821
                }
765
                else
822
                else
766
                {
823
                {
767
                        UART1_PutString("\n\r Not compatible!");
824
                        UART1_PutString("\n\r Not compatible!");
768
                        UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_INCOMPATIBLE;
825
                        UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_INCOMPATIBLE;