Hi guys,
I have defined a global struct for my ADC values (ATMEGA328) like
struct ADCint { uint8_t ADC_No; uint16_t ADC_Value ; uint16_t ADC_VoltX100; }; extern struct ADCint ADC_1, ADC_2, ADC_3, ADC_4, ADC_5, ADC_6, ADC_7;
In the function I want to access on of the structure variables (ADC_1, ADC_2, ...) depending on the ADC_No passed to the function, like this:
void ADC_VrefInt(uint8_t ADC_No) // writes values to the desired ADCint structure { // struct ADCint *ADCvaluesPTR = &ADC_6; //-> this alone works fine struct ADCint ADCvaluesPTR; switch(ADC_No) { case 1: *ADCvaluesPTR = &ADC_1; break; //-> this doesn't work case 2: *ADCvaluesPTR = &ADC_2; break; case 3: *ADCvaluesPTR = &ADC_3; break; case 4: *ADCvaluesPTR = &ADC_4; break; case 5: *ADCvaluesPTR = &ADC_5; break; case 6: *ADCvaluesPTR = &ADC_6; break; case 7: *ADCvaluesPTR = &ADC_7; break; } // Read ADC // 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit // ADMUX REFS1 REFS0 ADLAR - MUX3 MUX2 MUX1 MUX0 ADMUX = ADCvaluesPTR->ADC_No; // reading the desired ADC channel //.... and so on
Using for example
struct ADCint *ADCvaluesPTR = &ADC_6;
works fine.
But the use with switch /case does always process errors.
Any help would appreciated, maybe how to solve this more elegant, selecting structur variables depending on numbers.
Many thanks!
BEXX