Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
Problem in using SCI...send a string - folg...@yahoo.com - Jan 22 8:04:08 2009
Hello,
I have a problem with using SCI interface. I am able to send one character but sending a
string does not work. Perhaps anyone can tell me what is wrong.
void InitSCI0(void)
{
SCI0BDH= 0x00; // SCI Baud Rate Registers (SCIBDH and SCIBDL)
// calculating the baud rate is: SCI baud rate = SCI
// module clock / (16 x BR)
SCI0BDL= 26; // SCI Baud Rate Registers (SCIBDH and SCHBDL)
// Bit 7 6 5 4 3 2 1 0
// SBR7 SBR6 SBR5 SBR4 SBR3 SBR2 SBR1 SBR0
// 26 -> 19200 Baudrate at Bus Clock 8MHz
SCI0CR1= 0x00; // SCI Control Register 1 (SCICR1); 8N1
SCI0CR2= 0x00; // SCI Control Register 2 (SCICR2)
}/* void InitSCI0(void) */
void SetSCI0(char OnOff)
{
SCI0CR2= OnOff; // SCI Control Register 2 (SCICR2)
}/* void SetSCI0(char OnOff) */
void PutcharSCI0(unsigned char cPut)
{
while( !(SCI0SR1 & 0x80) );
SCI0DRL= cPut;
}/* void PutcharSCI0(unsigned char cPut) */
void PutStSCI0(unsigned char *strPut)
{
while (*strPut != 0)
{
while ( !(SCI0SR1 & 0x80) ); /
SCI0DRL = *strPut++;
}
}/* void PutcharSCI0(unsigned char cPut) */
InitSCI0();
SetSCI0(RX|TX);
PutcharSCI0(\'3\'); <- That works, sending one character
PutStSCI0(\"Send Text\"); <- That does not work
Best Regards
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
RE: Problem in using SCI...send a string - jpdi - Jan 22 9:52:36 2009
Hello,
Sometimes, I use polling technique too (transmission at high baudrate)
About your init :
SCI0BDH and SCI0BDL for init baudrate seems ok to me
What about RX and TX ? For me, I write "SCI0CR2 =3D 0x0c;" to switch on TE =
and
RE bits of CR2. Maybe you have to check your value OnOff ? For me, RX and T=
X
are not defined in my compiler (ICC12).
What is the '/' in=20
> while ( !(SCI0SR1 & 0x80) ); /
> SCI0DRL =3D *strPut++;
I suppose it's an error when you typed your mail ?
I hope this will help you...
Joel Petrique
> -----Message d'origine-----
> De=A0: 6...@yahoogroups.com [mailto:6...@yahoogroups.com] De la part =
de
> f...@yahoo.com
> Envoy=E9=A0: jeudi 22 janvier 2009 14:04
> =C0=A0: 6...@yahoogroups.com
> Objet=A0: [68HC12] Problem in using SCI...send a string
>=20
> Hello,
>=20
> I have a problem with using SCI interface. I am able to send one characte=
r
> but sending a string does not work. Perhaps anyone can tell me what is
> wrong.
>=20
> void InitSCI0(void)
> {
> SCI0BDH=3D 0x00; // SCI Baud Rate Registers (SCIBDH and SCIBDL)
> // calculating the baud rate is: SCI baud rate =3D SC=
I
> // module clock / (16 x BR)
>=20
> SCI0BDL=3D 26; // SCI Baud Rate Registers (SCIBDH and SCHBDL)
> // Bit 7 6 5 4 3 2 1 0
> // SBR7 SBR6 SBR5 SBR4 SBR3 SBR2 SBR1 SBR0
> // 26 -> 19200 Baudrate at Bus Clock 8MHz
> SCI0CR1=3D 0x00; // SCI Control Register 1 (SCICR1); 8N1
> SCI0CR2=3D 0x00; // SCI Control Register 2 (SCICR2)
> }/* void InitSCI0(void) */
>=20
> void SetSCI0(char OnOff)
> {
> SCI0CR2=3D OnOff; // SCI Control Register 2 (SCICR2)
> }/* void SetSCI0(char OnOff) */
>=20
> void PutcharSCI0(unsigned char cPut)
> {
> while( !(SCI0SR1 & 0x80) );
> SCI0DRL=3D cPut;
> }/* void PutcharSCI0(unsigned char cPut) */
>=20
> void PutStSCI0(unsigned char *strPut)
> {
> while (*strPut !=3D 0)
> {
> while ( !(SCI0SR1 & 0x80) ); /
> SCI0DRL =3D *strPut++;
> }
> }/* void PutcharSCI0(unsigned char cPut) */
>=20
> InitSCI0();
> SetSCI0(RX|TX);
> PutcharSCI0(\'3\'); <- That works, sending one character
> PutStSCI0(\"Send Text\"); <- That does not work
>=20
> Best Regards
>=20
> ------------------------------------
>=20
>
______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.
(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Problem in using SCI...send a string - folg...@yahoo.com - Jan 22 10:32:05 2009
Hello,
>What is the '/' in
>> while ( !(SCI0SR1 & 0x80) ); /
>> SCI0DRL =3D *strPut++;
>I suppose it's an error when you typed your mail ?
Yes!
TX and RX are defined like this:
#define TX 0x08
#define RX 0x04
#define RIE 0x20
Using:
void PutcharSCI0(unsigned char cPut)
{
while( !(SCI0SR1 & 0x80) );
SCI0DRL= cPut;
}/* void PutcharSCI0(unsigned char cPut) */
AND
PutcharSCI0('8');
works. The PC (Hyperterminal) receives the 8. If I want to send a string
PutStSCI0("Send Text");
void PutStSCI0(unsigned char *strPut)
{
while ( (*strPut) != '\0' )
{
PutcharSCI0(*strPut++);
}
}/* void PutcharSCI0(unsigned char cPut) */
It does not work. It stops here:
while( !(SCI0SR1 & 0x80) );
SCI0SR1 & 0x80 seems to be always 0.
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
RE: Re: Problem in using SCI...send a string - jpdi - Jan 22 11:02:36 2009
How...
I think I had that problem of SCI locked...
I don't use Hyperterminal, just scope to see if I transmit.
When I had this problem, it seems SCI received character, and this characte=
r
was not read. Do you know if Hyperterminal send characters (echo function) =
?
If you don't use handshake, and have an oscilloscope, try to disconnect
Hyperterminal and see what you have on your output.
Or slow down your baudrate, and put a led + resistor...
Joel Petrique
> -----Message d'origine-----
> De=A0: 6...@yahoogroups.com [mailto:6...@yahoogroups.com] De la part =
de
> f...@yahoo.com
> Envoy=E9=A0: jeudi 22 janvier 2009 16:32
> =C0=A0: 6...@yahoogroups.com
> Objet=A0: [68HC12] Re: Problem in using SCI...send a string
>=20
> Hello,
>=20
> >What is the '/' in
> >> while ( !(SCI0SR1 & 0x80) ); /
> >> SCI0DRL =3D3D *strPut++;
> >I suppose it's an error when you typed your mail ?
>=20
> Yes!
>=20
> TX and RX are defined like this:
>=20
> #define TX 0x08
> #define RX 0x04
> #define RIE 0x20
>=20
> Using:
>=20
> void PutcharSCI0(unsigned char cPut)
> {
> while( !(SCI0SR1 & 0x80) );
> SCI0DRL=3D cPut;
> }/* void PutcharSCI0(unsigned char cPut) */
>=20
> AND
>=20
> PutcharSCI0('8');
>=20
> works. The PC (Hyperterminal) receives the 8. If I want to send a string
>=20
> PutStSCI0("Send Text");
>=20
> void PutStSCI0(unsigned char *strPut)
> {
> while ( (*strPut) !=3D '\0' )
> {
> PutcharSCI0(*strPut++);
> }
>=20
> }/* void PutcharSCI0(unsigned char cPut) */
>=20
> It does not work. It stops here:
>=20
> while( !(SCI0SR1 & 0x80) );
>=20
> SCI0SR1 & 0x80 seems to be always 0.
>=20
>=20
>=20
>=20
>=20
> ------------------------------------
>=20
>

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Problem in using SCI...send a string - folg...@yahoo.com - Jan 22 11:58:18 2009
Hello,
I tried another terminal programm and it is the same, I think there is no echo function in
hyperterminal and nothing is received by the controller.
I tried the following:
PutcharSCI0('A');
PutcharSCI0('B');
That does not work. It is the same result like PutStSCI0("AB");
It is only possible to send one character: PutcharSCI0('A'); That works and the A is
received.
------------------------------------
______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.
(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Problem in using SCI...send a string - folg...@yahoo.com - Jan 22 15:35:38 2009
Hello,
I think that there is something wrong with the SCI Status Register 1 (SCISR1).
"Clear TDRE by reading SCI status register 1 (SCISR1), with TDRE set and then writing to
SCI data
register low (SCIDRL)"
I do this:
while( !(SCI0SR1 & 0x80) );
SCI0DRL= cPut;
but if I want to send a string the programm stops at the while loop.TDRE seems to be
always 0.
Has anybody an example about SCI with or without SCI to test?
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Re: Problem in using SCI...send a string - Rob Milne - Jan 23 11:36:14 2009
The following works fine for me if I only need a synchronous solution.
Using an interrupt driven routine gives much better performance wrt
concurrency.
#ifndef bit
#define bit(x) (1 << (x))
#endif
void put_char(char c) {
while((SCI0SR1 & bit(7)) == 0);
SCI0DRL = c;
}
void put_s(char* str) {
while(*str)
put_char(*str++);
}
> Has anybody an example about SCI with or without SCI to test?
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Problem in using SCI...send a string - folg...@yahoo.com - Jan 23 13:31:01 2009
Hello,
thank you but it is the same. It is possible to send one character put_s("T"); but it is
not possible to send a string put_s("Text");
It always stopps here: while((SCI0SR1 & 0x80) == 0);
I do not know. There really seems to be something wrong with the flags....
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Re: Problem in using SCI...send a string - Rob Milne - Jan 24 9:56:53 2009
Have you enabled the TE and RE bits in SCI0CR2?
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Problem in using SCI...send a string - folg...@yahoo.com - Jan 24 11:34:59 2009
Hello,
>Have you enabled the TE and RE bits in SCI0CR2?
Yes by using this function:
#define TX 0x08
#define RX 0x04
SetSCI0(RX|TX);
void SetSCI0(char OnOff)
{
SCI0CR2= OnOff; // SCI Control Register 2 (SCICR2)
}
I am able to send one character. I thing setting TE and RE is not the problem. I thing
something is destroying the status flags but what and why...
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )