SCI: LF works, but not CR

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

SCI: LF works, but not CR

跳至解决方案
1,123 次查看
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 解答
710 次查看
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 回复数
711 次查看
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 项奖励
回复
710 次查看
irob
Contributor V

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

0 项奖励
回复