while i compling my program i am getting the follwing error on this line
value = ((*v1 + *v2 + *v3 + *v4 + *v)/5);
error:(expression must have arithmetic or pointer type)
can any one help for me???
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
while i compling my program i am getting the follwing error on this line
value = ((*v1 + *v2 + *v3 + *v4 + *v)/5);
error:(expression must have arithmetic or pointer type)
can any one help for me???
in my project am using 5 analog input and i have to take avg of that 5
input.. by means of adc i convert that 5 analog input into digital.. now
those digital value stored in following address..
0x200
0x202
0x204
0x206
0x208
in order to take the avg of this 5 input i have read that content of above memory addrees
by means of pointer.. while i compiling this program i am getting those error
#include <msp430g2231.h>
void *ptr = (void *)(0x200);
void *ptr1 = (void *)(0x202);
void *ptr2 = (void *)(0x204);
void *ptr3 = (void *)(0x206);
void *ptr4 = (void *)(0x208);
void *v,*v1,*v2,*v3,*v4;
unsigned int value;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
ADC10CTL1 = INCH_4 + CONSEQ_1; // P1.0 = 1.0259, P1.1 = 1.5379, P1.2 = 2.0494, P1.3 = 2.5788, P1.4 = 3.0768, P1.5 = 0.3134, P1.6 = 0.6142, P1.7 = 0.9240
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10AE0 = 0x1F;
ADC10DTC1 = 0x05;
for (;;)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);
ADC10SA = 0x200;
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(CPUOFF + GIE);
v = &ptr;
v1 = &ptr1;
v2 = &ptr2;
v3 = &ptr3;
v4 = &ptr4;
value = ((*v1 + *v2 + *v3 + *v4 + *v)/5);
_NOP();
_NOP();
}
}
// ADC10 interrupt service rout ine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF);
}
Hi Karthik,
v1 and ptr1 are both pointers to void, so in your assignment to v1 you need to set v1 to ptr1, not the address of ptr1:
i.e.: v1 = ptr1;
However, what is the point of v1 etc, why not just do:
value = ((*ptr1 + *ptr2 + *ptr3 + *ptr4 + *ptr)/5);
Regards, Tony.
i did as per ur suggestion still am getting same error
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
ADC10CTL1 = INCH_4 + CONSEQ_1; // P1.0 = 1.0259, P1.1 = 1.5379, P1.2 = 2.0494, P1.3 = 2.5788, P1.4 = 3.0768, P1.5 = 0.3134, P1.6 = 0.6142, P1.7 = 0.9240
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10AE0 = 0x1F;
ADC10DTC1 = 0x05;
for (;;)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);
ADC10SA = 0x200;
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(CPUOFF + GIE);
//v = &ptr;
//v1 = &ptr1;
//v2 = &ptr2;
//v3 = &ptr3;
//v4 = &ptr4;
value = ((*ptr1 + *ptr2 + *ptr3 + *ptr4 + *ptr)/5);
_NOP();
_NOP();
}
}
// ADC10 interrupt service rout ine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF);
}
The type of *ptr1 etc is void. The C language does not define the plus operator for operands of type void. I'm not sure why you are declaring the pointers to be pointer-to-void. If you use pointer-to-int (int *) things should get better.
i did the coding as per all your suggestions its working .now i am trying to set some reference vale for the 5 avg outputs.. i did the coding like if the 5 avg outputs exceed the reference limits.. port 1.6 should be high and the led2 should be glow or else the PORT1.6 should be low and the LED2 in value addition board should not glow. .. but its not working..if i writing the same code for high and low the PORT1.6 for some other program means it s working.. pls check the below codes and help for me
#include <msp430g2231.h>
unsigned int * const ptr = (unsigned int *)(0x0200); // Pointer declaration for RAM address 0x020A
unsigned int * const ptr1 = (unsigned int *)(0x0202);
unsigned int * const ptr2 = (unsigned int *)(0x0204); // Pointer declaration for RAM address 0x020A
unsigned int * const ptr3 = (unsigned int *)(0x0206);
unsigned int * const ptr4 = (unsigned int *)(0x0208); // Pointer declaration for RAM address 0x020A
unsigned int x=0,x1=0,x2=0,x3=0,x4=0,y=0,avg=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
ADC10CTL1 = INCH_5 + CONSEQ_3; // P1.1 = 1.0023, P1.0 = 3.0652, P1.2 = 2.3866
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10AE0 = 0xF1;
ADC10DTC1 = 0x20;
P1DIR |= 0x40;
P1OUT & = ~0x40; //intially resets the P1.6 (led2)
for (;;)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);
ADC10SA = 0x200;
ADC10CTL0 |= ENC + ADC10SC;
x=*ptr;
x1=*ptr1;
x2=*ptr2;
x3=*ptr3;
x4=*ptr4;
y =(x+x1+x2+x3+x4);
avg=(y/5);
__bis_SR_register(LPM0_bits + GIE);
if (avg < 0x1FF)
P1OUT &= ~0x40; // Clear P1.6 LED off
else
P1OUT |= 0x40; // Clear P1.6 LED on
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF);
}
I'm pretty sure the key change is this ...
void *ptr = (void *) 0x200;
changes to ...
unsigned int * const ptr = (unsigned int *)0x200;
Thanks and regards,
-George