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

Return Value different to content of Variable ?

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



Joined: 21 May 2013
Posts: 1

View user's profile Send private message

Return Value different to content of Variable ?
PostPosted: Sat May 25, 2013 12:38 pm     Reply with quote

Hello Everyone,

i have a function to read from the SPI:
Code:
char *edip_read(void)
{   char result[10];
   int i=0;
   edip_SendC(0x00);
   do
   {
   output_bit(edip_ss,0);
   result[i] = spi_read2(0);
   output_bit(edip_ss,1);
   i++;
   }while(!input(Pin_B0));
   
   #ifdef debug
   printf("EDIP_Read:%s",result);
   #endif
   return result;

}


which is called from my isr with:
Code:

   Printf("Int Result:%s",edip_read());


The written results from the 2 printf´s differ in the first 2 Characters, the 3rd to 9th are equal.

Can anyone tell me what i´m doing wrong ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 25, 2013 1:14 pm     Reply with quote

Read this thread about returning a pointer to a local variable:
http://www.ccsinfo.com/forum/viewtopic.php?t=38421
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sat May 25, 2013 2:54 pm     Reply with quote

Quote:

which is called from my isr with:
Code:

Printf("Int Result:%s",edip_read());


it is i very risky and not good practice to do serial IO
from inside an ISR

instead use flags to semaphore "data ready"
and do the printf from main() or one of its child functions.
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Sun May 26, 2013 6:24 am     Reply with quote

Define the return array as static in your function.
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