Serial communication trouble

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Serial communication trouble

703 Views
CAAG
Contributor I

Hello, I have trouble on a serial communication subroutine and would like to have some help.

 

I'm using a MC9S12X MCU an after executing a ATD single-channel conversion the following code is executed:

 

                     LDAA ATDDR0
                     JSR SENDATA

 

SENDATA   BRCLR SCISR1,$80,SENDATA
                     STAA SCIDRL
                     RTS

 

The problem is that after the RTS, the program branches to the begging of the code instead of branching to the place of the code where the subroutine was called.

 

I've tried this code on a MC9S12 MCU too and the same thing occurs. I would like to find out why this is happening and any solution. I'll pretty much appreciate any help here.

Labels (1)
0 Kudos
1 Reply

333 Views
bigmac
Specialist III

Hello, and welcome to the forum.

 

One possibility is that you may be stuck within the wait loop in the first line of the SENDDATA sub-routine, and then a COP timeout eventually occurs, to cause a reset.  In this case the sub-routine would not complete, and the RTS instruction would not be reached.  Temporarily comment out the wait loop, and see if the reset problem persists.

 

If you are actually reaching the RTS instruction (and a single SCI character is sent),  perhaps the stack-based return address of the sub-routine is somehow being corrupted.  If execution of an ISR were to occur whilst within the sub-routine, the ISR would be the likely source of the problem.

 

Regards,

Mac

 

0 Kudos