UART 1 & 2

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

UART 1 & 2

7,491 Views
billp
Contributor I
I am using MC9S08GB with a MC1321xRM.  I have the units sending and receiving data using the radio.  After the data is received, I peel out some ot the data and send it on UART 2 to another unit.  I have check the data being sent on the UART 2 and it is good.  When I monitor the unit recieving the data on UART 2 all I get is 0, -1, -2.  Any examples or advice on why I can't read the data on UART 2.  Both devices are in Master Mode and the data sends great on the UART.  Both UART's are set at 38400 baud, 8, 1, no parity and I switch TX/RX for null modem.
Labels (1)
0 Kudos
11 Replies

847 Views
billp
Contributor I
I used the settings that I have listed above and to read the ports with my RS232 reader, it is set at 38400.  The application using the data is set at 38400 and it is displaying the data.
0 Kudos

847 Views
peg
Senior Contributor IV

While we are talking about the clock...

Are you using the internal clock and if so is it trimmed?

David

 

0 Kudos

847 Views
peg
Senior Contributor IV

Still confused, you are showing intialisation for UART 1 & 2 , surely we only need to worry about 1 SCI on each device?

Device A uses which one? and B?

Both initialisations only enable the transmitter and not the reciever!

to send data you usually monitor TDRE and to receive it, RDRF.

David

 

0 Kudos

847 Views
Jim_P
Contributor III
are you sure the baud rates are correct - - as baud rate settings are clock speed dependent?

Jim P.
0 Kudos

847 Views
billp
Contributor I

I also tried to use the following to wait for data :

while (SCI2S1_RDRF!=0) {

};

Again, the RDRF was never set to 1 so I didn't get out of the loop.  Yes, you are right, if I hook up GB 'A'  to the RS232 reader, it is tranmitting fine.  Then I hook it to GB 'B', reversing TX/RX to read the UART and I can't seem to read it.

 

0 Kudos

847 Views
billp
Contributor I
I got the while wrong, it's the following:
 
while (SCI2S1_RDRF==0) {
};
 
Also, I tried,
while (SCI2S1_RDRF!=1) {
};
 
0 Kudos

847 Views
billp
Contributor I
I tried to use the following code to wait for the data to be sent to UART 2:
  while (SCI2S2_RAF!=1) {
  };
but RAF never gets set...  So I never get out of the while loop.
0 Kudos

847 Views
billp
Contributor I

Yes, that is my problem.  I initialized my UART with the following:

void UART1(void) {
  // Setting is for 38400 baud
  SCI1BDH = 0x00;
  SCI1BDL = BAUD_38400;
  SCI1C1 = 0x00;
  SCI1C2 = 0x18;
  SCI1C3 = 0x00;
}

void UART2(void) {
  // Setting is for 38400 baud
  SCI2BDH = 0x00;
  SCI2BDL = BAUD_38400;
  SCI2C1 = 0x00;
  SCI2C2 = 0x18;
  SCI2C3 = 0x00;
}

I want to poll for the input data.  I guess I really need an example of waiting for the data to be received, then getting the data and clearing the registers.

0 Kudos

847 Views
billp
Contributor I
The MC9S08GB is doing the sending and receiving on the UART 1 & 2. I use the SPI modules for the Radio. I have checked the data sending on the UART and it looks fine. I'm just sending about 7 bytes and trying to receive them. Can I put UART 2 in receive only mode and UART 1 in transmit only mode ? The data is kinda like the following:

byte start = 0xAA;
byte tmpid = 1;
byte tmpptr = 10;
byte tag = 5;
byte tag2 = 11;
byte itemnum = 36;
byte itemptr = 20;

When I transmit and hook up the rs232 listener I see:
-89 1 10 5 11 36 20
Then I hook the other CPU in and try to read the UART and send the data out the second UART and it looks like:
-1 -1 -1 -1 -1 -1
0 Kudos

847 Views
peg
Senior Contributor IV

Hi Bill,

I'm still a little confused as to what you are doing.

Presumably for analysis of the problem we can forget about the radios???

You have two GB's with their SCI ports connected together (crossed over). Yes?

If you tap into the serial connection you can see that "A" GB is sending the data correctly???

But it appears that "B" GB is not receiving this correctly. It just recieves -1's which presumably is FF???

Is this your problem?

Are you recieving the same amount of bytes that you send?

Have you tried different amount of bytes sent to confirm this?

If this is the case the problem would appear to be in your SCI recieve code.

Enough for now as I might be on the wrong track.

Regards David

 

0 Kudos

847 Views
mjcoury
Contributor I
What device is doing the recieving and what is the data supposed to look like?
0 Kudos