|
|
View previous topic :: View next topic |
Author |
Message |
mtsoule
Joined: 19 Oct 2011 Posts: 31
|
String fprintf and fputc (fputc works, printf does not) |
Posted: Sun May 20, 2012 9:47 am |
|
|
ok, with this code my output is
I expect the output to be
which tells me the length of my string is 0, however if I uncomment the fputc statement, I get the expected data.
I have, for simplicity, taken out all of the error checking and other non essential code.
Compiler version is 4.132
Code: |
while(BT_inchar != '\n')
{
while(!BT_Inchar_Ready)
{
}
BT_Inchar_Ready = 0;
RX_Buffer[RX_ctr] = BT_inchar;
RX_ctr++;
// fputc(BT_inchar,prog);
}
fprintf(prog,"{%i{%s}}",strlen(RX_buffer), RX_Buffer);
|
here is my isr
Code: |
#int_RDA
void RDA_isr(void)
{
BT_Inchar = getc(BT);
BT_Inchar_Ready = 1;
}
|
|
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun May 20, 2012 5:47 pm |
|
|
Keep in mind using any string stuff in fprintf (or just printf) requires the string be NULL terminated.
Otherwise, the printf can run off into la-la land.
So when you get your string, before printing it, you need to make sure there's a zero at the end.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
mtsoule
Joined: 19 Oct 2011 Posts: 31
|
Got it!! |
Posted: Mon May 21, 2012 4:39 am |
|
|
Thanks Ben, that was it! i ended up moving my "Buffer Filler" to the ISR (i hate putting it there) i like to go in to the ISR and get out. But i found it works best for my app.
Basically here is what i have now in the ISR
Code: |
#int_RDA
void RDA_isr(void)
{
BT_Inchar = getc(BT);
if((Packet == Packet_Count) && (BT_Inchar != '\r') && (BT_Inchar != '\n'))
{
RX_Buffer[RX_ctr] = BT_Inchar;
RX_ctr++;
RX_Buffer[RX_ctr] = 0x00;
}
if(BT_Inchar == '\n')
{
BT_Inchar_Ready = 1;
Packet_Count++;
}
} |
i do this so i can read a spific portion of the incomming stream, and i also want to throw away all the "LF's" and "CR's" |
|
|
|
|
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
|