simple tests for STM32F100R6 microcontroller with dedicated library
Dependencies: mbed-STM32F100R6
To compile a program with this library, use NUCLEO-F103RB as the target name. !
Change only one "#if" to "#if 1" to select the desired test. Others "#if" must be "#if 0".
Diff: main.cpp
- Revision:
- 3:2ca9ec946232
- Parent:
- 2:7cc544472c34
--- a/main.cpp Mon May 09 03:20:26 2016 +0000 +++ b/main.cpp Sat May 14 00:49:19 2016 +0000 @@ -32,11 +32,14 @@ } #endif + + + #if 0 //******stdio UART test****** +// PA_2-TX; PA_3-RX -//Serial pc(PA_9, PA_10); // tx, rx DigitalOut myled(PB_0); int main() @@ -53,7 +56,7 @@ -#if 1 +#if 0 //******DAC test****** @@ -68,7 +71,7 @@ int main() { - for (k=0;k<SIN1_ARRAY_SIZE;k++) { + for (k=0; k<SIN1_ARRAY_SIZE; k++) { sin_data[k]= (1.0+sin(1.0*k/SIN1_ARRAY_SIZE*2.0*PI))/2*0xFFFF; }; @@ -85,4 +88,100 @@ } -#endif \ No newline at end of file +#endif + +#if 1 + +//******ADC test****** +// adapted from https://developer.mbed.org/teams/ST/code/Nucleo_analog_loop/ +// connect tested ADC input to PA_4 + +// serial output on pins where not adc option +Serial pc(PA_9, PA_10); // tx, rx + +// test signal source +AnalogOut out(PA_4); + + +// select tested ADC input +#define ADC_IN 0 + + +#if ADC_IN==0 +AnalogIn in(PA_0); +const char pin_name[]="PA_0"; +#elif ADC_IN==1 +AnalogIn in(PA_1); +const char pin_name[]="PA_1"; +#elif ADC_IN==2 +AnalogIn in(PA_2); +const char pin_name[]="PA_2"; +#elif ADC_IN==3 +AnalogIn in(PA_3); +const char pin_name[]="PA_3"; +#elif ADC_IN==4 +AnalogIn in(PA_4); +const char pin_name[]="PA_4"; +#elif ADC_IN==5 +AnalogIn in(PA_5); +const char pin_name[]="PA_5"; +#elif ADC_IN==6 +AnalogIn in(PA_6); +const char pin_name[]="PA_6"; +#elif ADC_IN==7 +AnalogIn in(PA_7); +const char pin_name[]="PA_7"; +#elif ADC_IN==8 +AnalogIn in(PB_0); +const char pin_name[]="PB_0"; +#elif ADC_IN==9 +AnalogIn in(PB_1); +const char pin_name[]="PB_1"; +#elif ADC_IN==10 +AnalogIn in(PC_0); +const char pin_name[]="PC_0"; +#elif ADC_IN==11 +AnalogIn in(PC_1); +const char pin_name[]="PC_1"; +#elif ADC_IN==12 +AnalogIn in(PC_2); +const char pin_name[]="PC_2"; +#elif ADC_IN==13 +AnalogIn in(PC_3); +const char pin_name[]="PC_3"; +#elif ADC_IN==14 +AnalogIn in(PC_4); +const char pin_name[]="PC_4"; +#elif ADC_IN==15 +AnalogIn in(PC_5); +const char pin_name[]="PC_5"; +#endif + + +int main() +{ + pc.printf("\nAnalog loop example\n"); + pc.printf("*** Connect %s and PA_4 pins together ***\n",pin_name); + while(1) { + for (float out_value = 0.0f; out_value <= 1.0f; out_value += 0.05f) { + // Output value using DAC + out.write(out_value); + wait(0.1); + // Read ADC input + float in_value = in.read(); + // Display difference between two values + float diff = out_value - in_value; + pc.printf("(out:%.4f) - (in:%.4f) = (% .4f) ", out_value, in_value, diff); + if (fabs(diff) > 0.03f) { + pc.printf("FAIL\n"); + } else { + pc.printf("OK\n"); + pc.printf("\033[1A"); // Moves cursor up of 1 line + } + } + } +} + + + +#endif