We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have some code to transfer a large amount of data over a SPI port running at the system clock/2 so I need my code to be as fast as possible. The code generated for my current method does not seem to be as optimal as it could be. I am using optimization (8, speed) with the 7.07 C51. Here is a simplified version of my code:
//this variable set in buffer data function static unsigned char xdata * data spiDataPtr; void transferData(void) small { //do not want to store changes in //spiDataPtr so use temp pointer unsigned char xdata * tempPtr; unsigned char data i; unsigned char data temp; tempPtr = spiDataPtr; //transfer set block size for(i = 0xff; i != 0; i--) { SPIDATA = *tempPtr; //initiate transfer tempPtr++; //prepare for next send while busy transfering while(!SPITXDONE); //wait for transfer to complete temp = SPIDATA; //read to avoid colission error } }
Hi, I think you should use #ASM/ENDASM for routines which must be as fast as possible really. Even example shown above is not fast enough. Really, it may be optimized much more:
MOV R7,#0FFH LOOP: MOVX A,@DPTR JNB SPITXDONE,$ XCH A,SPIDATA INC DPTR DJNZ R7,LOOP RET