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

CCS USB code won't print an int32 long signed or unsigned

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



Joined: 21 Nov 2011
Posts: 11

View user's profile Send private message

CCS USB code won't print an int32 long signed or unsigned
PostPosted: Thu Feb 02, 2012 11:03 am     Reply with quote

Hi all,
I'm using the CCS supplied USB CDC software functions along with the driver on my PC and everything works fine except it crashes when printing an int32. (signed or unsigned) I've tried %Lu and %Ld, but neither work. %X does work however, which is strange.

I'd like to print the values in decimal and not hex. Is this a bug or am I doing something wrong?

Thanks,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 02, 2012 11:20 am     Reply with quote

Post your PIC, compiler version, and a short program that shows the
problem. The program should have an #include, #fuses, #use delay()
statements, and a main().

Example of compiler version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
lindermat



Joined: 21 Nov 2011
Posts: 11

View user's profile Send private message

PostPosted: Thu Feb 02, 2012 12:54 pm     Reply with quote

I can't really post it since has a lot of company information, (and it's in many different files), but the parts you asked for are below:
Code:

#include <24FJ256GB210.h>
//#device ICD=2

//#fuses DEBUG                     // Debug mode for use with ICD
#fuses NODEBUG                   // No debug mode
#fuses NOWDT                     // Watch Dog timer disabled
#fuses NOWINDIS                  // Watch Dog Timer in Window mode
#fuses NOJTAG                    // JTAG disabled
#fuses NOIOL1WAY                 // Allows multiple configuration of peripheral pins
#fuses CKSFSM                    // Clock Switching is enabled, fail Safe clock monitor is enabled
#fuses PLL6                      // Divide primary oscillator 24MHz input by 6 to get 4MHz
#fuses NOPROTECT                 // Code NOT protected from reading
#fuses ICSP1                     // Use ICSP port 1
#fuses WPDIS                     // All Flash memory may be erased or written

#use delay(clock=32MHz, crystal=24MHz)
#use fast_io(ALL)

#use I2C(master, slow, sda = PIN_A15, scl = PIN_A14, force_hw, stream = I2C1)
#use I2C(master, slow, sda = PIN_A3,  scl = PIN_A2,  force_hw, stream = I2C2)
#use I2C(master, slow, sda = PIN_G0,  scl = PIN_G1,  force_hw, stream = I2C3)

#pin_select SDI1 = PIN_F8        // Data Out from SPI configuration memory (into the PIC)
#pin_select SDO1 = PIN_F3        // Data In to SPI configuration memory (out from the PIC)
#pin_select SCK1OUT = PIN_F2     // Serial CLocK signal to SPI configuration memory

#use SPI(master, di = PIN_F8, do = PIN_F3, clk = PIN_F2, force_hw, stream = SPI1, sample_rise, BITS = 8)

#pin_select OC2  = PIN_D5        // For output compare module PWM to the circulation fan (CH1_LOAD)
#pin_select OC3  = PIN_D4        // For output compare module PWM to the condensor fan (CH2_LOAD)
 
#include <defines.c>
#include <variables.c>
#include <ISRs.c>
#include <serial_flash.c>
#include <Gen2 Rev-.h>
#include <usb_cdc.h>
#include <string.h>
#include <input_output.c>

void main(void)
{


And finally the print statement:

Code:
   printf(usb_cdc_putc, "\r\nPower cycle number = 0x%X", Read_Int32_From_Page(POWER_CYCLE_OFFSET, READ_POINTER));

Which works with the %X, but not %Lu or %Ld
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 02, 2012 1:26 pm     Reply with quote

Quote:

printf(usb_cdc_putc, "\r\nPower cycle number = 0x%X", Read_Int32_From_Page(POWER_CYCLE_OFFSET, READ_POINTER));

The first thing I would try is to break up this complex statement into
two smaller statements. See if it then works. Example:
Code:

void main()
{
int32 result;
.
.
.
result = Read_Int32_From_Page(POWER_CYCLE_OFFSET, READ_POINTER);
printf(usb_cdc_putc, "\r\nPower cycle number = %lu", result);

while(1);
}
lindermat



Joined: 21 Nov 2011
Posts: 11

View user's profile Send private message

PostPosted: Thu Feb 02, 2012 2:01 pm     Reply with quote

Good idea, I thought that might work, but no luck.
It still locks up on %Lu but %X is ok.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 02, 2012 2:19 pm     Reply with quote

I don't have the PCD compiler to test, but you could try a couple more
things.

1. Try using sprintf() with %lu, which should put the output into an array.
Then display the array contents with "%s".

2. I suppose it's possible that CCS just wants "%L" for an int32 with PCD.
The manual doesn't say that, but that's another thing I would try.

I can't really do much more, because I don't have the compiler to test or
analyze the problem.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Feb 03, 2012 12:35 am     Reply with quote

Did you try to increase the default stack size?
lindermat



Joined: 21 Nov 2011
Posts: 11

View user's profile Send private message

PostPosted: Fri Feb 03, 2012 10:37 am     Reply with quote

Yes, that was it! It works now. (I also got the same reply from the official CCS support) Thank you everyone for your prompt replies!
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Fri Mar 30, 2012 3:16 am     Reply with quote

Hey!
I have the same problem to print int32.
what was your solution?
using sprintf?
increase the default stack size?
using "%L" ?

can you share the solution please

thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Fri Mar 30, 2012 3:46 am     Reply with quote

Increasing the stack size.
This is _required_ by 90% of code using %f, %l etc..
CCS defaults to having the stack so small that several of the default printf operators won't work....
It is just about the commonest problem on PCD.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Fri Mar 30, 2012 6:31 am     Reply with quote

Thanks for your quick reply
I'm sorry, but I don't really understand "how to do"
I guess the sprintf method schould work, but i would avoid to use a string as tempory variable.
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Fri Mar 30, 2012 6:56 am     Reply with quote

look at the #build pre processor directive in the compiler manual. It has instructions on how to set the stack size.
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