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.
Summary: Device TI MSC1210 A user function called in main passes a pointer to an array and either a 1 or a 0. The function uses the 1/0 to decide which serial port to use. It then outputs data from the pointed array over serial N. I have tried the function with both a case statement and an if-else. MAIN is an opcode handler which recieves serial opcodes and calls function based on those. When the opcode is given to call the above mentioned function, the function is stepped over. If I remove the case or if-else from the function and hardcode one serial port or the other, it calls just fine. Any ideas? I can post the code, but it'll have to wait till monday.
"Any ideas?" Not without seeing the code! HAve you tried looking at the generated code, and stepping it in the debugger to see where it actually goes "wrong"?
code snippet showing the general idea: void SerialXmit(BYTE * pArray, bit n) { if(n == 1) { //Use Serial Port 1 // transmit pArray stuff } else if( n == 0) { //Use Serial Port 0 // transmit pArray stuff } } void MAIN() { //Initialization Stuff BYTE DataArray [4]; BYTE * pArrayStart; pArrayStart = DataArray[0]; while(1) { switch(opcode) { case opcode4: SerialXmit(pArrayStart,1); break; // rest of cases... } } }
Here's the listing I get for your SerialXmit function:
; FUNCTION _SerialXmit (BEGIN) ; SOURCE LINE # 3 ;---- Variable 'pArray' assigned to Register 'R1/R2/R3' ---- ; SOURCE LINE # 4 ; SOURCE LINE # 5 0000 300004 R JNB n,?C0001 ; SOURCE LINE # 6 ; SOURCE LINE # 7 0003 7441 MOV A,#041H ; SOURCE LINE # 10 0005 8005 SJMP ?C0010 0007 ?C0001: ; SOURCE LINE # 11 0007 200005 R JB n,?C0004 ; SOURCE LINE # 12 ; SOURCE LINE # 13 000A 7442 MOV A,#042H 000C ?C0010: 000C 120000 E LCALL ?C?CSTPTR ; SOURCE LINE # 16 ; SOURCE LINE # 17 000F ?C0004: 000F 22 RET ; FUNCTION _SerialXmit (END)
1 typedef unsigned char BYTE; 2 3 void SerialXmit(BYTE * pArray, bit n) 4 { 5 1 if(n == 1) 6 1 { 7 2 *pArray='A'; 8 2 //Use Serial Port 1 9 2 // transmit pArray stuff 10 2 } 11 1 else if( n == 0) 12 1 { 13 2 *pArray='B'; 14 2 //Use Serial Port 0 15 2 // transmit pArray stuff 16 2 } 17 1 }
Well, I got back to work this morning and started poking around through the compiler outputs. Turns out it was indeed skipping the call. I changed the optimization settings, recompiled, and viola - function called properly. Thanks for the replies.
Can you please contact technical support about the code that was skipping the call so we can take a look at it and get this problem corrected? Jon