read/write string from/to the sci in MC9S08AW60 MCU

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

read/write string from/to the sci in MC9S08AW60 MCU

7,833 Views
SHUSH
Contributor I
Hello,
 
I have a problem, I success to write or read one char from or to the SCI in the MCU, but I could not succeeded to read or write a sting.
When I debug the problem I notice that the SCID register did not cleared after sending or reading the SCID register and I think that this is the main problem, how do I clear the SCID register that it can get net char after char ?
 
Thanks ,
 
shai
Labels (1)
0 Kudos
Reply
11 Replies

1,262 Views
peg
Senior Contributor IV

Hi SHUSH,

The SCID is never really clear, if you read it it will have the recently recieved byte in it. If you write to it the byte will be sent (assuming you have everything setup which you have if you can send 1 byte)

To transmit a string write to the SCID one byte at a time waiting for the TDRE bit of SCIxS1 register to be set before each byte.

To recieve a string read SCID everytime you read RDRF in SCIxS1 as a 1.

Simple as that!

Regards David

 

0 Kudos
Reply

1,262 Views
SHUSH
Contributor I
Hi Peg,
 
First thank a lot for your help.
 
About the reading proccess, I made what you said about sampling the RDRF flag but I not getting any new char after the first char reading? 
Is still you think that I doing somthing wrong ?
Do you have another suggest for that problem ?
 
Thanks,
 
Shai 
0 Kudos
Reply

1,263 Views
bigmac
Specialist III

Hello Shai,

After receiving each SCI character, you need to clear the the RDRF flag ready for the next character - I suspect that this may not be occurring for some reason.  It would help if you could post your SCI receive code.

Regards,
Mac

 

0 Kudos
Reply

1,263 Views
SHUSH
Contributor I
Hi Mac,
 
Thanks for your help I need it.
 
Here is my part of the CODE that take care in the RS232 read/write process :
 
Code:
/*** ===================================================================**     Interrupt handler : isrVsci1rx****     Description :**         User interrupt service routine. **     Parameters  : None**     Returns     : Nothing** ===================================================================*/__interrupt void isrVsci1rx(void){  int i=0,j=0;  //DisableInterrupts;  command_in[i]=SCI1D;      //READ the first char in the string   //for (j=0;j<1000;j++){}; //delay    /* READ the other chars in the string chain */  while (SCI1S1_RDRF==TRUE){      command_in[i]=SCI1D;      ++i;      //for (j=0;j<500;j++){}; //delay  }  /* ***************************************** */    /* put in the end of the string "/r/n" to recognize end of string */  ++i;  command_in[i]='/';  ++i;  command_in[i]='r';  ++i;  command_in[i]='/';  ++i;  command_in[i]='n';  /* *************************************************************** */    /* this part is for checking WRITE the string that READ before */  i=0;  while (command_in[i]!='/'&&command_in[i+1]!='r'&&command_in[i+2]!='/'&&command_in[i+3]!='n'){           a_last1=command_in[i];           AS1_SendChar(a_last1);           //for (j=0;j<500;j++){}; //delay           ++i;  }  //EnableInterrupts; }/* end of isrVsci1rx */This code is using the AS1_SendChar procedure , here is the code of that procedure :byte AS1_SendChar(AS1_TComData Chr){  if(!SCI1S1_TDRE)                     /* Is the transmitter empty— */    return ERR_TXFULL;                 /* If no then error */  SCI1D = (byte)Chr;  return ERR_OK;                       /* OK */}

 
Waiting for your replay ,
 
Thanks again,
 
Shai

Message Edited by Alban on 2006-08-21 12:35 PM

0 Kudos
Reply

1,263 Views
bigmac
Specialist III
Hello Shai,
 
When you first enter the ISR the RDRF flag is not cleared because you do not read the SCI1S1 register prior to reading the SCI1D register. 
 
However, there are also other issues -
  1. It is normal practice to process only a single receive byte at a time within the ISR.  Otherwise, you need not bother to use the interrupt, and adopt simple polling.  You would also need to allocate another global variable as a pointer or index to the current input buffer position.
  2. I suspect you are trying to implement a line buffer for the entry of command characters, but you do not test for the termination of the command, usually a CR control character.  At this point you would need to set a global flag to indicate to main() that the buffer data is ready for further processing.
  3. I presume you require to echo the characters received, but this would need to be done on a character-by-character basis, as each character is received.
  4. In addition to the CR character, you would need to decide what other control characters you need to process, and ignore all other control characters.  For a manual entry process you might consider the backspace character to allow simple editing.

Regards,
Mac

 

Message Edited by bigmac on 2006-08-26 06:20 AM

0 Kudos
Reply

1,263 Views
peg
Senior Contributor IV

Hi SHUSH,

You have gone about this quite incorrectly.

The way you have written it would be roughly correct if you were not using interrupts.

If you use interrupts you should be simply reading SCI1S1 first and then copying SCID into your buffer then exit. Do the rest of the housekeeping in the background.

Also finding the transmit buffer not empty is not an error, it just means you have to wait. The data dribbles out of the serial port much slower than you can throw the data at it!

Regards David

 

0 Kudos
Reply

1,263 Views
admin
Specialist II

SHUSH,

This serial driver app note was written for a different micro, but you can directly use 99% and just modify it for the -AW's registers.  It works great.

-Tomahawk

0 Kudos
Reply

1,263 Views
SHUSH
Contributor I
Hi All,
 
Thanks for your help but I am still have the problem.
 
I notice that when I have the first call to the the receive interrupt not only the the RDRF flag is in "1" state but also OR flag is in "1" state that means all the other chars (except the fist char) is lost.
Probably this is my problem that I can not succeeded to read a string as char by char.
Do anyone know how to deal with that situation ?
 
Thanks,
 
Shai
 
 
0 Kudos
Reply

1,263 Views
peg
Senior Contributor IV

Hi Shai,

Unless you have a very, very poorly written interrupt handler this can't really happen. Even at the fastest baudrate possible with your clock rate you should be able to store a string away to a buffer successfully.

You have one byte time to process each byte before overrun occurs.

Perhaps you can post your ISR?

Are you correctly resetting the interrupt flag?

Regards David

 

0 Kudos
Reply

1,263 Views
SHUSH
Contributor I

Hi Peg,

I absolutely agree with you that somthing is wrong here but I do not succeeded to understand what .

My interrupt code is written in my old massages, please can you check it and see if there any problem.

To tell you the true I don't think that its related to my code, because the OR flag set to "1" already when I "call" the read interrupt routine and the OR flag is automatic set (if I not mistake).

It's like the MCU not react like I expect from it. I have read the datasheet and I do not understand why the MCU react like this.

Can you guide me in this situation ? maybe it somthing in the RS232 configuration that I done incorrect ?

Thanks,

Shai

0 Kudos
Reply

1,263 Views
peg
Senior Contributor IV

Hi Shai,

OK, after my comments about the supplied code I was assuming you would have rewritten it.

How do you know OR is set? Its not checked there!

Unfortunately I can't afford the time to assist you any further at the moment and I am soon travelling.

Hopefully someone else can pick this up for you.

Regards David

 

 

0 Kudos
Reply