SCI: LF works, but not CR

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SCI: LF works, but not CR

ソリューションへジャンプ
1,121件の閲覧回数
irob
Contributor V

I have a strange bug that I'm unable to figure out yet.  I have a set of serial debugger functions that I want to use with my JS16 target.  So far so good, but my transmit function (TxString) behaves strangely.

 

In particular, I can't seem to get a carriage return code (0x0D) to register.  I'm using Realterm, in ASCII mode to see the LF and CR characters represented on the terminal.

 

Here's my code:

 

/********************************************************************
 * TxString():        send string of characters as ASCII via SCI
 *
 * Parameters:        pointer s, new line option
 * Entry Conditions:  None.
 * Exit Conditions:   None.
 * Return:            None.
 * Remarks:           no limit on input number of characters,
 *                    option for outputting newline escape characters
 *                    after conclusion of string
 ********************************************************************/

void TxString(byte* string,byte newline){  word time = 0xFF00;    do  {    __RESET_WATCHDOG(); // feeds the dog    while(!SCIS1_TDRE)    {      __RESET_WATCHDOG(); // feeds the dog    }    SCID = *string;  } while (*++string != 0);  if (newline == TRUE)  {    SCID = CR; // send carriage return <--- this line doesn't do anything in Realterm    SCID = LF; // send line feed  }  while(!SCIS1_TC)  {    __RESET_WATCHDOG(); // feeds the dog  }} // end TxString()

The macros "CR" and "LF" equate to 0x0d and 0x0a.  The CR line doesn't seem to send anything, but LF does.  It's as if the CR is being swallowed.

 

Curiously, if I call TxString with embedded escape codes, then I can get repeatable CRs:

 

TxString("CRLF test here --->\r\n",0);

 Now why is that?  What's so special about the "\r"?!

ラベル(1)
0 件の賞賛
返信
1 解決策
708件の閲覧回数
bigmac
Specialist III

Hello,

 

When you send the string data, you are waiting for TDRE flag to become set before sending the next character.  However, you are not doing this when you separately send the control characters.

 

Regards,

Mac

 

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
709件の閲覧回数
bigmac
Specialist III

Hello,

 

When you send the string data, you are waiting for TDRE flag to become set before sending the next character.  However, you are not doing this when you separately send the control characters.

 

Regards,

Mac

 

0 件の賞賛
返信
708件の閲覧回数
irob
Contributor V

Huh, what do you know?  It was right in front of me the whole time.  Thanks, bigmac.

0 件の賞賛
返信