In the file you have provided, I (*finally*) found the lines where you have added the comments about the 'crash' - it is in "nRF.c" if anyone else is looking for it.
However in that file you do not declare or define what 'datalength' is - there are no include files referenced.
THEN I saw that the 'MyProject.c" file includes a whole lot of ".c" files! Whoever taught you to program like this has certainly NOT done you any favours!
What do you mean by "crash"? Does it reset? Does it loop forever? What?
As 'datalength' is declared as a global variable, I suggest that you have a look in the debugger just before you execute the statement that 'crashes' and see what value it has. I suspect that there may be a pointer or similar that is altering the data to something that is not accepted by the SPI1_Write() function (although I have no idea what as the SPI peripheral itself can send any 8 or 16 bit value in that device but there may be some strange code in the library function).
Susan