Re: Serial communication of ATMega128



On Jan 31, 7:49 am, "sindhu" <scinthia_...@xxxxxxxxxxxxxx> wrote:
Hi all,
Iam working on Atmega128 and STK500.Iam new to this.
I need to transmit a character from controller.I have given the code
below.

#include"iom128v.h"
#include "io.h"

unsigned char data;
unsigned int baud;
unsigned int i;
int transmit(unsigned char);

void USART0_Init( unsigned int baud)
{
UBRR0H=0x96;
UBRR0L=0x00;
UCSR0B=0x08;
UCSR0C=0x06;}

int transmit(unsigned char data)
{
PORTA=0x41;
DDRA=0xFF;
loop_until_bit_is_set(UCSR0A,UDRE);
UDR0=data;
return 0;}

int main(void)
{
SREG=0x80;
SPL=0x61;
SPH=0x00;
USART0_Init(9600);
transmit('A');
return 0;}

This code is working.PORTA outputs 41.Hyperterminal is not showing
character A.
Can anyone point out the mistake?

Bye.


Looks like your baud rate is programmed to the wrong value. UBBR0H
should be the most significant byte of the divisor, and UBRR0L the
least significant byte.

For example, if your CPU clock is 4 MHz, and your baudrate 9600, the
divisor should be 4000000 / 16 / 9600 = 26.04, subtract one and round
to get 25. Program 0 (MSB) into UBRR0H, and 25 (LSB) into UBRR0L.

I always use something like this (with FCLK defined to be CPU clock):

int ubrr = (FCLK / baud + 8) / 16 - 1;

UBRR0H = (ubrr > 8);
UBRR0L = ubrr;

.



Relevant Pages

  • Re: Serial communication of ATMega128
    ... I need to transmit a character from controller.I have given the code ... unsigned int baud; ... void USART0_Init(unsigned int baud) ... int transmit(unsigned char data) ...
    (comp.arch.embedded)
  • Serial communication of ATMega128
    ... I need to transmit a character from controller.I have given the code ... unsigned int baud; ... void USART0_Init(unsigned int baud) ... int transmit(unsigned char data) ...
    (comp.arch.embedded)
  • Re: scanf pushes back two chars?
    ... > unsigned int i; ... The subject sequence is defined as the longest initial subsequence ... character, that is of the expected form. ... The longest subsequence of the expected form is '0', ...
    (comp.lang.c)
  • [PATCH] Add support for non-standard XTALs to 16c950 driver
    ... prescaler for division by 7, and DLAB to 1, to get 115200Bd. ... To get card properly running you also have to add lines below to ... -static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud) ...
    (Linux-Kernel)
  • Re: detab utility challenge.
    ... on the clc wiki, which does character ... Possibly (though you could use unsigned int, ... Oh horror of horrors!) ...
    (comp.lang.c)