Problem on UART transmit

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

Problem on UART transmit

464 Views
rexzhou
Contributor I

Hi,

I am writing a code to use UART to transmit a certain character and display it on the PC with the MC13213-SRB board. It is kind of a simple code, however what I got from the PC are just junky code that were unreadable. The following is a general description of my codes:

 

first of all, I defined the SCI port I will use to communicate:

#define  SCID       SCI2D#define  SCIS1_TDRE  SCI2S1_TDRE#define  SCIS1_TC    SCI2S1_TC      

 Then in the main loop, the codes are:

void main(void) { MCUInit(); for (;;){  while (!SCIS1_TDRE);         SCID = 'f';         while (!SCIS1_TC); }

 In the MCU initialization part I define the control register for SCI and for the CPU clock to figure out the baurdrate:

void MCUInit(void){  SOPT = 0x72;                /* Turn off the watchdog. */    SPMSC1 = 0x1C;                                        SPMSC2 = 0x00;                                        ICGC1 = 0x44;                                        ICGC2 = 0x00;                                        /* Common initialization of the CPU registers */  /* PTASE: PTASE7=0,PTASE6=0,PTASE5=0,PTASE4=0,PTASE3=0,PTASE2=0,PTASE1=0,PTASE0=0 */  PTASE = 0x00;                                        /* PTBSE: PTBSE7=0,PTBSE6=0,PTBSE5=0,PTBSE4=0,PTBSE3=0,PTBSE2=0,PTBSE1=0,PTBSE0=0 */  PTBSE = 0x00;                                        /* PTCSE: PTCSE7=0,PTCSE6=0,PTCSE5=0,PTCSE4=0,PTCSE3=0,PTCSE2=0,PTCSE1=0,PTCSE0=0 */  PTCSE = 0x00;                                        /* PTDSE: PTDSE7=0,PTDSE6=0,PTDSE5=0,PTDSE4=0,PTDSE3=0,PTDSE2=0,PTDSE1=0,PTDSE0=0 */  PTDSE = 0x00;                                        /* PTESE: PTESE7=0,PTESE6=0,PTESE5=0,PTESE4=0,PTESE3=0,PTESE2=0,PTESE1=0,PTESE0=0 */  PTESE = 0x00;                                        /* PTFSE: PTFSE7=0,PTFSE6=0,PTFSE5=0,PTFSE4=0,PTFSE3=0,PTFSE2=0,PTFSE1=0,PTFSE0=0 */  PTFSE = 0x00;                                        /* PTGSE: PTGSE7=0,PTGSE6=0,PTGSE5=0,PTGSE4=0,PTGSE3=0,PTGSE2=0,PTGSE1=0,PTGSE0=0 */  PTGSE = 0x00;           /* ### Init_SCI init code */         SCI2BDH = 0x00;      SCI2BDL = 0x35;      SCI2C1 = 0x00;                                            SCI2C2 = 0x28;                                            SCI2C3 = 0x00;                                            asm CLI;                             /* Enable interrupts */}

 So with those codes | should get character 'f' repeatly displayed on my PC. I try to tune the transmit buardrate in SCIBDL, However I still got the unreadable code on my PC. Is this because  the code: SCID='f'; is wrong or because of the wrong initialization?

 

Thanks

Labels (1)
0 Kudos
1 Reply

270 Views
bigmac
Specialist III

Hello,

 

Your problem is likely to be lack of a sufficiently accurate baud rate.

 

I notice that your code initialises the ICG module for SCM (self clocked mode), which is also the power on default mode.  The ICGOUT frequency will lie somewhere within the range 5.5 - 10.5 MHz.  This will produce a bus frequency range of 2.75 - 5.25 MHz.

 

To produce a bus frequency of sufficient stability for the SCI module, you will need to change the ICG operation to FEI mode.  In addition, the internal reference oscillator needs to be accurately trimmed.  The register ICGTRM has a power on default setting of 0x80, and the reference frequency will have a wide unit-to-unit tolerance of +/-25 percent from the nominal value of 243kHz.  The ICGTRM setting needs to be adjusted to within say +/-2 percent.

 

The non-volatile trim setting is normally stored at flash address 0xFFBE, and needs to be transferred to ICGTRM register during initialisation.  However, if this flash location has been erased during the programming of the code, the trim value will need to be recalibrated, and stored in flash.  This can be done by the Multilink interface.

 

For a trimmed internal reference frequency of 243kHz, it is possible to achieve one of the following bus frequencies (not including possible bus frequencies less than 5 MHz) -

5.5543 MHz

6.6651

7.7760

8.8869

9.9977

11.109

13.330

15.552

17.774

19.995

 

For example, with a bus frequency of 9.9977 MHz and a baud rate of 9600 bit per second, the SCIBD value would need to be 65 decimal.  Some bus frequencies will produce more accurate baud rate than other bus frequencies.

 

Regards,

Mac

0 Kudos