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.

SSI Handlers and passing adc output to web browser

Hello !

I want to pass output of adc module to web browser via ssi handlers, but SSI handlers does pass the char * instead of int * . So, how can I pass my buffer pointer to SSI handler so it can be displayed on web browser. What changes can I do to make it possible, does it require changes in http_rawserver.c file of LWIP or it can be without of doing change in lwip files.

Regards

  • It would be a little surprising if they handled anything other than characters. You have to do the formatting yourself. Web browsers can only handle characters.

    Robert
  • Hi Ali, try sprintf(), something like this, to send a character string to the browser:

    char myString[11];
    
    sprintf(myString, "ADC %6d", adcValue);
    myString[10] = '\0';
    
    // now use myString to send the ADC reading to the web browser

    www.cplusplus.com/.../

    Good luck

    Angelo

  • Hi Angelo !
    Thanks for your kind reply, I got your point, the thing I was doing wrong with sprint was passing the int buffer pointer instead of a single value.

    Can I pass the the buffer pointer in as a last parameter of sprint(); as u mentioned it as adcvalue.

    Regards
    Haroon
  • Ali, I have only worked with the TM4C123GXL Launchpad and have no experience with other µcontrollers. When  I use the ADC I have something like this

    uint32_t adcReading;
    
    MAP_ADCSequenceDataGet(ADC0_BASE, 0, &adcReading);

    But if your ADC reading is kept in a buffer that holds the pointer to the 32-bit value, you could use something like this

    sprintf(stringBuffer, "%d", *intBuffer);

    Good luck,

    Angelo

  • Hello Angelo !

    I have used the same as u told me but the sprint() is not working with my code, please have a look on my adc code as shown below, and let me know about bugs of my code,

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/adc.h"
    #include<stdio.h>
    
    
    volatile uint32_t value[1];
    uint32_t bufptr[1];
    char pcInsert[50];
    void adc ();
    void main(void) {
    
    	 
    
    	SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ);
    	SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
    		SYSCTL_CFG_VCO_480), 120000000);
    
    adc();
    
    sprintf(pcInsert,"%d",&value);// i am unable to get the output of pcInsert. when i see in watch window i see .... in pcInsert, 
    			                      //why i am getting this
    
    void adc(){
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
    	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    	ADCSequenceStepConfigure(ADC0_BASE, 3,0, ADC_CTL_CH9|ADC_CTL_IE|ADC_CTL_END);
    	ADCSequenceEnable(ADC0_BASE, 3);
    while(1) {
    	ADCIntClear(ADC0_BASE, 3);
    	ADCProcessorTrigger(ADC0_BASE, 3);
    	while(!ADCIntStatus(ADC0_BASE, 3, false))
    	{
    	}
    	ADCSequenceDataGet(ADC0_BASE, 3, bufptr);
    
     value[0]=bufptr[0];
    
    
    
    
    }
    	}
    
    
    
    

  • sprintf(pcInsert,"%d",&value);

    This is not scanf() - try passing the value of the variable in your call to sprintf(), not it's address.

    Something like  sprintf(pcInsert,"%d",value[0]);
  • Hello f.m !
    I did the same but did not get any value to my pcInsert buffer. please suggest another solution to this . Thanks a lot
    Regards
    Ali
  • Wouldn't it be helpful to do the ADC initialisation and starting before your sprintf() string operation ?

    Just referring to the code provided some posts earlier.

  • I have initialized the sprint() before adc(); function call, but the same result . can u suggest me another function to store integer to char buffer
  • Ali, since you are reading just one sample from the ADC, I suggest you use a regular variable instead of a vector, since a vector in C is just a pointer to a memory location with space pre-allocated by the compiler. I would modify your code this way:

    #include <stdint.h>
    #include <stdio.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/adc.h"
    
    volatile uint32_t value;
    char pcInsert[50];
    
    void adc ();
    
    void main(void) {
        SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ);
        SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
    
        adc();
    
        sprintf(pcInsert, "%9d", value);
        pcInsert[9] = '\0';
    
        // the remaining code in main() does not matter for our discussion
    }
    
    void adc() {
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
        ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH9|ADC_CTL_IE|ADC_CTL_END);
        ADCSequenceEnable(ADC0_BASE, 3);
        while(1) {
            ADCIntClear(ADC0_BASE, 3);
            ADCProcessorTrigger(ADC0_BASE, 3);
            while(!ADCIntStatus(ADC0_BASE, 3, false));
            ADCSequenceDataGet(ADC0_BASE, 3, &value); // pass the address of the variable
        }
    }

    Good luck

  • Oops, after I posted I think I saw a problem with your code. The ad() function starts an infinite loop. It will never return to main() and you will not have the reading of the ADC available to main(). The adc() function should be this way:

    void adc() {
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
        ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH9|ADC_CTL_IE|ADC_CTL_END);
        ADCSequenceEnable(ADC0_BASE, 3);
        ADCIntClear(ADC0_BASE, 3);
        ADCProcessorTrigger(ADC0_BASE, 3);
        while(!ADCIntStatus(ADC0_BASE, 3, false));
        ADCSequenceDataGet(ADC0_BASE, 3, &value); // pass the address of the variable
    }

  • Hello ,
    Thanks for your kind advice, but the result is same sprint() is not writing any thing in pcInsert, I have applied same code as wrote above, I am not getting where I am wrong,

    although your code gives the compiler warnings like mismatch in &value type that is volatile type declared.

    Can anybody help me in this ,

    Ali
  • I have already removed While(1) { }; in my code but still not getting output using sprint
    Ali
  • How about debugging, to verify that your ADC code actually works ?

    Does it deliver a sensible value to your bufptr variable ?

    BTW, I agree with Angelo, one-item-arrays make very limited sense. And to avoid confusion, it's better to not use *ptr in variable names that are not pointers.

  • Hello Ali, I keep forgetting about the need to increase the heap and stack sizes when using stdio functions. I had to increase both the heap and the stack to 1024 to make this code work in my Launchpad:

    #include <stdint.h>
    #include <stdio.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/adc.h"
    
    static uint32_t value;
    char pcInsert[50];
    
    void adc ();
    
    void main(void) {
        SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ);
    	SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ | SYSCTL_USE_PLL | SYSCTL_SYSDIV_4);
    
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    
        adc();
    
        sprintf(pcInsert, "%9d", value);
        pcInsert[9] = '\0';
    }
    
    void adc() {
    	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0);
        ADCSequenceEnable(ADC0_BASE, 3);
    	ADCIntClear(ADC0_BASE, 3);
    	ADCProcessorTrigger(ADC0_BASE, 3);
    	while(!ADCIntStatus(ADC0_BASE, 3, false));
    	ADCSequenceDataGet(ADC0_BASE, 3, &value);
    }

    I have a potentiometer connected to the pin that I configured and I am able to see that pcInsert correctly gets the text value of the reading. The above code works perfectly in my TM4C123G Launchpad.

    If this solution works for you, of course with the needed changes for your board, please mark this post as an answer.

  • Thanks , just increase in heap size make it worked