• R/O
  • HTTP
  • SSH
  • HTTPS

cpu2010: Commit

サブCPU2010のPICプログラム
ADデータ取得とGPS時刻付けを行いLinux部にデータを出力します。


Commit MetaInfo

Revisão67e3bba2402eac306d925f2e070e04063e7d59c1 (tree)
Hora2011-12-15 23:51:22
AutorNaoya Takamura <ntaka206@user...>
CommiterNaoya Takamura

Mensagem de Log

timepulse1 1Hz: GPS時刻fixしなくても出力するようにした
ADbufType

add attribute((packed))
add rescode field
add resdata[] field

SPI CMD rcv add

Mudança Sumário

Diff

--- a/main.c
+++ b/main.c
@@ -44,12 +44,18 @@ _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2 )
4444 */
4545 #define ADBUF_BYTE 3 // AD 1CH 1sample dataのbyte数
4646 #define ADBUF_LEN sizeof(ADbufType) // 1dataの長さ byte $含まず
47+#define RESDATA_LEN 17 // コマンドに対する返答データ 最大長さ
4748
49+// SPI送信にそのまま使われるので注意!
4850 typedef struct {
51+ unsigned char rescode; // コマンドに対する返答 ACK/NAK/NUL
52+ unsigned char resdata[RESDATA_LEN]; // コマンドに対する返答データ
4953 UbloxNavTimeUtc t; // タイムスタンプ
5054 long data1sec[AD_CHNUM]; // 1sec平均値
5155 unsigned char data[AD_CHNUM][ADBUF_BYTE*AD_SAMPLE]; // AD_SAMPLE[Hz]のデータ
56+ int cheksum;
5257 } ADbufType;
58+//} __attribute__((__packed__)) ADbufType;
5359 static ADbufType adbuf[RING_NUM];
5460
5561 // SPI外部送信用バッファ AD_SAMPLE[Hz]
@@ -109,8 +115,20 @@ inline void adbuf_time_write(char buf_no, UbloxNavTimeUtc *t)
109115 my_memcpy(adbuf_time_get(buf_no), t, sizeof(UbloxNavTimeUtc));
110116 }
111117
112-/**** ublox *************************************************/
118+/**** SPI CMD受信バッファ
119+ */
120+#define SPI_RX_LEN 20 // Overoから受信するコマンド長 $含む
121+static char spi_rx_buf[SPI_RX_LEN];
122+static char spi_rx_cnt; // 受信文字数カウント
123+
124+#define CMD_STS_NONE 0 // 有効なコマンド無し
125+#define CMD_STS_RCVD 1 // 有効なコマンド受け取った
126+static char spi_cmd_sts; // コマンド受信状態
113127
128+/**** ublox ************************************************
129+ */
130+static UbloxNavTimeUtc gpsNow;
131+#if 0
114132 void test_ublox_rcv_mon(void)
115133 {
116134 unsigned char class, id;
@@ -135,7 +153,7 @@ void test_ublox_rcv_mon(void)
135153
136154 }
137155 }
138-static UbloxNavTimeUtc gpsNow;
156+#endif
139157 static void ublox_rcv(void)
140158 {
141159 unsigned char class, id;
@@ -158,7 +176,6 @@ static void ublox_rcv(void)
158176 */
159177 }
160178 }
161-
162179 /**** INT1/SPI1 ***********************************************/
163180 /*
164181 * INT1 Int及びSPI1 IntでADのデータを取得する
@@ -294,6 +311,34 @@ void test_spi_send(void)
294311 }
295312
296313 }
314+// ADレジスタgetして表示
315+void test_ad_get_config(void)
316+{
317+ int cs = AD_CH1_CS;
318+ int i;
319+ unsigned char reg[9];
320+ char sz[64];
321+
322+ ad_cs(cs);
323+ ad_spi_send(ADCMD_SDATAC);
324+ ad_cs_dis();
325+ ad_cs(cs);
326+ ad_spi_rcv(ADCMD_RREG | 0); // Register read command
327+ ad_spi_rcv(9 - 1); // 9byte write
328+#if 1
329+ for(i = 0; i < 9; i++) {
330+ reg[i] = ad_spi_rcv(0);
331+ }
332+#endif
333+ ad_cs_dis();
334+
335+ for(i = 0; i < 9; i++) {
336+ sprintf(sz, "%d: %02X\r\n", i, reg[i]);
337+ PDEBUG(sz);
338+ }
339+
340+}
341+
297342 /*
298343 * main()
299344 */
@@ -357,12 +402,12 @@ int main(int argc, char** argv) {
357402 CNPU2bits.CN20PUE = 1; // Pullup ON
358403 cnint_level_set(4);
359404
360-
361405 adint_cnt = 0;
362406 ad_cs_dis();
363407 sts_set(STS_NOSYNC);
364408 pps_intf_clear();
365409 DRDY_OUT = 1;
410+ spi_cmd_sts = CMD_STS_NONE;
366411
367412 // GPS UART1初期設定 BRGH=Standard mode
368413 // 9600bps 8bit nonparity 1stop nonflowcnt.
@@ -383,16 +428,9 @@ int main(int argc, char** argv) {
383428 spi2_init();
384429 spi1_int_disable();
385430 spi2_int_disable();
386- spi2_putc('$');
431+ spi2_putc('$'); // 一番最初のデータ送信のためにセットしておく
387432
388433 PDEBUG("START\r\n");
389- puts("START debug\r\n");
390- sprintf(sz, "RPINR20=%04X\r\n", RPINR20);
391- PDEBUG(sz);
392- sprintf(sz, "SPI1CON1=%04X\r\n", SPI1CON1);
393- PDEBUG(sz);
394- sprintf(sz, "SPI1CON2=%04X\r\n", SPI1CON2);
395- PDEBUG(sz);
396434 sprintf(sz, "sizeof(ADBUF)=%d\r\n", ADBUF_LEN);
397435 PDEBUG(sz);
398436
@@ -416,6 +454,11 @@ int main(int argc, char** argv) {
416454 ublox_rcvbuf_clear();
417455 ublox_send_cfg_tp5_timepulse2();
418456 ublox_rcv_ack();
457+ // TimePulse1をGPS時刻fixしなくても出力する
458+ // pulse幅 unlocked=500msec locked=100msec
459+ ublox_rcvbuf_clear();
460+ ublox_send_cfg_tp5_timepulse1();
461+ ublox_rcv_ack();
419462 // NAV-TIMEUTC出力させる
420463 ublox_send_cfg_msg();
421464 ublox_rcv_ack();
@@ -438,16 +481,17 @@ int main(int argc, char** argv) {
438481 // INT1ハンドラ内で有効にされる
439482 spi1_intf_clear();
440483 spi1_set_int_level(4);
484+ // DataOut SPI2 割り込み許可しない CSのCN INTで許可するので
485+ spi2_intf_clear();
486+ spi2_set_int_level(4);
441487
488+ /**** ペリフェラル割り込み許可 INT1/INT0/CN ************************/
442489 // INT1割り込み許可
443490 int1_intf_clear();
444491 int1_int_enable(); // Int enable
445492 // INT0割り込み許可
446493 int0_intf_clear();
447494 int0_int_enable(); // Int enable
448- // DataOut SPI2 割り込み許可しない CSのCN INTで許可するので
449- spi2_intf_clear();
450- spi2_set_int_level(4);
451495 // ChangeNotification INT許可 SPI2(Overo) CS
452496 cnint_intf_clear();
453497 cnint_int_enable();
@@ -485,26 +529,14 @@ int main(int argc, char** argv) {
485529 #endif
486530 ring_read2_plus();
487531 }
488- }
489-/*
490- if (pps_is_intf_enable()) {
491- pps_intf_clear();
492- PDEBUG("pps\r\n");
532+ // SPIからコマンド受信
533+ if (spi_cmd_sts == CMD_STS_RCVD) {
534+ sprintf(sz, "CMD RCV: %02X %02X %02X %02X\r\n", spi_rx_buf[0], spi_rx_buf[1], spi_rx_buf[2], spi_rx_buf[3]);
535+ PDEBUG(sz);
536+ spi_cmd_sts = CMD_STS_NONE;
493537 }
494- i = 0;
495- while(1) {
496- if (ring_read_get() != ring_write_get()) {
497- char ch;
498- for(ch=0; ch<AD_CHNUM; ch++) {
499- sprintf(sz, "%+7ld,", adbuf_1sec[ring_read_get()][ch]);
500- PDEBUG(sz);
501- }
502- PDEBUG("\r\n");
503538
504- ring_read_plus();
505- }
506539 }
507-*/
508540
509541 return (EXIT_SUCCESS);
510542 }
@@ -513,7 +545,7 @@ int main(int argc, char** argv) {
513545 *
514546 *
515547 */
516-void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void)
548+void __attribute__((interrupt, no_auto_psv, shadow)) _INT0Interrupt(void)
517549 {
518550 // AD STARTピン=H
519551 ad_start_ena();
@@ -533,8 +565,7 @@ void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void)
533565 ad_start_dis();
534566 sts_set(STS_SYNCNOW1);
535567 } else if (sts_get() == STS_SYNCNOW1) {
536- // AD STARTピン=H
537-// ad_start_ena();
568+ // AD STARTピン=H 関数先頭で行っているのでここではやらない
538569 sts_set(STS_SYNCWAIT);
539570 } else if (sts_get() == STS_SYNCWAIT) {
540571 sts_set(STS_SYNCED);
@@ -653,7 +684,6 @@ void __attribute__((interrupt, auto_psv)) _SPI1Interrupt(void)
653684 * DataOut SPI2 Interrupt Handler
654685 * TX FIFOに1byteの空きが出来ると発生
655686 */
656-//static unsigned char spi2c;
657687 void __attribute__((interrupt, no_auto_psv)) _SPI2Interrupt(void)
658688 {
659689 unsigned char rx;
@@ -662,17 +692,24 @@ void __attribute__((interrupt, no_auto_psv)) _SPI2Interrupt(void)
662692 // 送信
663693 while(SPI2_TBF == 0) {
664694 if (dataout_cnt_get() <= 0) break;
665-// spi2_putc(spi2c++);
666695 spi2_putc(*dout_ptr++);
667696 dataout_cnt_minus();
668697 }
669698 // 受信
670699 while(SPI2_SRXMPT == 0) {
671700 rx = spi2_getc();
701+ if (spi_cmd_sts == CMD_STS_NONE && spi_rx_cnt < SPI_RX_LEN) {
702+ spi_rx_buf[spi_rx_cnt] = rx;
703+ spi_rx_cnt++;
704+ if (spi_rx_cnt >= SPI_RX_LEN) {
705+ if (spi_rx_buf[0] != 0) {
706+ spi_cmd_sts = CMD_STS_RCVD;
707+ }
708+ }
709+ }
672710 }
673711
674712 // オーバーランエラーならばクリアする
675- // spi2_rx_is_overrun()
676713 if (SPI2STATbits.SPIROV == 1) SPI2STATbits.SPIROV = 0;
677714
678715 }
@@ -703,15 +740,17 @@ void __attribute__((interrupt, no_auto_psv)) _CNInterrupt(void)
703740 // リングバッファ読み込み位置get
704741 dout_ptr = (char*)adbuf_get(ring_read1_get());
705742 // SPI送信の一番最初
706-// spi2c = 0;
707743 dataout_cnt_set(ADBUF_LEN);
708744 // SPI2 TX FIFOに送信データ書き込み
709745 while(SPI2_TBF == 0) {
710746 if (dataout_cnt_get() <= 0) break;
711-// spi2_putc(spi2c++);
712747 spi2_putc(*dout_ptr++);
713748 dataout_cnt_minus();
714749 }
750+ if (spi_cmd_sts == CMD_STS_NONE) {
751+ // SPI受信文字数カウンタクリア
752+ spi_rx_cnt = 0;
753+ }
715754 // SPI2割り込みON
716755 spi2_int_enable();
717756 // DRDY=H
--- a/myad.c
+++ b/myad.c
@@ -1,7 +1,8 @@
11 /*
22 * ADS1259
33 *
4- * ADデータSPIエンディアン MSB first
4+ * AD
5+ * SPIエンディアン MSB first
56 */
67 #include <p24FJ64GA004.h>
78 #include <libpic30.h>
@@ -10,28 +11,6 @@
1011 #include "myspi.h"
1112 #include "myad.h"
1213
13-
14-#if 0
15-// AD DRDY0 INTフラグ 1=INTかかった 0=なし
16-static char ad_drdy0_int;
17-// AD DRDY0 INTフラグ
18-void ad_drdy0_intf_set(void)
19-{
20- ad_drdy0_int = 1;
21-}
22-void ad_drdy0_intf_clear(void)
23-{
24- ad_drdy0_int = 0;
25-}
26-char ad_is_drdy0_intf(void)
27-{
28- if (ad_drdy0_int == 1) {
29- return 1;
30- }
31- return 0;
32-}
33-#endif
34-
3514 void ad_cs_init(void)
3615 {
3716 asm("NOP");
@@ -41,50 +20,6 @@ void ad_cs_init(void)
4120 asm("NOP");
4221 CS_DATA = 0;
4322 }
44-# if 0
45-/*
46- int cs: 0〜15
47- */
48-void ad_cs(unsigned char cs)
49-{
50- unsigned char i;
51-
52-//CS_CLK = 1;
53- for(i = 16; i > 0; i--) {
54- if (i == cs+1) {
55- CS_DATA = 0;
56- } else {
57- CS_DATA = 1;
58- }
59- asm("NOP");
60- CS_CLK = 1;
61- CS_CLK = 0;
62- }
63- asm("NOP");
64- CS_RCLK = 1;
65- asm("NOP");
66- CS_DATA = 0;
67- asm("NOP");
68- CS_RCLK = 0;
69-}
70-
71-void ad_cs_dis(void)
72-{
73- unsigned char i;
74-
75- CS_DATA = 1;
76- for(i = 16; i > 0; i--) {
77- CS_CLK = 1;
78- CS_CLK = 0;
79- }
80- asm("NOP");
81- CS_RCLK = 1;
82- asm("NOP");
83- CS_DATA = 0;
84- asm("NOP");
85- CS_RCLK = 0;
86-}
87-#endif
8823
8924 void ad_reset(void)
9025 {
@@ -106,15 +41,15 @@ void ad_spi_send(unsigned char c)
10641 while(spi1_tx_fifo_is_full());
10742 spi1_putc(c);
10843 }
109-// polling rcv
110-unsigned char ad_spi_rcv(void)
44+// polling send/rcv
45+unsigned char ad_spi_rcv(unsigned char c)
11146 {
11247 spi1_rx_overrun_clear();
11348 while(spi1_tx_fifo_is_full());
11449 // 前に受信したデータをクリア
11550 spi1_getc();
11651 // 送信
117- spi1_putc(0);
52+ spi1_putc(c);
11853 // 受信待ち
11954 while(!spi1_rx_fifo_is_full());
12055 return spi1_getc();
@@ -124,89 +59,89 @@ void ad_init(void)
12459 {
12560 int cs;
12661 int i;
127-for(i = 0; i < AD_CHNUM; i++) {
128- cs = AD_CH1_CS + i;
129-//1. Send the SDATAC command <11h>. This command cancels the RDATAC mode. RDATAC mode must be
130-//cancelled before the register write commands.
131-
132- ad_cs(cs);
133- ad_spi_send(ADCMD_SDATAC);
134- ad_cs_dis();
135-//2. Send the register write command. The following example shows the register write as a block of nine bytes,
136-//starting at register 0 (CONFIG0).
137- ad_cs(cs);
138- ad_spi_send(ADCMD_WREG | 0); // Register write command
139- ad_spi_send(9 - 1); // 9byte write
140- // CONFIG0: RFBIAS OFF, SPI timeout enable
141- // Bit 2 RBIAS: Internal reference bias
142- // 0 = Internal reference bias disabled
143- // 1 = Internal reference bias enabled (default)
144- // Bit 0 SPI: SCLK timeout of SPI interface
145- // 0 = SPI timeout disabled
146- // 1 = SPI timeout enabled (default), when SCLK is held low for 216 clock cycles
147- // bit76543210
148- ad_spi_send(0b00000101);
149- // CONFIG1: sinc1 filter, EXTREF ON, START delay = 0
150- // Bit 6 CHKSUM: Checksum
151- // 0 = Disabled (default)
152- // 1 = Conversion data checksum byte included in readback
153- // Bit 4 SINC2: Digital filter mode
154- // 0 = sinc1 filter (default)
155- // 1 = sinc2 filter
156- // Bit 3 EXTREF: Reference select
157- // 0 = Internal
158- // 1 = External (default)
159- // Bits 2-0 DELAY[2:0]: START conversion delay
160- // 000 = No delay (default)
161- // bit76543210
162- ad_spi_send(0b00001000);
163-
164-
165- // CONFIG2: SYNCOUT ON, Gate control, DataRate=10Hz
166- // Bit 5 SYNCOUT: SYNCOUT clock enable
167- // 0 = SYNCOUT disabled (default)
168- // 1 = SYNCOUT enabled
169- // Bit 4 PULSE: Conversion Control mode select
170- // 0 = Gate Control mode (default)
171- // 1 = Pulse Control mode
172- // Bits 2-0 DR[2:0] Data rate setting
173- // 000 = 10SPS (default)
174- // 001 = 16.6SPS
175- // 010 = 50SPS
176- // 011 = 60SPS
177- // 100 = 400SPS
178- // 101 = 1200SPS
179- // 110 = 3600SPS
180- // 111 = 14400SPS
181- // NOTE: fCLK = 7.3728MHz
182- unsigned char rate_bit;
183- switch(AD_SAMPLE) {
184- case 50:
185- rate_bit = 0b00000010;
186- break;
187- case 400:
188- rate_bit = 0b00000100;
189- break;
190- default:
191- case 10:
192- rate_bit = 0b00000000;
193- break;
194- }
195- // bit76543210
196- ad_spi_send(0b00100000 | rate_bit);
197-
198- // OFC0,1,2: no offset correction
199- ad_spi_send(0);
200- ad_spi_send(0);
201- ad_spi_send(0);
62+ for(i = 0; i < AD_CHNUM; i++) {
63+ cs = AD_CH1_CS + i;
64+ //1. Send the SDATAC command <11h>. This command cancels the RDATAC mode. RDATAC mode must be
65+ //cancelled before the register write commands.
20266
203- // FSC0,1,2: no full scale correction
204- ad_spi_send(0);
205- ad_spi_send(0);
206- ad_spi_send(0b01000000);
207- ad_cs_dis();
67+ ad_cs(cs);
68+ ad_spi_send(ADCMD_SDATAC);
69+ ad_cs_dis();
70+ //2. Send the register write command. The following example shows the register write as a block of nine bytes,
71+ //starting at register 0 (CONFIG0).
72+ ad_cs(cs);
73+ ad_spi_send(ADCMD_WREG | 0); // Register write command
74+ ad_spi_send(9 - 1); // 9byte write
75+ // CONFIG0: RFBIAS OFF, SPI timeout enable
76+ // Bit 2 RBIAS: Internal reference bias
77+ // 0 = Internal reference bias disabled
78+ // 1 = Internal reference bias enabled (default)
79+ // Bit 0 SPI: SCLK timeout of SPI interface
80+ // 0 = SPI timeout disabled
81+ // 1 = SPI timeout enabled (default), when SCLK is held low for 216 clock cycles
82+ // bit76543210
83+ ad_spi_send(0b00000101);
84+ // CONFIG1: sinc1 filter, EXTREF ON, START delay = 0
85+ // Bit 6 CHKSUM: Checksum
86+ // 0 = Disabled (default)
87+ // 1 = Conversion data checksum byte included in readback
88+ // Bit 4 SINC2: Digital filter mode
89+ // 0 = sinc1 filter (default)
90+ // 1 = sinc2 filter
91+ // Bit 3 EXTREF: Reference select
92+ // 0 = Internal
93+ // 1 = External (default)
94+ // Bits 2-0 DELAY[2:0]: START conversion delay
95+ // 000 = No delay (default)
96+ // bit76543210
97+ ad_spi_send(0b00001000);
98+
99+
100+ // CONFIG2: SYNCOUT ON, Gate control, DataRate=10Hz
101+ // Bit 5 SYNCOUT: SYNCOUT clock enable
102+ // 0 = SYNCOUT disabled (default)
103+ // 1 = SYNCOUT enabled
104+ // Bit 4 PULSE: Conversion Control mode select
105+ // 0 = Gate Control mode (default)
106+ // 1 = Pulse Control mode
107+ // Bits 2-0 DR[2:0] Data rate setting
108+ // 000 = 10SPS (default)
109+ // 001 = 16.6SPS
110+ // 010 = 50SPS
111+ // 011 = 60SPS
112+ // 100 = 400SPS
113+ // 101 = 1200SPS
114+ // 110 = 3600SPS
115+ // 111 = 14400SPS
116+ // NOTE: fCLK = 7.3728MHz
117+ unsigned char rate_bit;
118+ switch(AD_SAMPLE) {
119+ case 50:
120+ rate_bit = 0b00000010;
121+ break;
122+ case 400:
123+ rate_bit = 0b00000100;
124+ break;
125+ default:
126+ case 10:
127+ rate_bit = 0b00000000;
128+ break;
129+ }
130+ // bit76543210
131+ ad_spi_send(0b00100000 | rate_bit);
132+
133+ // OFC0,1,2: no offset correction
134+ ad_spi_send(0);
135+ ad_spi_send(0);
136+ ad_spi_send(0);
137+
138+ // FSC0,1,2: no full scale correction
139+ ad_spi_send(0);
140+ ad_spi_send(0);
141+ ad_spi_send(0b01000000);
142+ ad_cs_dis();
208143
209-}
144+ }
210145 // 4. Take the START pin high or send the START command to start conversions.
211146 ad_start_ena(); // +AD START
212147
@@ -221,45 +156,46 @@ for(i = 0; i < AD_CHNUM; i++) {
221156
222157 }
223158 /*
224- PGA280 init
225- BUF OFF
159+ * PGA280 init
160+ * BUF OFF
161+ * SYNCin enable
226162 */
227163 void pga_init(void)
228164 {
229165 int cs;
230166 int i;
231-for(i = 0; i < AD_CHNUM; i++) {
232- cs = PGA_CH1_CS + i;
233- //Register 1
234- //Soft Reset
235- ad_cs(cs);
236- ad_spi_send(0x41);
237- ad_spi_send(0x01);
238- ad_cs_dis();
239- //waitいる?
240- delay_ms(1);
167+ for(i = 0; i < AD_CHNUM; i++) {
168+ cs = PGA_CH1_CS + i;
169+ //Register 1
170+ //Soft Reset
171+ ad_cs(cs);
172+ ad_spi_send(0x41);
173+ ad_spi_send(0x01);
174+ ad_cs_dis();
175+ //waitいる?
176+ delay_ms(1);
241177
242- //Register 0
243- //Gain=1/4
244- ad_cs(cs);
245- ad_spi_send(0x40); //(BUF OFF)
246- ad_spi_send(0x08);
247- ad_cs_dis();
178+ //Register 0
179+ //Gain=1/4
180+ ad_cs(cs);
181+ ad_spi_send(0x40); //(BUF OFF)
182+ ad_spi_send(0x08);
183+ ad_cs_dis();
248184
249- //Register 8: GPIO Configuration Register
250- //使わないpinはoutput(=1)にする
251- //bit6 GPIO6(SYNCIN) input(=0)
252- ad_cs(cs);
253- ad_spi_send(0x48);
254- ad_spi_send(0b00111111);
255- ad_cs_dis();
185+ //Register 8: GPIO Configuration Register
186+ //使わないpinはoutput(=1)にする
187+ //bit6 GPIO6(SYNCIN) input(=0)
188+ ad_cs(cs);
189+ ad_spi_send(0x48);
190+ ad_spi_send(0b00111111);
191+ ad_cs_dis();
256192
257- //Register 12: Special Functions Register
258- //bit6 SYNCin=1 SYNCIN(GPIO6) Enable
259- ad_cs(cs);
260- ad_spi_send(0x4C);
261- ad_spi_send(0b01000000);
262- ad_cs_dis();
263-}
193+ //Register 12: Special Functions Register
194+ //bit6 SYNCin=1 SYNCIN(GPIO6) Enable
195+ ad_cs(cs);
196+ ad_spi_send(0x4C);
197+ ad_spi_send(0b01000000);
198+ ad_cs_dis();
199+ }
264200 }
265201
--- a/myad.h
+++ b/myad.h
@@ -19,8 +19,10 @@
1919
2020 // SPI CMD
2121 #define ADCMD_SDATAC 0x11
22+#define ADCMD_RREG 0x20
2223 #define ADCMD_WREG 0x40
2324 #define ADCMD_RDATAC 0x10
25+#define ADCMD_SDATAC 0x11
2426
2527 // AD DRDY0 INTフラグ
2628 //void ad_drdy0_intf_set(void);
@@ -81,7 +83,7 @@ void ad_start(void);
8183 void ad_init(void);
8284
8385 void ad_spi_send(unsigned char c);
84-unsigned char ad_spi_rcv(void);
86+unsigned char ad_spi_rcv(unsigned char c);
8587
8688 void pga_init(void);
8789
--- a/myspi.c
+++ b/myspi.c
@@ -2,6 +2,19 @@
22
33 #include "myspi.h"
44
5+
6+void spi1_rx_fifo_clear(void)
7+{
8+ int i;
9+ unsigned char c;
10+ for(i = 0; i < 16; i++) c = SPI1BUF;
11+}
12+void spi2_rx_fifo_clear(void)
13+{
14+ int i;
15+ unsigned char c;
16+ for(i = 0; i < 16; i++) c = SPI2BUF;
17+}
518 /*
619 AD SPI1 Init
720 Enhanced Buffer OFF
@@ -21,8 +34,11 @@ int spi1_init(void)
2134 // bit12 DISSCK=0 0=Internal SPI clock is enabled
2235 // bit11 DISSDO=0 0 = SDOx pin is controlled by the module
2336 // bit10 MODE16=0 8bit
24- // bit9 SMP=1 1=Input data sampled at end of data output time @MasterMode
25- // bit8 CKE=0 DATA CHANGE=CLK LtoH
37+ // bit9 SMP=0
38+ // @MasterMode
39+ // 1 = Input data sampled at end of data output time
40+ // 0 = Input data sampled at middle of data output time
41+ // bit8 CKE=0 DATA CHANGE=CLK Idle to Active =LtoH
2642 // bit7 SSEN=0 SS pin disable
2743 // bit6 CKP=0 CLK IDLE=LOW
2844 // bit5 MSTEN=1 Master
@@ -37,7 +53,7 @@ int spi1_init(void)
3753 // 01 = Primary prescale 16:1
3854 // 00 = Primary prescale 64:1
3955 // 5432109876543210
40- SPI1CON1 = 0b0000001000111110;
56+ SPI1CON1 = 0b0000000000111110;
4157
4258 // Enahanced Buffer(FIFO) Disable
4359 // bit0 SPIBEN: Enhanced Buffer Enable bit
--- a/myspi.h
+++ b/myspi.h
@@ -2,6 +2,8 @@
22 #include <p24FJ64GA004.h>
33
44 #define __MYSPI_H__
5+void spi1_rx_fifo_clear(void);
6+void spi2_rx_fifo_clear(void);
57 int spi1_init(void);
68 int spi2_init(void);
79
--- a/nbproject/Makefile-default.mk
+++ b/nbproject/Makefile-default.mk
@@ -93,110 +93,110 @@ ${OBJECTDIR}/byte2var.o: byte2var.c nbproject/Makefile-${CND_CONF}.mk
9393 @${MKDIR} ${OBJECTDIR}
9494 @${RM} ${OBJECTDIR}/byte2var.o.d
9595 @${RM} ${OBJECTDIR}/byte2var.o.ok ${OBJECTDIR}/byte2var.o.err
96- @${FIXDEPS} "${OBJECTDIR}/byte2var.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/byte2var.o.d" -o ${OBJECTDIR}/byte2var.o byte2var.c -Winline
96+ @${FIXDEPS} "${OBJECTDIR}/byte2var.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/byte2var.o.d" -o ${OBJECTDIR}/byte2var.o byte2var.c -Winline
9797
9898 ${OBJECTDIR}/myuart.o: myuart.c nbproject/Makefile-${CND_CONF}.mk
9999 @${MKDIR} ${OBJECTDIR}
100100 @${RM} ${OBJECTDIR}/myuart.o.d
101101 @${RM} ${OBJECTDIR}/myuart.o.ok ${OBJECTDIR}/myuart.o.err
102- @${FIXDEPS} "${OBJECTDIR}/myuart.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/myuart.o.d" -o ${OBJECTDIR}/myuart.o myuart.c -Winline
102+ @${FIXDEPS} "${OBJECTDIR}/myuart.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/myuart.o.d" -o ${OBJECTDIR}/myuart.o myuart.c -Winline
103103
104104 ${OBJECTDIR}/debug_print.o: debug_print.c nbproject/Makefile-${CND_CONF}.mk
105105 @${MKDIR} ${OBJECTDIR}
106106 @${RM} ${OBJECTDIR}/debug_print.o.d
107107 @${RM} ${OBJECTDIR}/debug_print.o.ok ${OBJECTDIR}/debug_print.o.err
108- @${FIXDEPS} "${OBJECTDIR}/debug_print.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/debug_print.o.d" -o ${OBJECTDIR}/debug_print.o debug_print.c -Winline
108+ @${FIXDEPS} "${OBJECTDIR}/debug_print.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/debug_print.o.d" -o ${OBJECTDIR}/debug_print.o debug_print.c -Winline
109109
110110 ${OBJECTDIR}/mysts.o: mysts.c nbproject/Makefile-${CND_CONF}.mk
111111 @${MKDIR} ${OBJECTDIR}
112112 @${RM} ${OBJECTDIR}/mysts.o.d
113113 @${RM} ${OBJECTDIR}/mysts.o.ok ${OBJECTDIR}/mysts.o.err
114- @${FIXDEPS} "${OBJECTDIR}/mysts.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/mysts.o.d" -o ${OBJECTDIR}/mysts.o mysts.c -Winline
114+ @${FIXDEPS} "${OBJECTDIR}/mysts.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/mysts.o.d" -o ${OBJECTDIR}/mysts.o mysts.c -Winline
115115
116116 ${OBJECTDIR}/ublox.o: ublox.c nbproject/Makefile-${CND_CONF}.mk
117117 @${MKDIR} ${OBJECTDIR}
118118 @${RM} ${OBJECTDIR}/ublox.o.d
119119 @${RM} ${OBJECTDIR}/ublox.o.ok ${OBJECTDIR}/ublox.o.err
120- @${FIXDEPS} "${OBJECTDIR}/ublox.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/ublox.o.d" -o ${OBJECTDIR}/ublox.o ublox.c -Winline
120+ @${FIXDEPS} "${OBJECTDIR}/ublox.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/ublox.o.d" -o ${OBJECTDIR}/ublox.o ublox.c -Winline
121121
122122 ${OBJECTDIR}/myad.o: myad.c nbproject/Makefile-${CND_CONF}.mk
123123 @${MKDIR} ${OBJECTDIR}
124124 @${RM} ${OBJECTDIR}/myad.o.d
125125 @${RM} ${OBJECTDIR}/myad.o.ok ${OBJECTDIR}/myad.o.err
126- @${FIXDEPS} "${OBJECTDIR}/myad.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/myad.o.d" -o ${OBJECTDIR}/myad.o myad.c -Winline
126+ @${FIXDEPS} "${OBJECTDIR}/myad.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/myad.o.d" -o ${OBJECTDIR}/myad.o myad.c -Winline
127127
128128 ${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
129129 @${MKDIR} ${OBJECTDIR}
130130 @${RM} ${OBJECTDIR}/main.o.d
131131 @${RM} ${OBJECTDIR}/main.o.ok ${OBJECTDIR}/main.o.err
132- @${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c -Winline
132+ @${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c -Winline
133133
134134 ${OBJECTDIR}/ring.o: ring.c nbproject/Makefile-${CND_CONF}.mk
135135 @${MKDIR} ${OBJECTDIR}
136136 @${RM} ${OBJECTDIR}/ring.o.d
137137 @${RM} ${OBJECTDIR}/ring.o.ok ${OBJECTDIR}/ring.o.err
138- @${FIXDEPS} "${OBJECTDIR}/ring.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/ring.o.d" -o ${OBJECTDIR}/ring.o ring.c -Winline
138+ @${FIXDEPS} "${OBJECTDIR}/ring.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/ring.o.d" -o ${OBJECTDIR}/ring.o ring.c -Winline
139139
140140 ${OBJECTDIR}/myspi.o: myspi.c nbproject/Makefile-${CND_CONF}.mk
141141 @${MKDIR} ${OBJECTDIR}
142142 @${RM} ${OBJECTDIR}/myspi.o.d
143143 @${RM} ${OBJECTDIR}/myspi.o.ok ${OBJECTDIR}/myspi.o.err
144- @${FIXDEPS} "${OBJECTDIR}/myspi.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/myspi.o.d" -o ${OBJECTDIR}/myspi.o myspi.c -Winline
144+ @${FIXDEPS} "${OBJECTDIR}/myspi.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_ICD3=1 -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/myspi.o.d" -o ${OBJECTDIR}/myspi.o myspi.c -Winline
145145
146146 else
147147 ${OBJECTDIR}/byte2var.o: byte2var.c nbproject/Makefile-${CND_CONF}.mk
148148 @${MKDIR} ${OBJECTDIR}
149149 @${RM} ${OBJECTDIR}/byte2var.o.d
150150 @${RM} ${OBJECTDIR}/byte2var.o.ok ${OBJECTDIR}/byte2var.o.err
151- @${FIXDEPS} "${OBJECTDIR}/byte2var.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/byte2var.o.d" -o ${OBJECTDIR}/byte2var.o byte2var.c -Winline
151+ @${FIXDEPS} "${OBJECTDIR}/byte2var.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/byte2var.o.d" -o ${OBJECTDIR}/byte2var.o byte2var.c -Winline
152152
153153 ${OBJECTDIR}/myuart.o: myuart.c nbproject/Makefile-${CND_CONF}.mk
154154 @${MKDIR} ${OBJECTDIR}
155155 @${RM} ${OBJECTDIR}/myuart.o.d
156156 @${RM} ${OBJECTDIR}/myuart.o.ok ${OBJECTDIR}/myuart.o.err
157- @${FIXDEPS} "${OBJECTDIR}/myuart.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/myuart.o.d" -o ${OBJECTDIR}/myuart.o myuart.c -Winline
157+ @${FIXDEPS} "${OBJECTDIR}/myuart.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/myuart.o.d" -o ${OBJECTDIR}/myuart.o myuart.c -Winline
158158
159159 ${OBJECTDIR}/debug_print.o: debug_print.c nbproject/Makefile-${CND_CONF}.mk
160160 @${MKDIR} ${OBJECTDIR}
161161 @${RM} ${OBJECTDIR}/debug_print.o.d
162162 @${RM} ${OBJECTDIR}/debug_print.o.ok ${OBJECTDIR}/debug_print.o.err
163- @${FIXDEPS} "${OBJECTDIR}/debug_print.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/debug_print.o.d" -o ${OBJECTDIR}/debug_print.o debug_print.c -Winline
163+ @${FIXDEPS} "${OBJECTDIR}/debug_print.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/debug_print.o.d" -o ${OBJECTDIR}/debug_print.o debug_print.c -Winline
164164
165165 ${OBJECTDIR}/mysts.o: mysts.c nbproject/Makefile-${CND_CONF}.mk
166166 @${MKDIR} ${OBJECTDIR}
167167 @${RM} ${OBJECTDIR}/mysts.o.d
168168 @${RM} ${OBJECTDIR}/mysts.o.ok ${OBJECTDIR}/mysts.o.err
169- @${FIXDEPS} "${OBJECTDIR}/mysts.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/mysts.o.d" -o ${OBJECTDIR}/mysts.o mysts.c -Winline
169+ @${FIXDEPS} "${OBJECTDIR}/mysts.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/mysts.o.d" -o ${OBJECTDIR}/mysts.o mysts.c -Winline
170170
171171 ${OBJECTDIR}/ublox.o: ublox.c nbproject/Makefile-${CND_CONF}.mk
172172 @${MKDIR} ${OBJECTDIR}
173173 @${RM} ${OBJECTDIR}/ublox.o.d
174174 @${RM} ${OBJECTDIR}/ublox.o.ok ${OBJECTDIR}/ublox.o.err
175- @${FIXDEPS} "${OBJECTDIR}/ublox.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/ublox.o.d" -o ${OBJECTDIR}/ublox.o ublox.c -Winline
175+ @${FIXDEPS} "${OBJECTDIR}/ublox.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/ublox.o.d" -o ${OBJECTDIR}/ublox.o ublox.c -Winline
176176
177177 ${OBJECTDIR}/myad.o: myad.c nbproject/Makefile-${CND_CONF}.mk
178178 @${MKDIR} ${OBJECTDIR}
179179 @${RM} ${OBJECTDIR}/myad.o.d
180180 @${RM} ${OBJECTDIR}/myad.o.ok ${OBJECTDIR}/myad.o.err
181- @${FIXDEPS} "${OBJECTDIR}/myad.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/myad.o.d" -o ${OBJECTDIR}/myad.o myad.c -Winline
181+ @${FIXDEPS} "${OBJECTDIR}/myad.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/myad.o.d" -o ${OBJECTDIR}/myad.o myad.c -Winline
182182
183183 ${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
184184 @${MKDIR} ${OBJECTDIR}
185185 @${RM} ${OBJECTDIR}/main.o.d
186186 @${RM} ${OBJECTDIR}/main.o.ok ${OBJECTDIR}/main.o.err
187- @${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c -Winline
187+ @${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c -Winline
188188
189189 ${OBJECTDIR}/ring.o: ring.c nbproject/Makefile-${CND_CONF}.mk
190190 @${MKDIR} ${OBJECTDIR}
191191 @${RM} ${OBJECTDIR}/ring.o.d
192192 @${RM} ${OBJECTDIR}/ring.o.ok ${OBJECTDIR}/ring.o.err
193- @${FIXDEPS} "${OBJECTDIR}/ring.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/ring.o.d" -o ${OBJECTDIR}/ring.o ring.c -Winline
193+ @${FIXDEPS} "${OBJECTDIR}/ring.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/ring.o.d" -o ${OBJECTDIR}/ring.o ring.c -Winline
194194
195195 ${OBJECTDIR}/myspi.o: myspi.c nbproject/Makefile-${CND_CONF}.mk
196196 @${MKDIR} ${OBJECTDIR}
197197 @${RM} ${OBJECTDIR}/myspi.o.d
198198 @${RM} ${OBJECTDIR}/myspi.o.ok ${OBJECTDIR}/myspi.o.err
199- @${FIXDEPS} "${OBJECTDIR}/myspi.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -O1 -MMD -MF "${OBJECTDIR}/myspi.o.d" -o ${OBJECTDIR}/myspi.o myspi.c -Winline
199+ @${FIXDEPS} "${OBJECTDIR}/myspi.o.d" $(SILENT) -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -omf=elf -x c -c -mcpu=$(MP_PROCESSOR_OPTION) -mlarge-data -O1 -MMD -MF "${OBJECTDIR}/myspi.o.d" -o ${OBJECTDIR}/myspi.o myspi.c -Winline
200200
201201 endif
202202
--- a/nbproject/Makefile-genesis.properties
+++ b/nbproject/Makefile-genesis.properties
@@ -1,5 +1,5 @@
11 #
2-#Sat Dec 03 14:49:06 JST 2011
2+#Thu Dec 15 23:32:46 JST 2011
33 default.languagetoolchain.dir=/opt/microchip/mplabc30/v3.30c/bin
44 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=11bb82e71763925c87fa30f6c65473b1
55 default.languagetoolchain.version=3_30
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -86,7 +86,7 @@
8686 <property key="post-instruction-scheduling" value="default"/>
8787 <property key="enable-unroll-loops" value="false"/>
8888 <property key="enable-symbols" value="true"/>
89- <property key="data-model" value="default"/>
89+ <property key="data-model" value="large-data"/>
9090 <property key="isolate-each-function" value="false"/>
9191 <property key="enable-fatal-warnings" value="false"/>
9292 <property key="enable-omit-frame-pointer" value="false"/>
@@ -102,11 +102,11 @@
102102 <property key="extra-include-directories-for-assembler" value=""/>
103103 <property key="preprocessor-macros" value=""/>
104104 <property key="list-file" value=""/>
105- <property key="list-assembly" value="false"/>
106105 <property key="list-source" value="false"/>
106+ <property key="list-assembly" value="false"/>
107107 <property key="relax" value="false"/>
108- <property key="extra-include-directories-for-preprocessor" value=""/>
109108 <property key="warning-level" value="emit-warnings"/>
109+ <property key="extra-include-directories-for-preprocessor" value=""/>
110110 <property key="list-section-info" value="false"/>
111111 <property key="omit-forms" value="false"/>
112112 <property key="list-symbols" value="false"/>
@@ -132,23 +132,23 @@
132132 <property key="enable-handles" value="true"/>
133133 <property key="enable-data-init" value="true"/>
134134 <property key="secure-flash" value="no_flash"/>
135- <property key="boot-write-protect" value="no_write_protect"/>
136- <property key="boot-flash" value="no_flash"/>
137- <property key="report-memory-usage" value="false"/>
138135 <property key="generate-cross-reference-file" value="false"/>
136+ <property key="report-memory-usage" value="false"/>
137+ <property key="boot-flash" value="no_flash"/>
138+ <property key="boot-write-protect" value="no_write_protect"/>
139139 <property key="input-libraries" value=""/>
140140 <property key="secure-ram" value="no_ram"/>
141141 <property key="enable-check-sections" value="true"/>
142142 <property key="enable-default-isr" value="true"/>
143143 <property key="symbol-stripping" value="keep-all"/>
144144 <property key="boot-ram" value="no_ram"/>
145- <property key="secure-eeprom" value="no_eeprom"/>
146145 <property key="extra-lib-directories" value=""/>
146+ <property key="secure-eeprom" value="no_eeprom"/>
147147 </C30-LD>
148148 <C30Global>
149149 <property key="fast-math" value="false"/>
150- <property key="output-file-format" value="elf"/>
151150 <property key="legacy-libc" value="false"/>
151+ <property key="output-file-format" value="elf"/>
152152 </C30Global>
153153 <ICD3PlatformTool>
154154 <property key="UART 2" value="true"/>
@@ -186,14 +186,14 @@
186186 <property key="TIMER4" value="true"/>
187187 <property key="TIMER3" value="true"/>
188188 <property key="SPI 2" value="true"/>
189- <property key="TIMER2" value="true"/>
190189 <property key="SPI 1" value="true"/>
190+ <property key="TIMER2" value="true"/>
191191 <property key="TIMER1" value="true"/>
192192 <property key="CRC" value="true"/>
193193 <property key="I2C2" value="true"/>
194194 <property key="I2C1" value="true"/>
195- <property key="Freeze All Other Peripherals" value="true"/>
196195 <property key="programoptions.preserveprogramrange.end" value="0xff"/>
196+ <property key="Freeze All Other Peripherals" value="true"/>
197197 </ICD3PlatformTool>
198198 </conf>
199199 </confs>
--- a/ublox.c
+++ b/ublox.c
@@ -238,7 +238,7 @@ void ublox_send_cfg_tp5_timepulse1(void)
238238
239239 payload[4] = 50; // cable delay ns
240240
241- payload[8] = 0x40; // Period us
241+ payload[8] = 0x40; // Period 1,000,000us
242242 payload[9] = 0x42;
243243 payload[10] = 0x0F;
244244 payload[11] = 0x00;
@@ -248,16 +248,16 @@ void ublox_send_cfg_tp5_timepulse1(void)
248248 payload[14] = 0x0F;
249249 payload[15] = 0x00;
250250
251- payload[16] = 0x00; // Pulse width us
252- payload[17] = 0x00;
253- payload[18] = 0x00;
251+ payload[16] = 0x20; // Pulse width 500,000us
252+ payload[17] = 0xA1;
253+ payload[18] = 0x07;
254254 payload[19] = 0x00;
255255
256-// payload[20] = 0xA0; // Pulse width locked 100,000us
257-// payload[21] = 0x86;
258-// payload[22] = 0x01;
259-// payload[23] = 0x00;
260-
256+ payload[20] = 0xA0; // Pulse width locked 100,000us
257+ payload[21] = 0x86;
258+ payload[22] = 0x01;
259+ payload[23] = 0x00;
260+#if 0
261261 payload[20] = 0x20; // Pulse width locked 500,000us
262262 payload[21] = 0xA1;
263263 payload[22] = 0x07;
@@ -267,7 +267,7 @@ void ublox_send_cfg_tp5_timepulse1(void)
267267 payload[21] = 0x35;
268268 payload[22] = 0x0C;
269269 payload[23] = 0x00;
270-
270+#endif
271271
272272 payload[28] = 0b11110111; // Grid=GPS,Pol=Rise
273273
@@ -424,11 +424,11 @@ int ublox_rcv_ack(void)
424424 ublox_rcv_pkt(&class, &id, &len, payload);
425425 if (class == 0x05 && id == 0x01) {
426426 // ACK
427- PDEBUG("ACK\r\n");
427+// PDEBUG("ACK\r\n");
428428 return 1;
429429 } else if (class == 0x05 && id == 0x00) {
430430 // NACK
431- PDEBUG("NACK\r\n");
431+// PDEBUG("NACK\r\n");
432432 return 0;
433433 }
434434 }
--- a/ublox.h
+++ b/ublox.h
@@ -18,6 +18,7 @@
1818 #define UBX_LEN_NAV_TIMEUTC 20
1919
2020 // NAV-TIMEUTCパケットのデータ格納
21+// SPI送信にそのまま使われるので注意!
2122 typedef struct {
2223 unsigned long tow; // ms GPS Millisecond Time of Week
2324 unsigned long tacc; // ns Time Accuracy Estimate
Show on old repository browser