View previous topic :: View next topic |
Author |
Message |
Baerle1983
Joined: 21 May 2013 Posts: 1
|
Return Value different to content of Variable ? |
Posted: Sat May 25, 2013 12:38 pm |
|
|
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
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat May 25, 2013 2:54 pm |
|
|
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
|
|
Posted: Sun May 26, 2013 6:24 am |
|
|
Define the return array as static in your function. |
|
|
|