0

I have been having some problems with the segment of code below.

#include "stm32f0xx_tim.h"
#include "stm32f0xx_adc.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_conf.h"
#include "adc.h"

void calcSensor(float voltage1, float voltage2, int X, int Y)
{
    float Iload = 0;
    float Vsensor = 0;
    float Rsensor = 0;
    float Vdrop = voltage1 - voltage2;
    uint32_t resistance = 0;
    Iload = Vdrop/Rload;
    Vsensor = Vin - Iload*Rmux - Iload*Rdemux-Vdrop;
    resistance = Vsensor/Iload;
    Rsensor[1][5] = resistance;
    Y++;
    if (Y == 22)
    {
        Y = 0;
        X++;
        if (X == 44)
        {
            X = 0;
        }

    }
}
void initRArray(void)
{
    int x;
    int y;
    for(x = 0; x < 44; x++) 
    { 
        for(y = 0; y < 22; y++)
        {
            Rsensor[x][y] = 0;
        }   
    }
}

The error comes the line:

Rsensor[1][5] = resistance;

The error is the same as the title:

subscripted value is neither array nor pointer

I originally had X and Y for indicies but have switched to 0 and 5 thinking it may have been an issue. That did not fix it. Additionally, I have the intRarray function which sets all values to 0. This array compiles fine, and it is using the same array that is having issues.

Below is the declaration of the array in the header file.

unsigned long int Rsensor[44][22];

2 Answers 2

3

You have a local variable float Rsensor = 0; which shadows the global array. Rename one of the two.

Sign up to request clarification or add additional context in comments.

2 Comments

Hungarian notation would have avoided this problem ;)
@MattMcNabb: We had a problem with our variable names, so we introduced Hungarian notation. Now we have two.
0

You have the following declaration in the program

float Rsensor = 0;

This makes Rsensor a float variable, not an array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.