Nee, wird nirgends aufgelöst. Mach ich morgen mit weiter.
Aber im Moment hab ichn schlimmeres Problem: scanf verursacht böse
Speicherfehler.
1 | #include <string.h>
|
2 | #include "asf.h"
|
3 | #include "conf_board.h"
|
4 |
|
5 | #define NUM_CHANNELS (4)
|
6 |
|
7 | /** ADC convention done mask. */
|
8 | #define ADC_DONE_MASK ( (1<<NUM_CHANNELS) - 1 )
|
9 |
|
10 | /** Size of the receive buffer and transmit buffer. */
|
11 | #define BUFFER_SIZE NUM_CHANNELS
|
12 |
|
13 | /** Reference voltage for ADC, in mv. */
|
14 | #define VOLT_REF (3300)
|
15 |
|
16 |
|
17 | /** The maximal digital value */
|
18 | #define MAX_DIGITAL (4095)
|
19 |
|
20 | #define STRING_EOL "\r"
|
21 | #define STRING_HEADER "\r\n\r\n-- ADC Example --\r\n" \
|
22 | "-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
|
23 |
|
24 | #define MENU_HEADER "\n\r" \
|
25 | "===================================================\n\r" \
|
26 | "Menu: press a key to change the configuration.\n\r" \
|
27 | "---------------------------------------------------------\n\r"
|
28 |
|
29 | /** ADC channel for potentiometer */
|
30 | int g_i_selected_channel;
|
31 |
|
32 |
|
33 |
|
34 | /** Global timestamp in milliseconds since start of application */
|
35 | static volatile uint32_t gs_ul_ms_ticks = 0;
|
36 |
|
37 |
|
38 |
|
39 | static void display_menu2(void)
|
40 | {
|
41 | puts(MENU_HEADER);
|
42 | printf ("Select channel: ");
|
43 | scanf("%d", &g_i_selected_channel); // <-PROBLEM
|
44 | printf ("\rg_i_selected_channel = %d\r", g_i_selected_channel);
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | /**
|
51 | * \brief Display ADC configuration menu.
|
52 | */
|
53 | static void display_menu(void)
|
54 | {
|
55 | uint8_t uc_char;
|
56 |
|
57 | puts(MENU_HEADER);
|
58 | uc_char = (g_adc_test_mode.uc_trigger_mode == TRIGGER_MODE_SOFTWARE) ? 'X' : ' ';
|
59 | printf("[%c] 0: Set ADC trigger mode: Software.\r", uc_char);
|
60 | ...
|
61 | ...
|
62 | ...
|
63 | uc_char = (g_adc_test_mode.uc_offset_en) ? 'E' : 'D';
|
64 | printf("[%c] O: Enable/Disable offset for potentiometer channel.\r",
|
65 | uc_char);
|
66 |
|
67 | puts(" Q: Quit configuration and start ADC.\r");
|
68 | puts("=========================================================\r");
|
69 | }
|
mit Aufruf in main:
...
...
display_menu2();
display_menu(); //show only
start_adc();
...
...
vrursacht willkürlichen Speichermüll in der Ausgabe:
g_i_selected_channel = 0
===================================================
Menu: press a key to change the configuration.
---------------------------------------------------------
[X] 0: Set ADC trigger mode: Software.
[ ] 1: Set ADC trigger mode: ADTRG.
[ ] 2: Set ADC trigger mode: Timer TIOA.
[ ] 3: Set ADC trigger mode: PWMEvent Line.
[ ] 4: Set ADC trigger mode: Free run mode.
[E] T: Enable/Disable to transfer with PDC.
[D] S: Enable/D…‰±•to use user sequence mode.
[D] P: Enable/Disable ADC power save mode.
[D] G: Enable/Disable to set gain = 2x for potentiometer channel.
[D] O: Enable/Disable offset for potentiometer channel.
Q: Quit configuration and start ADC.
================êêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêêj
Press any key to display configuration menu.
-- ADC Example --
-- Compiled: Jun 27 2013 21:36:39 --
Configure system tick to get 1ms tick period.
===================================================
Menu: press a key to change the configuration.
---------------------------------------------------------
Select channel:
uC istn SAM3X8E. Ich hab jetzt mehrere Datentypen für
g_i_selected_channel und für den Spezifizierer für scanf ausprobiert
weil ich eigentlich dachte der Speicher reicht nicht... hilft aber nicht
weiter.