any ideas to debug SCI code

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

any ideas to debug SCI code

4,062 Views
bhandley
Contributor I
I have spent most of today getting a 9S12 variant to spit data out fo the serial port.  However, it seems that no matter hwat characters I program to go out of the port, I get other characters.  I have tried many different baud rates on the target side (MCU) and on the receiving host side (my PC).
I have gone through the debugger multiple times and I am satisfied that the functions are passing the correct data and supposedly handing the correct data to the SCI Data register.  Once I view it on my PC, it makes no sense.  So does anybody have any tried-and-true ways for debugging SCI communication problems?
 
Brian
Labels (1)
0 Kudos
Reply
4 Replies

872 Views
glork
Contributor I
Hello Brian.
You need to confirm that your UART setup is correct:
1. The bit-rate is probably the most difficult/error-prone area. Make sure you know EXACTLY what bit-rate you've set.
2. The bit-rate 'deviation from ideal' is also important. The divisors you choose must put the bit-rate within about 2% of the standardized bit-rate (i.e. 9600 +/- 2% bps).
3. Make sure your data bits, parity and stop-bits settings are correct (must be identical to those of the pc you are trying to talk to).

Your problem is likely to be somewhere in the above.
ron
0 Kudos
Reply

872 Views
bigmac
Specialist III

Hello Brian,

You mention that you have problems sending SCI data, but can you correctly receive any data?  Are you using a MAX232, or similar device to provide the interface to the PC?  Some MCUs have an option to invert the transmit data - I wonder if this is properly set up?  If the interface circuitry you are using inverts the data, the SCI setting should be non-inverted (normal).

I also assume that you have not unintentionally enabled 9-bit mode.

Regards,
Mac

 

0 Kudos
Reply

872 Views
bhandley
Contributor I
I swapped the wires on my serial to USB converter.  This gave me recognizable characters (at least correlating to what I expected).  After that I had to insert a significant delay loop after each character send.  I guess the processor was working faster than the serial port could output.  Thanks to all for your ideas.
0 Kudos
Reply

872 Views
bigmac
Specialist III

Hello,

It appears you may not have been waiting for the transmit buffer to empty before sending the next character.  You need to test the associated TDRE flag, and wait until it becomes set, prior to sending the next character.  You do not mention the baud rate you are using, but I would assume it could be relatively slow.  At 9600 bits per second each character will take slightly more than 1 millisecond to send.

Regards,
Mac

 

Message Edited by bigmac on 2006-06-21 01:52 AM

0 Kudos
Reply