3 #include <p24FJ64GA004.h>
8 #include "debug_print.h"
17 /**** TEST *******************************************/
21 void test_spi_flag(void)
25 unsigned char txc = 0;
28 // spi2_int_disable();
29 // cnint_int_disable();
32 sprintf(sz, "SPI2STAT=%04X "
33 "SPIBEC=%d SRMPT=%d SPIROV=%d SRXMPT=%d TBF=%d RBF=%d\r\n"
43 if ((in = uart2_rcvbuf_getc()) >= 0) {
50 sprintf(sz, "RX=%02X\r\n", rxc);
55 sprintf(sz, "TX=%02X\r\n", txc);
59 spi2_rx_overrun_clear();
62 SPI2STATbits.SPIEN = 0;
64 SPI2STATbits.SPIEN = 1;
68 SPI2STATbits.SRXMPT = 1;
77 void test_spi_send(void)
79 unsigned char txc = 1;
88 while(SPI2STATbits.SPITBF == 0) {
92 if (SPI2STATbits.SRXMPT == 0) {
93 while(SPI2STATbits.SRXMPT == 0) {
98 sprintf(sz, "SPI2STAT=%04X "
99 "SPIBEC=%d SRMPT=%d SPIROV=%d SRXMPT=%d TBF=%d RBF=%d\r\n"
101 , SPI2STATbits.SPIBEC
103 , SPI2STATbits.SPIROV
104 , SPI2STATbits.SRXMPT
105 , SPI2STATbits.SPITBF
106 , SPI2STATbits.SPIRBF
115 void test_ad_get_config(void)
119 unsigned char reg[9];
123 ad_spi_send(ADCMD_SDATAC);
126 ad_spi_rcv(ADCMD_RREG | 0); // Register read command
127 ad_spi_rcv(9 - 1); // 9byte write
129 for(i = 0; i < 9; i++) {
130 reg[i] = ad_spi_rcv(0);
135 for(i = 0; i < 9; i++) {
136 sprintf(sz, "%d: %02X\r\n", i, reg[i]);
142 void test_ublox_rcv_mon(void)
144 unsigned char class, id;
146 unsigned char payload[128];
148 UbloxNavTimeUtc *gps, gps1;
153 ublox_rcv_pkt(&class, &id, &len, payload);
154 sprintf(sz, "CLASS=%02X ID=%02X LEN=%d\r\n", class, id, len);
156 ublox_debug_pkt_out(payload, len);
157 ublox_decode_nav_timeutc(payload, gps);
158 sprintf(sz, "%04u/%02d/%02d %02d:%02d:%02d.%09ld %6lums %6luns %02X\r\n",
159 gps->year, gps->month, gps->day, gps->hour, gps->min, gps->sec, gps->nano,
160 gps->tow, gps->tacc, gps->valid
189 unsigned int c = 0x12;
191 unsigned int sts = 0;
201 // while(spi2_tx_fifo_is_full());
203 // while(spi2_rx_fifo_is_empty());
206 while(spi2STATbits.SPIRBF == 0);
208 if (spi2STATbits.SPITBF == 0) {
211 // while(spi2STATbits.SPIRBF == 1) {
217 if (spi2STATbits.SPIROV == 1) spi2STATbits.SPIROV = 0;
218 sprintf(sz, "%d %04X\r\n", i, sts);
221 // while(spi2STATbits.SPITBF == 1);
222 // while(spi2STATbits.SPITBF);
224 while(!spi2_tx_fifo_is_full())
226 while(!spi2_rx_fifo_is_empty()) {
228 if (rx == '$') c = 0;
245 while(!ad_is_drdy0_enable());
247 for(cs=0; cs<6; cs++) {
249 in[2] = ad_spi_rcv();
250 in[1] = ad_spi_rcv();
251 in[0] = ad_spi_rcv();
253 l[cs] = byte3_to_long(in);
254 // sprintf(sz, "%02X %02X %02X", in[2], in[1], in[0]);
257 for(cs=0; cs<6; cs++) {
258 sprintf(sz, "%+7ld,", l[cs]);