USB Default Baud Rate - No Bootloader

I want to use the Diecimila without the bootloader. After erasing the bootloader by writing a program into it using an AVR-ISP, I am unable to communicate with the board over the USB! Twidling pins and other functions work great. I guess I should have thought about this just a minute before uploading over the bootloader, eh? Anyway, I have been unsuccessful after many attempts at configuring the UART. I am writing rather simple programs using C and the WinAVR compiler. Can anyone help? :-?

What are you trying to communicate over USB?

Did you know you can write programs with the Arduino IDE and upload them with no bootloader using your ISP?

Can you post your code? What's on the computer side that's trying to talk to the Arduino?

Thank you for the replies. I am simply trying to transfer data in one direction at this point: to a terminal. That may show my ignorance on where the USB interface gets its information about the baud rate. After reading the replies, it occurs to me that perhaps I should be using the Serial Monitor.

The code is provided below. I am trying to figure out what baud rate I need to send a sentence to the terminal attached to USB Serial Port COM7. The Preferences file contains this line: serial.download_rate=19200. Still, what sets the USB baud rate and how can the Atmega168 know what that is?


#define F_CPU 16000000UL
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <stdio.h>
#include <util/delay.h>
#include “iocompat.h” /* Note [1] /
#define BAUD 9600
#define MYUBRR (F_CPU/(16
BAUD))-1

int main (void)
{
PORTB = 0x00; // pull-up unsed outputs (clear LED, RADIO and COMP)
DDRB = 0x3F; // set Port B to outputs (no PB6.7)
PORTC = 0x00; // pull-up unused outputs (no PC6,7)
DDRC = 0x3F; // set 0 as input (RESET input but no intr, ADC0 input)
PORTD = 0x00; // pull-up unused pins
DDRD = 0xFE; // set unused pins to outputs

UBRR0 = (uint16_t) 51;
UCSR0A = 0x00;
UCSR0B = 0x10;
UCSR0C = 0x06;

while (1)
{
printf ("\n\rThe Arduino is talking at 9600 …");
UBRR0 = (uint16_t) 25;
PORTB = PORTB ^ 0x20;
_delay_ms(100);
printf ("\n\rThe Arduino is talking at 19200 …");
UBRR0 = (uint16_t) 3;
PORTB = PORTB ^ 0x20;
_delay_ms(100);
printf ("\n\rThe Arduino is talking at 115200 …");
UBRR0 = (uint16_t) 51;
PORTB = PORTB ^ 0x20;
_delay_ms(100);
}
return (0);
}

Still, what sets the USB baud rate

The application on the host system that the USB side of the USB device is connected to, just like a COM port.

how can the Atmega168 know what that is?

That is determined in advance (by you).

-j

You need to set the baud rate both in the code that's running on the Arduino and in the software on the computer. On the Arduino, the easiest way is to use the Serial.begin() command that's part of the Arduino core: e.g. Serial.begin(9600). If you don't want to use the Arduino core, you'll need to set some of the ATmega's registers to the values corresponding to your baud rate. Here's the code from the Arduino core that does this. For the ATmega168:

#if defined(__AVR_ATmega168__)
      UBRR0H = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8;
      UBRR0L = ((F_CPU / 16 + baud / 2) / baud - 1);
      
      // enable rx and tx
      sbi(UCSR0B, RXEN0);
      sbi(UCSR0B, TXEN0);
      
      // enable interrupt on complete reception of a byte
      sbi(UCSR0B, RXCIE0);
#else
      UBRRH = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8;
      UBRRL = ((F_CPU / 16 + baud / 2) / baud - 1);
      
      // enable rx and tx
      sbi(UCSRB, RXEN);
      sbi(UCSRB, TXEN);
      
      // enable interrupt on complete reception of a byte
      sbi(UCSRB, RXCIE);
#endif
      
      // defaults to 8-bit, no parity, 1 stop bit

It should work in your program, but I'm not 100% sure it doesn't require some other small bits of configurations (e.g. enabling interrupts in general).