CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sprintf error 114

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alimary158



Joined: 26 Jan 2012
Posts: 16

View user's profile Send private message

Sprintf error 114
PostPosted: Thu Jan 26, 2012 11:32 am     Reply with quote

Hello, i am using a command
sprintf(pressure,"Valore=%d\r\n",RxBaseADC[RxTailADC++]);

where the RxBaseADC[RxTailADC++] is a int16[32]

but when i try to compile it gives me this error:

error 114: sprintf format type is invalid

here is my full code

in particular the RxBaseADC[RxTailADC++] variable is coming from a ring buffer that i implement in the code



has anyone any suggestion? i don't know why this error is coming

thank you all

Code:



#include <PIATTAFORMA.h>
#ifndef DWORD
#define DWORD int32
#endif

#ifndef WORD
#define WORD int16
#endif

DWORD get_fattime(void)
{
   return 0;
}

#include <ff.h>


int16 data=85;
int16 value=0;
//int8 databyte1=0;
//int8 databyte0=0;
//int8 TIME_H=0,TIME_L=0, CKS=0;



char mesg[32];


#define RxADCQsize 32
volatile int16   RxBaseADC[RxADCQsize];

// Rx Ring Buffer control
volatile BYTE   RxHeadADC;
BYTE   RxTailADC;



void init_pic(void)
///////////////////////////////////////////////////////////////////////////
// void init_pic(void)
//
// Initialise the hardware defaults
///////////////////////////////////////////////////////////////////////////
{
   setup_spi(FALSE);
   
   setup_wdt(WDT_OFF);
   
#ifdef PCmp_Def
   // setup_comparator
   CMCON = PCmp_Def;   // initialise comparators
#endif
   
   // initialse port A
   output_a(PA_DefData);
   set_tris_a(PA_DefTRIS);
   
   // initialise port B
   port_b_pullups(TRUE);
   output_b(PB_DefData);
   set_tris_b(PB_DefTRIS);
   
   // initialise port C
   output_c(PC_DefData);
   set_tris_c(PC_DefTRIS);
   
#ifdef PD_DefData
   // initialise port D
   output_d(PD_DefData);
   set_tris_d(PD_DefTRIS);
#endif
   
#ifdef PE_DefData
   // initialise port E
   output_e(PE_DefData);
   set_tris_e(PE_DefTRIS);
#endif
   
#ifdef PF_DefData
   // initialise port F
   output_f(PF_DefData);
   set_tris_f(PF_DefTRIS);
#endif
   
#ifdef PG_DefData
   // initialise port G
   output_g(PG_DefData);
   set_tris_g(PG_DefTRIS);
#endif
   
#ifdef PH_DefData
   // initialise port H
   output_h(PH_DefData);
   set_tris_h(PH_DefTRIS);
#endif
   
#ifdef PJ_DefData
   // initialise port J
   output_j(PJ_DefData);
   set_tris_j(PJ_DefTRIS);
#endif
   
   
}

#INT_timer2

void timer2_isr()
{
   

   //disable_interrupts(global);
   
   //data=read_adc(); //This function will read the digital value from the ADC
   //databyte1=make8(data,1); //estraggo byte high
   //databyte0=make8(data,0);//estraggo byte low
   
   
     
   //Covertire dato intero in una stringa
  // sprintf(mesg,"%d",data);
   
 
 
   RxBaseADC[RxHeadADC++]=data;
   
   // test if ring buffer wrap is required
   if (RxHeadADC >= RxADCQsize)
      RxHeadADC = 0;
 
   
  // enable_interrupts(global);
   
}



void main (){
   
   
   
   
    FIL fsrc;            // file structures
    FRESULT result;     // FatFs function common result code
    WORD btw, bw;       // File R/W count
     

   
    FRESULT   FS_Status;
   
    char pressure[64];
 
   disable_interrupts(GLOBAL);
   
   restart_wdt();
   
   
   // Pic Inizialization
   init_pic();
   
 
   
   //setup_adc_ports(sAN1);
   
   //setup_adc(ADC_CLOCK_INTERNAL);
   
   //set_adc_channel(1);
   
   setup_timer_2 (T2_DIV_BY_16, 255, 1);
   
   RxHeadADC=0;
   RxTailADC=0;
   
   //clear_interrupt(INT_RDA);
   //enable_interrupts(INT_RDA);
   
   
   
   
   
   enable_interrupts(GLOBAL);
  // enable_interrupts(int_timer2);
   
   
   do
   {
      FS_Status = f_mountdrv();
   }
   while (FS_Status);
   
   
   //Il file creato si chiamera pressure.txt
   strcpy(pressure,"event4.txt");
   
   //F_OPEN(): if the file already exist the datas will be appened. if the file doesnt exsist it is created
   
   result  = f_open(&fsrc,&pressure, FA_OPEN_ALWAYS | FA_WRITE);
   
   
  //Find the end of the file to append datas
 
   result = f_lseek(&fsrc, fsrc.fsize);
   
   
   
   //write a string delimiter to each append data log
   
            strcpy(pressure, "\r\nNewTrial \r\n");
         
            btw=strlen(pressure);
         
            result = f_write(&fsrc,pressure, btw, &bw);
           
           
       
   //checking the buffer tail and head
   
   disable_interrupts(int_timer2);
   
   if (RxHeadADC != RxTailADC)
   {
      enable_interrupts(int_timer2);
   
      // here we have data waiting to be written
 
      sprintf(pressure,"Valore=%d\r\n",RxBaseADC[RxTailADC++]);
      // test if ring buffer wrap is required
      if (RxTailADC >= RxADCQsize)
            RxTailADC = 0;
          f_write(&fsrc,pressure,strlen(pressure),&bw);

       }
    else
    enable_interrupts(int_timer2);
   
   
 
           

   result = f_sync(&fsrc);
   
   
   f_close(&fsrc);
   
}
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 26, 2012 11:56 am     Reply with quote

hmmmmmmmm.....
sprintf(pressure,"Valore=%d\r\n",RxBaseADC[RxTailADC++]);

My guess is that the compiler doesn't like the ++ added to the end of the varibale RxTailADC.

I'd suggest trying something like..

dummy_value=1;
sprintf(pressure,"Valore=%d\r\n",RxBaseADC[dummy_value]);

and see what happens.

If the error goes away then you've found out why there is the problem
alimary158



Joined: 26 Jan 2012
Posts: 16

View user's profile Send private message

PostPosted: Thu Jan 26, 2012 12:17 pm     Reply with quote

i have changed my code in this way:

Int16 dummy_value;

dummy_value=RxBaseADC[RxTailADC];

RxTailADC=(RxTailADC+1);

sprintf(pressure,"%d",dummy_value);

but the error keeps going!!!!!!!!
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 26, 2012 12:53 pm     Reply with quote

%d specifies a signed integer ( 8 bits) -128 to +127

dummy_value has been declared a long integer(16 bits)

if you press F11 with your project open, you''ll access the onscreen Help files that CCS provides..
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Jan 26, 2012 2:06 pm     Reply with quote

temtronic makes a good point here. Lets hope the F11 help key isn't missing on some keyboards. Also a quick look at a beginners C code tutorial especially basic syntax might also be a useful strategy for some. Chances are if you are new to CCS then the error you have has already been made before so searching C syntax and this board often will lead to a faster solution.
alimary158



Joined: 26 Jan 2012
Posts: 16

View user's profile Send private message

PostPosted: Thu Jan 26, 2012 2:23 pm     Reply with quote

Hello yes the problem was in the %d that i changed in %lu now this is working!

thank you so much
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group