I'm seeing some issues I don't understand when using RTT. Here is a short fragment of code around the RTT_Write statement.
static float readADC() { int nmbBytes; char strBfr[32]; int8_t datBfr[4] = {0}; Ads1115Ptr = ADS1115_RGDATA; int16_t data = ADS1115_read_reg(Ads1115Ptr); // SEGGER_RTT_printf(0, "ADC Data: 0x%x\n", data); datBfr[0] = 0xFF&data; datBfr[1] = data>>8; uint32_t var3 = 0; var3 = *datBfr; nmbBytes = SEGGER_RTT_Write(0, datBfr, 4); // SEGGER_RTT_printf(0, "%d data bytes written\n", nmbBytes); // SEGGER_RTT_printf(0, "%x\n", data); float voltage = (float) data * ADCGain; // sprintf(strBfr, "Voltage (V): %12.5f\n", voltage); // SEGGER_RTT_WriteString(0, strBfr); return voltage; }
The commented out statements are included while I try alternatives but not currently relevant. The routine is called a bit less than every 7.812ms using a
while (true) { nrf_delay_us(7812);
(i.e. at a 128Hz rate) and the routine is called exactly 256 times. Except for the RTT issue, the code appears to be working correctly. I haven't timed anything yet.
Issue 1) I am storing the terminal window into a log file and using RTT logging to channel 0; they are giving different results
The intent is to store the ADC data quickly to the desktop using binary. The logging to the terminal window is outputting two of the four bytes with an unrelated third byte in between them, irrespective if I use a 2 or a 4 for the number of bytes to output in the write statement. There are about 169 of the 256 samples output to the SES terminal logging window.
Issue 2) The channel 0 logging window is outputting a lot of undesired text (I would like to not have in the file) and then outputs 2 of the 4 bytes only for about 65 of the 256 samples.
Here is the terminal window after the program ran, but before stopping logging:
> od -tx1z term.log 0000000 23 20 53 45 47 47 45 52 20 4a 2d 4c 69 6e 6b 20 ># SEGGER J-Link < 0000020 52 54 54 20 56 69 65 77 65 72 20 56 36 2e 37 33 >RTT Viewer V6.73< 0000040 62 20 28 62 65 74 61 29 20 54 65 72 6d 69 6e 61 >b (beta) Termina< 0000060 6c 20 4c 6f 67 20 46 69 6c 65 0d 0a 23 20 43 6f >l Log File..# Co< 0000100 6d 70 69 6c 65 64 3a 20 31 37 3a 32 35 3a 34 35 >mpiled: 17:25:45< 0000120 20 6f 6e 20 4d 61 79 20 31 35 20 32 30 32 30 0d > on May 15 2020.< 0000140 0a 23 20 4c 6f 67 67 69 6e 67 20 73 74 61 72 74 >.# Logging start< 0000160 65 64 20 40 20 30 37 20 4a 75 6c 20 32 30 32 30 >ed @ 07 Jul 2020< 0000200 20 31 35 3a 33 35 3a 32 39 0d 0a > 15:35:29..< 0000213 >
and here is the same after stopping logging where I assume the flushing has occurred (I have not used insert code here to make it easier to read):
> od -tx1z term.log
0000000 23 20 53 45 47 47 45 52 20 4a 2d 4c 69 6e 6b 20 ># SEGGER J-Link <
0000020 52 54 54 20 56 69 65 77 65 72 20 56 36 2e 37 33 >RTT Viewer V6.73<
0000040 62 20 28 62 65 74 61 29 20 54 65 72 6d 69 6e 61 >b (beta) Termina<
0000060 6c 20 4c 6f 67 20 46 69 6c 65 0d 0a 23 20 43 6f >l Log File..# Co<
0000100 6d 70 69 6c 65 64 3a 20 31 37 3a 32 35 3a 34 35 >mpiled: 17:25:45<
0000120 20 6f 6e 20 4d 61 79 20 31 35 20 32 30 32 30 0d > on May 15 2020.<
0000140 0a 23 20 4c 6f 67 67 69 6e 67 20 73 74 61 72 74 >.# Logging start<
0000160 65 64 20 40 20 30 37 20 4a 75 6c 20 32 30 32 30 >ed @ 07 Jul 2020<
0000200 20 31 35 3a 33 35 3a 32 39 0d 0a 30 30 3e 20 ca > 15:35:29..00> .<
0000220 43 c8 43 c7 43 cc 43 c9 43 c9 43 ca 43 ca 43 c7 >C.C.C.C.C.C.C.C.<
0000240 43 c9 43 c7 43 c9 43 c2 43 c9 43 c8 43 c9 43 c9 >C.C.C.C.C.C.C.C.<
0000260 43 c6 43 c8 43 c9 43 c7 43 c7 43 c9 43 c8 43 c8 >C.C.C.C.C.C.C.C.<
0000300 43 c6 43 c8 43 c9 43 ca 43 c6 43 c9 43 c6 43 c5 >C.C.C.C.C.C.C.C.<
0000320 43 c6 43 cb 43 ca 43 c8 43 c7 43 c6 43 ca 43 cd >C.C.C.C.C.C.C.C.<
0000340 43 c9 43 c9 43 c9 43 c9 43 ca 43 c9 43 c8 43 ca >C.C.C.C.C.C.C.C.<
0000360 43 cb 43 ca 43 c6 43 c9 43 c9 43 c7 43 c8 43 c7 >C.C.C.C.C.C.C.C.<
0000400 43 ca 43 c8 43 c8 43 c6 43 c7 43 c6 43 0d 0a 23 >C.C.C.C.C.C.C..#<
0000420 20 4c 6f 67 67 69 6e 67 20 73 74 6f 70 70 65 64 > Logging stopped<
0000440 20 40 20 20 37 20 4a 75 6c 20 32 30 32 30 20 31 > @ 7 Jul 2020 1<
0000460 35 3a 33 39 3a 32 30 0d 0a >5:39:20..<
0000471
> The four bytes in order should be {0xca, 0x43, 0x00, 0x00} for example. There are too few samples, the outputted samples don't start with the first one (established using breakpoints), the 0x00 samples are missing.
Following is a dump from the file produced setting Project Options->Debugger->Debug Terminal Log Window: notice that again, the 0x00's are missing, and that additional bytes have been added (with values between 0x82 and 0x8A), and that not all the samples have been ouput but many more samples than were output using the RTT Viewer Terminal Logging. I have read Segger's J-Link manual more times than I know, and it's documentation is at best sketchy. I also can't find anything searching DevZone that seems to address this issue.
> od -tx1z DbgTerm.log
0000000 c3 82 43 c3 8a 43 c3 88 43 c3 89 43 c3 8a 43 c3 >..C..C..C..C..C.<
0000020 8a 43 c3 8a 43 c3 8a 43 c3 8b 43 c3 8a 43 c3 89 >.C..C..C..C..C..<
0000040 43 c3 8d 43 c3 8a 43 c3 89 43 c3 8b 43 c3 8a 43 >C..C..C..C..C..C<
0000060 c3 8a 43 c3 8b 43 c3 8d 43 c3 89 43 c3 8c 43 c3 >..C..C..C..C..C.<
0000100 8a 43 c3 8c 43 c3 8a 43 c3 88 43 c3 8b 43 c3 8c >.C..C..C..C..C..<
0000120 43 c3 89 43 c3 8a 43 c3 89 43 c3 8a 43 c3 8a 43 >C..C..C..C..C..C<
0000140 c3 87 43 c3 89 43 c3 8a 43 c3 8a 43 c3 8a 43 c3 >..C..C..C..C..C.<
0000160 87 43 c3 8c 43 c3 8a 43 c3 89 43 c3 89 43 c3 87 >.C..C..C..C..C..<
0000200 43 c3 89 43 c3 8a 43 c3 8a 43 c3 87 43 c3 86 43 >C..C..C..C..C..C<
0000220 c3 88 43 c3 88 43 c3 87 43 c3 88 43 c3 89 43 c3 >..C..C..C..C..C.<
0000240 87 43 c3 86 43 c3 8a 43 c3 88 43 c3 88 43 c3 84 >.C..C..C..C..C..<
0000260 43 c3 88 43 c3 87 43 c3 87 43 c3 87 43 c3 89 43 >C..C..C..C..C..C<
0000300 c3 8a 43 c3 87 43 c3 8b 43 c3 87 43 c3 88 43 c3 >..C..C..C..C..C.<
0000320 85 43 c3 89 43 c3 84 43 c3 89 43 c3 87 43 c3 8a >.C..C..C..C..C..<
0000340 43 c3 89 43 c3 89 43 c3 8b 43 c3 88 43 c3 86 43 >C..C..C..C..C..C<
0000360 c3 87 43 c3 86 43 c3 88 43 c3 89 43 c3 89 43 c3 >..C..C..C..C..C.<
0000400 86 43 c3 86 43 c3 85 43 c3 86 43 c3 88 43 c3 87 >.C..C..C..C..C..<
0000420 43 c3 86 43 c3 88 43 c3 87 43 c3 87 43 c3 88 43 >C..C..C..C..C..C<
0000440 c3 86 43 c3 85 43 c3 86 43 c3 87 43 c3 85 43 c3 >..C..C..C..C..C.<
0000460 88 43 c3 88 43 c3 89 43 c3 87 43 c3 88 43 c3 8a >.C..C..C..C..C..<
0000500 43 c3 88 43 c3 86 43 c3 88 43 c3 87 43 c3 86 43 >C..C..C..C..C..C<
0000520 c3 88 43 c3 89 43 c3 87 43 c3 8a 43 c3 87 43 c3 >..C..C..C..C..C.<
0000540 89 43 c3 87 43 c3 89 43 c3 89 43 c3 88 43 c3 89 >.C..C..C..C..C..<
0000560 43 c3 88 43 c3 88 43 c3 8a 43 c3 85 43 c3 88 43 >C..C..C..C..C..C<
0000600 c3 88 43 c3 89 43 c3 87 43 c3 89 43 c3 89 43 c3 >..C..C..C..C..C.<
0000620 87 43 c3 87 43 c3 87 43 c3 86 43 c3 89 43 c3 86 >.C..C..C..C..C..<
0000640 43 c3 86 43 c3 87 43 c3 88 43 c3 89 43 c3 86 43 >C..C..C..C..C..C<
0000660 c3 87 43 c3 87 43 c3 88 43 c3 87 43 c3 86 43 c3 >..C..C..C..C..C.<
0000700 88 43 c3 89 43 c3 85 43 c3 87 43 c3 88 43 c3 87 >.C..C..C..C..C..<
0000720 43 c3 87 43 c3 87 43 c3 87 43 c3 86 43 c3 87 43 >C..C..C..C..C..C<
0000740 c3 87 43 c3 86 43 c3 88 43 c3 89 43 c3 8a 43 c3 >..C..C..C..C..C.<
0000760 89 43 c3 86 43 c3 87 43 c3 86 43 c3 87 43 c3 85 >.C..C..C..C..C..<
0001000 43 >C<
0001001
>
Changing the number of specified bytes to dump from 4 to 2 (in SEGGER_RTT_Write(0, datBfr, 4)) seems to have no effect (that I have yet noticed).