Thread: Routine locking when calling weight reading function (Pointer as argument)

  1. #1
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184

    Routine locking when calling weight reading function (Pointer as argument)

    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 )

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Do you have a UART or similar?

    It is really hard to make heads or tails from that code, because I can't see where everything is defined/setup


    If you don't have any UART/I2C/SPI/... to actually display the values, toggling a pin under certain conditions can also be used.

    Code:
    if(apple == NULL) 
      SetTestPinHigh();

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > My routine is crashing when trying to perform analog weighing signal reading, using the ADS1231 library.
    > Probably some pointer error, could you help me?
    Instead of speculation, run the program in the debugger.

    Then print the stack trace and all the parameters and local variables in the crashing frame.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-14-2013, 03:25 PM
  2. Calling argument of member function
    By davewang in forum C++ Programming
    Replies: 3
    Last Post: 02-26-2010, 01:51 PM
  3. Calling a function with argument
    By Ali.B in forum C Programming
    Replies: 2
    Last Post: 08-08-2009, 10:58 AM
  4. Thanks for locking my post and calling me a cheater.
    By phosphorousgobu in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 12-12-2004, 02:41 PM

Tags for this Thread