|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Printf prints only the first character
Have you added recent code that generates a lot of interrupts? You could be missing some now. Or maybe...
Your output is going crazy when you try to print your first variable. Is there something wrong with your variables? Is the linker giving you any warnings? HTH |
|
#2
|
|||||
|
|||||
|
Re: Printf prints only the first character
Quote:
) so maybe...Code:
unsigned int EEPROM_Read2Byte(unsigned int arg_address) {
//Return the parameter.
return (EEPROM_Read(arg_address) * 0x100) + EEPROM_Read(arg_address+1);
}
Now, why don't we have a "beating head on brick wall" smiley? JBot |
|
#3
|
|||||
|
|||||
|
Re: Printf prints only the first character
Your last two parameters in the third printf() are single bytes. The %d specification wants to see two-byte integers. You are thus causing it to try to read more data than you've provided, which results in really really weird printing.
If those last two things are really single bytes, make the printf() happy by saying (int)EEPROM_Read(...). Otherwise, correct them to say EEPROM_Read2Byte(...). |
|
#4
|
|||
|
|||
|
Re: Printf prints only the first character
The last two calls are to routines that return single bytes... but the compiler automatically passes these as ints to the printf - for readability you can and the (int) or (unsigned int) case, but it won't change the code generated.
Code:
RCALL EEPROM_Read MOVF POSTDEC1, F, ACCESS ; pop the arg off stack MOVF POSTDEC1, F, ACCESS ; pop 2nd byte of arg off stack MOVWF POSTINC1, ACCESS ; push returned char onto stack CLRF POSTINC1, ACCESS ; push 2nd byte of zeros onto stack printf( "P: %d / %d\r\n", EEPROM_Read2Byte(EEPROM_ADDRESS_P_NUMERATOR),EEPRO M_Read2Byte(EEPROM_ADDRESS_P_DENOMINATOR) Could be running up against variable stack limit (shouldn't be) or formated printf buffer limit... Actually, I'll take that back... could be a variable stack limit depending on how the printf -> vprintf -> vfprintf -> ... is done vis-a-vis copying stack arguments. Debug steps are the same, reduce the printf. Could change this into a series of printfs and leave off the \r\n until the last one in the series too. |
|
#5
|
|||||
|
|||||
|
Re: Printf prints only the first character
OK, new strangeness...
I used to see this glitch only on lines that had variables in them. I now am getting single-character output from a line with no variables. It always prints the first token; if I have a %d first thing, the number is printed, but often the rest of the string is absent. Code:
PRESET #1 EDIT: S-1 Wrist goal: 2 Code:
int loc_temp;
printf("\r\nPRESET #%d EDIT:\r\n",(int)arg_preset);
loc_temp = EEPROM_Read2ByteSigned(EEPROM_ADDRESS_PRESET_BASE + (arg_preset-1)*EEPROM_PRESET_LENGTH + EEPROM_PRESET_OFFSET_SHOULDER);
printf("Shoulder goal: ");
printf("%d\r\n",loc_temp);
loc_temp = EEPROM_Read2ByteSigned(EEPROM_ADDRESS_PRESET_BASE + (arg_preset-1)*EEPROM_PRESET_LENGTH + EEPROM_PRESET_OFFSET_WRIST);
printf("Wrist goal: ");
printf("%d\r\n",loc_temp);
This is getting stranger by the second. JBot |
|
#6
|
||||
|
||||
|
Re: Printf prints only the first character
Try things one at a time. You can't easily deduce which line is causing the problem. The output is buffered so sometimes its a bit difficult to correlate the cause of the problem with what actually makes it out the serial port.
Are you sure you are not reading from places in memory that are not in the EPROM? Try printing out the parameters to the EEPROM_Read2ByteSigned function. Maybe the serial buffers are overflowing, are you checking the return values of printf? HTH |
|
#7
|
|||||
|
|||||
|
Re: Printf prints only the first character
Quote:
[QUOTE}Are you sure you are not reading from places in memory that are not in the EPROM? Try printing out the parameters to the EEPROM_Read2ByteSigned function.[/quote] Aah...good point. I'll check that exhaustively today. They appear to read/write and retain their value fine, though, suggesting that they are indeed EEPROM. Quote:
What is the expected return value? I would assume 0, and nonzero is failure...but I never thought about it at all. Thanks so much for continuing to check this thread. I've had another printf bug thread die quickly with not many replies... JBot |
|
#8
|
||||
|
||||
|
Re: Printf prints only the first character
" On success the number of input fields converted and stored are returned. If an input failure occurred, then EOF is returned."
HTH |
|
#9
|
||||
|
||||
|
Re: Printf prints only the first character
try not calling frunctions from the printf i have had trouble with that in the past..
|
|
#10
|
|||
|
|||
|
Re: Printf prints only the first character
I just started having this same problem last night as well. It seems to be a series of printfs that are in a single if block. I can comment out any combination of them and get the same result. The one thing I didn't check was passing a byte as an argument although Ithink I've done this in the past without problems.
Subsequent printfs don't seem to be a problem. One symptom is that I have multiple lines in single printfs (ie. printf("x=%d\n\ry=%d\n\r", x, y) I get the first character of each line not just the first character of the printf. |
|
#11
|
||||
|
||||
|
Re: Printf prints only the first character
This is smelling like a stack issue.
HTH |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| THE FIRST AND ONLY PALMETTO FANTASY FIRST LEAGUE (so far!) | Billfred | Fantasy FIRST | 106 | 04-04-2005 22:52 |
| printf isn't printf-ing. Help! | Meandmyself | Programming | 14 | 15-02-2004 16:27 |
| pic: And it's only the first day... | CD47-Bot | Chit-Chat | 8 | 17-01-2004 20:21 |
| An effort to get all the blue prints measurment | archiver | 2001 | 1 | 23-06-2002 22:43 |