C on Raspberry Pi: SPI order changes when 'printf' statement is executed -


i working on project in c on raspberry pi 2 in pi polling microcontroller via spi when microcontroller asserts particular pin.

there 2 functions intended executed in fashion. 1 of functions - lnk_pollnetwork() - checks see if request pin high , - if - downloads data until pin low again, parses. other function - lnk_generatenetstat() - sends byte requesting network status , downloads data until pin low again.

it seems if place 'printf' statement after poll byte in lnk_generatenetstat(), works fine. if remove printf statement, program goes haywire , clear me other function executing in parallel function.

both functions on same thread... or believe.

void lnk_generatenetstat(){     uint8_t statusserialstring[(netstat_header_bytes                     + (max_num_of_nodes                     * netstat_field_width_bytes))];     uint8_t = 0;      spi_transfer(0x86);      /* if printf executed, works */     if(verbose)         printf("network status polled");      while(bcm2835_gpio_lev(req_pin) == high){         statusserialstring[i] = spi_transfer(0xfe);         i++;     }      /* parsing code below line */     /* ... */ } 

the other function polls request pin and, if high, starts pulling data until pin low:

void lnk_pollnetwork(){     if(bcm2835_gpio_lev(req_pin) == high){         int = 0;         uint8_t payload[payload_max_length];          spi_transfer(0xff);  // dummy read - allows slave load buffer         while(bcm2835_gpio_lev(req_pin) == high){             payload[i] = spi_transfer(0xff);             i++;         }          /* payload parsing below line */         /* ... */     } } 

both of these should executed sequentially. there higher level task manager executes lnk_pollnetwork() every 1ms , lnk_generatenetstat() every 1250ms.

i know lnk_generatenetstat() being pre-empted because have used different values in spi polling routine each function in order identify going on. 0x86 executes , should begin polling bytes numbered 0xfe, seeing 0xff bytes in many cases , - - intermixed. i'm using logic analyzer observe.

thoughts?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -