SCI port help - MC9S08QG8

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

SCI port help - MC9S08QG8

2,291 Views
Fraz
Contributor I
Hi im new to microcontrollers and im trying to use the SCI port on a S08QG8 its just a simple program to make sure i am transmitting data, im using the output of the micro connected to a Maxim232 chip and using hyperterminal to view the results.  Athough i cannot get any data to transmit what am i doing wrong? i suspect its something to do with the baud rate which im trying to set to 9600.  The 232 and hyperterminal setup is working fine as i have tested this with another device
 
my program ;
 
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "MC9S08QG8.h" /* include peripheral declarations */

void main(void){

          int i;
        PTBPE = 0x00;
        PTAPE = 0x00;     
        PTBDD = 0x00;
        PTADD = 0x00;
 
for(;; )
{
  __RESET_WATCHDOG(); /* feeds the dog */
 
  SCIBDH = 0;
  SCIBDL = 0x82;   /* 9600 baud */
  SCIC1 = 0x00; /* Normal mode, 8 bits,  no parity */
  SCIC2 = 0x0C; /* Enable transmitter and receiver, no interrupts */
/*********************************************************************/
/* send the character */
/*********************************************************************/
   
for (i=1; i<1000; i++) {       /* delay before/after sending each character */
    }
  
  SCID = 0x41;  /* Send the letter A */
  while ((SCIS1 & 0x80) == 0);   /* Wait for TDRE */
 
} /* loop forever */
}
 
 
 
cheers



Message Edited by Fraz on 2008-01-26 02:08 PM

 

Added part number to subject.



Message Edited by NLFSJ on 2008-01-27 10:27 AM
Labels (1)
0 Kudos
Reply
5 Replies

664 Views
erooll
Contributor II
Could you tell us, configuration your clock settings.

- are you using a external crystal, or internal clock generator?, What is the value of this?
- How do you are sure that your CPU runs at 20 MHz?

Regards
0 Kudos
Reply

664 Views
Fraz
Contributor I
Yeh i was assuming a clock speed of 20 Mhz thats what the data sheet said the bus speed for Hs08 was.  How do i configure the SCI clock speed is it automatically the same as the processors bus speed? the only registers i can see are baud rate, control, status and data ?
cheers
0 Kudos
Reply

664 Views
JimDon
Senior Contributor III
How about I teach you to fish instead of just giving you fish.

First of all, down load the datasheet, and at least read the overview.
Next, if you haven't done so all ready download and install CW for Microcontrollers 6.1.

Then create a dummy project using processor expert. Under the CPU bean you will find a page that will let you configure the clock. What I do is generate PE code, then look up the registers in the spec sheet to understand how it all works. I then write the code in my project. You could just generate your whole project with PE if you like, but I don't care for the way PE does it. However it is a GREAT tool, and for all the freescale processors I use, I don't have get a headache to do things.
Do not just turn on PE in your project - its all or nothing. Make a sample project and add the code you need.

Somewhere there is a PE manual, but  I just click around in the UI until I find what I need.

If you don't have a BDM grab a DEMO9S08QG8  for 50.00. Add a 6 pin header and a 6 pin IDE, pull out the a chip and you have a full P&E BDM - which works with HCS12 and CF V! too.

0 Kudos
Reply

664 Views
peg
Senior Contributor IV
Hi Fraz,

The code attached to this post may help you.
For one it will give you some working serial code to test and also you have the source to see how it is all done.

0 Kudos
Reply

664 Views
JimDon
Senior Contributor III
What about the CPU clock set up?
Your tx code looks ok, but the baud rate depends on how you set up the clock.
since
baudrate = BCLK/16/REGVAL
or
BCLK = 16* BR * REGVAL
19,968,000       = 16 * 9600 * 130d
So a value of 0x82 (130d) says you have a bus clock of like 20 MHz, or an ECLK of 40 Mhz.
(Max is 20 MHz for ECLK)
Maybe  you have an ECLK of 20 Mhz, and missed that it is divided by 2. Try half that. 0x41.
0 Kudos
Reply