Rev 3734 Rev 3735
Line 20... Line 20...
20 #define MR PIN_E2 // external counter master reset 20 #define MR PIN_E2 // external counter master reset
21 #define CLKI PIN_C0 // internal counter input 21 #define CLKI PIN_C0 // internal counter input
22   22  
23 unsigned int32 count; // count per second 23 unsigned int32 count; // count per second
24   24  
-   25 int1 fire_setup; // flag for sending setup to GPS
-   26  
25 #define BUF_LEN 4 27 #define BUF_LEN 4
26 int8 buffer[BUF_LEN]; // I2C buffer 28 int8 buffer[BUF_LEN]; // I2C buffer
27 int8 address=0; 29 int8 address=0;
28   30  
29 unsigned int16 of=0; // count of overflow 31 unsigned int16 of=0; // count of overflow
-   32  
-   33 // 1x 100 us per 10 s UTC synchronised; 40 configuration bytes
30 34 char cmd[50]={40, 0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x80, 0x96, 0x98, 0x00, 0xE0, 0xC8, 0x10, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0xC6, 0x51};
-   35  
31 // configure GPS 36 // configure GPS
32 void setup_GPS() 37 void setup_GPS()
33 { 38 {
34 // 1x 100 us per 10 s UTC synchronised -  
35 const char cmd[40]={0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x80, 0x96, 0x98, 0x00, 0xE0, 0xC8, 0x10, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0xC6, 0x51}; -  
36 int n; 39 int n;
-   40 int len;
-   41 len=cmd[0];
37 for (n=0;n<40;n++) putc(cmd[n]); 42 for (n=1;n<=len;n++) putc(cmd[n]);
38 } 43 }
39   44  
40 #INT_SSP 45 #INT_SSP
41 void ssp_interupt () 46 void ssp_interupt ()
42 { 47 {
Line 50... Line 55...
50   55  
51 if(state == 1) //Second received byte is address of register 56 if(state == 1) //Second received byte is address of register
52 { 57 {
53 address = incoming; 58 address = incoming;
54 } 59 }
-   60  
-   61 if(state == 2) //Thid received byte are configuration data
-   62 {
-   63 if ((address==0)&&(incoming==0))
-   64 {
-   65 fire_setup = 1; // Write configuration to the GPS if configuration data length is 0
-   66 }
-   67 else
-   68 {
-   69 cmd[address] = incoming; // Store byte to configuration sentence
-   70 }
-   71 }
55 } 72 }
56 if(state == 0x80) //Master is requesting data 73 if(state == 0x80) //Master is requesting data
57 { 74 {
58 //i2c_read(); // Dummy read of I2C device address 75 //i2c_read(); // Dummy read of I2C device address
59 76
Line 62... Line 79...
62 buffer[0]=make8(count,0); 79 buffer[0]=make8(count,0);
63 buffer[1]=make8(count,1); 80 buffer[1]=make8(count,1);
64 buffer[2]=make8(count,2); 81 buffer[2]=make8(count,2);
65 buffer[3]=make8(count,3); 82 buffer[3]=make8(count,3);
66 } 83 }
-   84 if(address <= BUF_LEN)
-   85 {
67 if(address <= BUF_LEN) i2c_write(buffer[address]); // Prepare one byte to SSP buffer 86 i2c_write(buffer[address]); // Prepare one byte to SSP buffer
-   87 }
68 else 88 else
69 { 89 {
70 i2c_write(0x00); // There is nothing to prepare, so zero 90 i2c_write(0x00); // There is nothing to prepare, so zero
71 } 91 }
72 } 92 }
73   93  
Line 79... Line 99...
79 { 99 {
80 i2c_write(buffer[2]); // Prepare next byte to SSP buffer 100 i2c_write(buffer[2]); // Prepare next byte to SSP buffer
81 } 101 }
82 if(state == 0x83) //Master is requesting data 102 if(state == 0x83) //Master is requesting data
83 { 103 {
84 i2c_write(buffer[3]); // Prepare next byte to SSP buffer 104 i2c_write(buffer[3]); // Prepare next byte to SSP buffer
85 -  
86 setup_GPS(); -  
87 } 105 }
88   106  
89 if(state > 0x83) //Master is requesting data 107 if(state > 0x83) //Master is requesting data
90 { 108 {
91 i2c_write(0x00); // There is nothing to prepare, so zero 109 i2c_write(0x00); // There is nothing to prepare, so zero
Line 161... Line 179...
161 buffer[0]=0x0; // Clear I2C output buffer 179 buffer[0]=0x0; // Clear I2C output buffer
162 buffer[1]=0x0; 180 buffer[1]=0x0;
163 buffer[2]=0x0; 181 buffer[2]=0x0;
164 buffer[3]=0x0; 182 buffer[3]=0x0;
165   183  
166 printf("\r\ncvak...\r\n"); 184 //printf("\r\ncvak...\r\n");
-   185
-   186 fire_setup = 0;
167   187  
168 while(true) 188 while(true)
169 { 189 {
170 restart_wdt(); 190 restart_wdt();
171 delay_ms(1500); 191 delay_ms(1000);
-   192 if (fire_setup)
-   193 {
-   194 setup_GPS(); // Write configuration to the GPS
-   195 fire_setup = 0;
-   196 }
172 // printf("%X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]); 197 //printf("%X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]);
173 printf("%010Lu\r\n", count); 198 //printf("%010Lu\r\n", count);
174 } 199 }
175 } 200 }