Hello Guys,
My routine is crashing when trying to perform analog weighing signal reading, using the ADS1231 library.
Probably some pointer error, could you help me?
Below the github link with the library code I am using.
main.c Errorpoint
Code:
while(1) {
if (ADS1231_ReadRawData2(&myData,1)==0)
{
massabuffer[k]=myData.myRawValue;
k++;
if (k==celula_carga.sensibilidade)
k=0;
media=0;
for(int j=0;j<celula_carga.sensibilidade;j++)
media+=massabuffer[j];
myData.myRawValue=media/celula_carga.sensibilidade;
myCalculatedMass = ADS1231_CalculateMass ( &myData, celula_carga.peso_calibracao, ADS1231_SCALE_kg );
}
if (((myCalculatedMass.myMass> (myCalculatedMassAnt.myMass+2)) | (myCalculatedMass.myMass< (myCalculatedMassAnt.myMass-2))) )
{
if (conta_estabilidade>10000)
{
myCalculatedMassAnt.myMass=myCalculatedMass.myMass;
pesoAnterior = pesoTeste;
celula_carga.peso_estavel=0;
}
else
conta_estabilidade++;
}
else
{
if (conta_estabilidade==0)
celula_carga.peso_estavel=1;
else
conta_estabilidade--;
}
if (celula_carga.peso_estavel)
port_pin_set_output_level(LED_STATUS, 1);
else
port_pin_set_output_level(LED_STATUS, 0);
if (F_ENVIA_DADO && iniciado)
{
F_LED_COMUNICA=1;
//QuantidadeBytes=5;
can_send_standard_message(0, tx_message_0, QuantidadeBytes);
F_ENVIA_DADO=0;
}
else
{
if (F_ENVIA_AMOSTRA && celula_carga.envio_automatico && iniciado)
{
tx_message_0[0]=CAN_RX_STANDARD_FILTER_ID_0; //ENDEREÇO ORIGEM
tx_message_0[1]=1; //TIPO DO DISPOSITIVO
tx_message_0[2]=4; //FUNÇÃO
tx_message_0[3]='R'; //LEITURA/ESCRITA
tx_message_0[Dado1]=(int)celula_carga.peso_estavel;
tx_message_0[Dado2]=IO.entradas;
// TODO - FIXO
tx_message_0[Dado3]=(int)pesoTeste>>8;
tx_message_0[Dado4]=(int)pesoTeste;
//tx_message_0[Dado3]=(int)myCalculatedMass.myMass>>8;
//tx_message_0[Dado4]=(int)myCalculatedMass.myMass;
QuantidadeBytes=8;
can_send_standard_message(0, tx_message_0, QuantidadeBytes);
F_ENVIA_AMOSTRA=0;
}
}
if(!iniciado)
{
tx_message_0[0]=CAN_RX_STANDARD_FILTER_ID_0; //ENDEREÇO ORIGEM
tx_message_0[1]=0xFF; //TIPO DO DISPOSITIVO
tx_message_0[2]=0XFF; //FUNÇÃO
tx_message_0[3]=0x57; //LEITURA/ESCRITA
tx_message_0[4]=0x00; //LEITURA/ESCRITA
tx_message_0[5]=0x01; //LEITURA/ESCRI
can_send_standard_message(0, tx_message_0,6); //ID: 0x469
}
iniciado = true;
}
Scope of the 1st function that calls inside main.c and is probably catching
Code:
ADS1231_status_t ADS1231_ReadRawData2 ( Vector_count_t* myNewRawData, uint32_t myAverage )
Code:
typedef struct
{
float myRawValue_WithCalibratedMass;
float myRawValue_WithoutCalibratedMass;
float myRawValue_TareWeight;
uint32_t myRawValue;
} Vector_count_t;
typedef struct
{
float myMass;
} Vector_mass_t;
typedef struct
{
float myVoltage;
} Vector_voltage_t;
#endif
Scope of the 2nd function that calls inside main.c and is probably catching
Code:
Vector_mass_t ADS1231_CalculateMass ( Vector_count_t* myNewRawData, float myCalibratedMass, ADS1231_scale_t myScaleCalibratedMass )