-1
\$\begingroup\$

I'm trying simple UART transaction functions for ATmega32. I can send the bytes but not receiving anything. I am using polled UART receive.

void UARTReadStr12(uint8_t *buffer) {

   uint16_t i = 0;

   for (i = 0; i < 12; i++) {
       while (!(UCSRA & (1 << RXC)));
       *(buffer + i) = UDR;
   }
}

and initialized as,

void UARTInit(uint16_t ubrr_value) {

//Set Baud rate
    UBRRL = ubrr_value;
    UBRRH = (ubrr_value >> 8);
    UCSRC = (1 << URSEL) | (3 << UCSZ0);
    UCSRB = (1 << RXEN) | (1 << TXEN);
}
\$\endgroup\$
  • 2
    \$\begingroup\$ Uhm well it is hard to tell sth from that, if you can send something from atmega then it looks like uart is working. You are sure that you send data to atmega with proper baud rate and proper data format ? \$\endgroup\$ – molok May 18 '16 at 17:36
1
\$\begingroup\$

From this we know enough to say that the problem can be anything, but the most common problem used to be the wrong clocking.

  1. Fresh atmega is running on 1MHz instead of 8, until you unset CKDIV8 fuse.
  2. Internal oscillator may drift more than the required accurancy (+-10%)
  3. You have crystal oscillator attached, but atmega is still running on internal oscillator (see 1,2)
  4. ubbr is not within +-2% accurancy: http://wormfood.net/avrbaudcalc.php
  5. ubbr is not a baud rate so you have calculate it first
\$\endgroup\$
  • \$\begingroup\$ I've checked the frequency and baud, both are correct. \$\endgroup\$ – Parth Parikh May 21 '16 at 11:16
  • \$\begingroup\$ Try also loopback test on the pc side. \$\endgroup\$ – jnk0le May 25 '16 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.