UART initialization

cancel
Showing results for 
Search instead for 
Did you mean: 

UART initialization

3,010 Views
crt
Contributor I
Hi,
with my friends we are doing school project. One part of this project requires UART initialization. This is first time we are using such processor(CF5282), until now we were only using M68HC11. Problem is that we can't get UART to work at all. I think we set correctly everything, but on PC we don't receive anything. Our setting are 9600bps, 8bits per char, 1 stop bit, no parity. Can somebody tell us what did we wrong?
 
Thanks in advance, Crt Gorup
 
 
Code:
.EQU    TERM_BUF,     0x4000020C    /* buffer register */.EQU    TERM_CMD,     0x40000208    /* command register */.EQU    TERM_IRQ,     0x40000214    /* interrupt enable/disable register */.EQU    TERM_CLK,     0x40000204    /* clock select register */.EQU    TERM_UBG1N,   0x40000218    /* clock divider upper register */.EQU    TERM_UBG2N,   0x4000021C    /* clock divider lower register */.EQU    TERM_UMR1,    0x40000200    /* parity, bits per char */.EQU    TERM_UMR2,    0x40000204    /* stop bit length, RTS */.EQU    TERM_ENB,     0x01    /* enable interrupt */.EQU    TERM_DIS,     0x00    /* disable interrupt */  MOVE.B  #0x3A, %D0       /* reset transmiter, disable transmiter and */  MOVE.B  %D0, TERM_CMD    /* disable reciever                         */  MOVE.B  #0x6, %D0        /* enable reciever */  MOVE.B  %D0, TERM_CMD  MOVE.B  #0x00, %D0       /* set clock divider upper register */  MOVE.B  %D0, TERM_UBG1N  MOVE.B  #0xD6, %D0       /* set clock lower upper register */  MOVE.B  %D0, TERM_UBG2N  MOVE.B  #0xDD, %D0       /* select system prescaled clock */  MOVE.B  %D0, TERM_CLK    MOVE.B  #0x13, %D0      /* parity none, 8 bits per character */      MOVE.B  %D0, TERM_UMR1    MOVE.B  #0x07, %D0      /* stop bit length = 1.0, RTS disabled */  MOVE.B  %D0, TERM_UMR2                         
   /* sending character */  MOVE.B  #TERM_ENB,%D0       /* enable interrupts */  MOVE.B  %D0,TERM_IRQ    MOVE.B  #STRING, %D0        /* put char into buffer */  MOVE.B  %D0, TERM_BUF    MOVE.B  #TERM_DIS,%D0       /* disable interrupts */  MOVE.B  %D0,TERM_IRQ

 
 
 
Labels (1)
0 Kudos
4 Replies

241 Views
SimonMarsden_de
Contributor II
Hi

I haven't checked your code, but I have another suggestion. Have you checked that you've set up the UART pins correctly in the GPIO module? Without this, everything might be working fine in the UART code but the signals never make it to the outside world.

On the MCF5282, there are more possible I/O signals than there are physical pins to accomodate them all. To handle this, it's necessary to pick from a list of different functions assigned to a pin, and then select this using the pin multiplexing feature.

To do this, you typically need to set up the PAR register which applies to the pins you want to configure. For UART 0, the signals Tx and Rx are part of GPIO port UA, and so configured with the PUAPAR register. You would need to do something like:

MCF5282_GPIO_PUAPAR = 0xf;

Hope this helps, and good luck with the project.


Simon
0 Kudos

241 Views
crt
Contributor I
Hi,
thanks for information about that register. My code is working at the moment, but something is very strange with baud rate. There are 3 registers for setting baudrate. With UCSR1 we can choose between external clock or prescaled(divider 32) system clock. In second case we have to set additional 16 bit divider(registers UBG21 and UBG11). I have used formula from manuals, that means divider=SYSCLOCK/(32*baudrate). I belive(Is there any other frequency possible?) that my CF5282 on development board works on 66Mhz. In my case I need baud rate 9600 bps, so I had to set divider registers to 0x00 and 0xD6. Problem is that UART transfer between CF and PC doesn't work at 9600 bps. There are some strange characters appearing. The most interesting thing is that when I change baudrate on PC to 4800 bps it looks like that transfer works. Can anybody explain this?
 
Thanks in advance,
 
Crt
 
Code:
.EQU    UMR11,        0x40000200    /* parity, bits per char, reset */.EQU    UMR21,        0x40000200    /* stop bit length, RTS         */.EQU    UCSR1,        0x40000204    /* uart clock select register   */.EQU    UCR1,         0x40000208    /* uart command register        */ .EQU    UTB1,         0x4000020C    /* uart transmit buffer         */.EQU    UBG1N,        0x40000218    /* clock divider upper register */.EQU    UBG2N,        0x4000021C    /* clock divider lower register */.EQU    PUAPAR,       0x4010005C    /* port function register       */MOVE.B  #0x10, %D0       /* reset mode register pointer */MOVE.B  %D0, UCR1  MOVE.B  #0x13, %D0       /* parity none, 8 bits per character */    MOVE.B  %D0, UMR11  MOVE.B  #0x07, %D0       /* stop bit length = 1.0 */MOVE.B  %D0, UMR21  MOVE.B  #0x30, %D0       /* reset TX */MOVE.B  %D0, UCR1MOVE.B  #0x00, %D0       /* set clock divider msb register */MOVE.B  %D0, UBG1NMOVE.B  #0x6B, %D0       /* set clock lower lsb register */MOVE.B  %D0, UBG2NMOVE.B  #0xDD, %D0       /* select system prescaled clock */MOVE.B  %D0, UCSR1 MOVE.B  #0xFF, %D0       /* pins are set to UART pins */MOVE.B  %D0, PUAPARMOVE.B  #0x4,%D0       /* enable TX */MOVE.B  %D0,UCR1  MOVE.B  %D2, UTB1      /* send char */    MOVE.B  #0x8,%D0       /* disable TX */MOVE.B  %D0,UCR1

 P.S.: Which was is better? Enabling and disabling TX for every character or keep it enabled until all characters are send?
0 Kudos

241 Views
Petter
Contributor II
I'm not familar with the 5282, but on the 52235 I had to init the PLL in order for the UART to operate properly. I had problems similar to yours before doing this:

MCF_CLOCK_SYNCR = MCF_CLOCK_SYNCR_MFD(4) | MCF_CLOCK_SYNCR_CLKSRC| MCF_CLOCK_SYNCR_PLLMODE | MCF_CLOCK_SYNCR_PLLEN ;

while (!(MCF_CLOCK_SYNSR & MCF_CLOCK_SYNSR_LOCK)) {
}
0 Kudos

241 Views
ColdFireHot
Contributor I
crt,
  You may want to try D0 for your divisor.  The PLL is probably running at 64MHz not 66MHz.
 
Mark
0 Kudos