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
Problem in using SCI...send a string
Started by ●January 22, 2009
Reply by ●January 22, 20092009-01-22
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 = 0x0c;" to switch on TE and
RE bits of CR2. Maybe you have to check your value OnOff ? For me, RX and TX
are not defined in my compiler (ICC12).
What is the '/' in
> while ( !(SCI0SR1 & 0x80) ); /
> SCI0DRL = *strPut++;
I suppose it's an error when you typed your mail ?
I hope this will help you...
Joel Petrique
> -----Message d'origine-----
> De: 6... [mailto:6...] De la part de
> f...@yahoo.com
> Envoy jeudi 22 janvier 2009 14:04
> : 6...
> Objet: [68HC12] Problem in using SCI...send a string
>
> 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
>
>
>
>
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 = 0x0c;" to switch on TE and
RE bits of CR2. Maybe you have to check your value OnOff ? For me, RX and TX
are not defined in my compiler (ICC12).
What is the '/' in
> while ( !(SCI0SR1 & 0x80) ); /
> SCI0DRL = *strPut++;
I suppose it's an error when you typed your mail ?
I hope this will help you...
Joel Petrique
> -----Message d'origine-----
> De: 6... [mailto:6...] De la part de
> f...@yahoo.com
> Envoy jeudi 22 janvier 2009 14:04
> : 6...
> Objet: [68HC12] Problem in using SCI...send a string
>
> 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
>
>
>
>
Reply by ●January 22, 20092009-01-22
Hello,
>What is the '/' in
>> while ( !(SCI0SR1 & 0x80) ); /
>> SCI0DRL = *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.
>What is the '/' in
>> while ( !(SCI0SR1 & 0x80) ); /
>> SCI0DRL = *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.
Reply by ●January 22, 20092009-01-22
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 character
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: 6... [mailto:6...] De la part de
> f...@yahoo.com
> Envoy jeudi 22 janvier 2009 16:32
> : 6...
> Objet: [68HC12] Re: Problem in using SCI...send a string
>
> 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.
>
>
>
>
>
>
>
>
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 character
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: 6... [mailto:6...] De la part de
> f...@yahoo.com
> Envoy jeudi 22 janvier 2009 16:32
> : 6...
> Objet: [68HC12] Re: Problem in using SCI...send a string
>
> 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.
>
>
>
>
>
>
>
>
Reply by ●January 22, 20092009-01-22
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.
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.
Reply by ●January 22, 20092009-01-22
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?
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?
Reply by ●January 23, 20092009-01-23
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?
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?
Reply by ●January 23, 20092009-01-23
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....
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....
Reply by ●January 24, 20092009-01-24
Reply by ●January 24, 20092009-01-24
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...
>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...