Optimise spiMaster.c and added test code