Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Simple Serial communication with a attiny 2313
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Simple Serial communication with a attiny 2313

by tge1986 on Tue Jan 20, 2009 10:59 pm

I'm trying to get a simple serial application to work with a attiny2313, I'm trying to send the chip a value (1-5) and have it turn on one of 5 pins that corresponds with that value. I've tried to just get a simple serial program to work with the chip but even that won't work for me. here is the code I'm working with:
Code: Select all | TOGGLE FULL SIZE
#include <avr/io.h>

#define F_CPU 16000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

int main (void)
{
   char ReceivedByte;

   UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
   UCSRC |= (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes

   UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of t
   UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte o

   for (;;) // Loop forever
   {
      while ((UCSRA & (1 << RXC)) == 0) {}; // Do nothing until data have been recieved and is
      ReceivedByte = UDR; // Fetch the recieved byte value into the variable "ByteReceived"

      while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to b
      UDR = ReceivedByte; // Echo back the received byte back to the computer
   }   
}

there is something wrong with this code and i can't figure it out. when I use a serial port monitor and send it something and wait for a response nothing comes back. I have a 16hz crystal attached to the proper ports and everything else seems right. I'm following two different tutorials to try to get this to work the first one is on the AVRfreaks site it's the Using the USART with AVR-GCC tutorial and then i found some other tutorial on google because I kept getting errors because of the line
Code: Select all | TOGGLE FULL SIZE
 UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);

something about URSEL not being declared in the scope, so i found a tutorial that left the URSEL out. The AVR freaks tutorial is for the Mega16 so maybe that's the issue I'm coming up with.
-Tim
tge1986
 
Posts: 28
Joined: Mon Jul 21, 2008 10:09 pm

Re: Simple Serial communication with a attiny 2313

by mtbf0 on Tue Jan 20, 2009 11:48 pm

tge1986 wrote:something about URSEL not being declared in the scope, so i found a tutorial that left the URSEL out. The AVR freaks tutorial is for the Mega16 so maybe that's the issue I'm coming up with.


oh, yeah. you can say that again.

you'll have to take a peek at the 2313 datasheet to get the correct names for its registers and bits.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: Simple Serial communication with a attiny 2313

by tge1986 on Tue Jan 20, 2009 11:57 pm

What am i looking for in the data sheet? I'm quite new to the AVR scene, after playing in the shallow end with the arduino i'm trying to go to the deep end and use AVR's outside the arduino environment.

Update:
I found what I was looking for in the data sheet, however it did not seem to solve the problem I'm having. I've followed the example code they use in the data sheet and it still doesn't work I receive lots of gibberish characters. Is is a timing issue? I read somewhere that I need to burn the fuse to tell the chip that i'm using an external crystal is that true? if so how do i burn fuses that is something I've never done before. I'm using Programmers Notepad to write the code and I'm compiling it with AVR-GCC, I have to burn fuses in the Makefile, thats all i know about burning fuses.
tge1986
 
Posts: 28
Joined: Mon Jul 21, 2008 10:09 pm

Re: Simple Serial communication with a attiny 2313

by mtbf0 on Wed Jan 21, 2009 5:49 am

coming form the factory your 2313 is running at 1MHz. you'll need to run avrdude using the same programmer type, part and port options as in your Makefile and the option
Code: Select all | TOGGLE FULL SIZE
-U lfuse:w:0xee:m
to turn on the fuse for high frequency external crystal and to turn off clock divide by 8.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: Simple Serial communication with a attiny 2313

by trialex on Tue Jan 27, 2009 8:00 pm

This thread makes you realise how good the arduino combination of hardware and software is in making microcontrollers easy to use.

Kudos to you though for working on the 2313 - if you could post up your code when you get serial comms working that would be awesome - I'll be using it for sure!
trialex
 
Posts: 189
Joined: Mon Apr 03, 2006 6:25 pm

Re: Simple Serial communication with a attiny 2313

by raykholo on Wed Aug 04, 2010 8:48 am

I need something very similar to this, for an Attiny25 micro. All it needs to do is power up, transmit a 10 byte string that I define in the program, and then do nothing or sleep, doesn't matter which.

I take it that this is a 2 wire interface?
raykholo
 
Posts: 26
Joined: Fri Feb 19, 2010 6:54 pm

Re: Simple Serial communication with a attiny 2313

by uhe on Thu Aug 05, 2010 7:55 pm

If people refer to a 2-wire interface they normaly talking about I2C not RS232.
Both are using two wires but they are used differently. I2C has one wire for clock and one for data, RS232 has one wire for sending (TX) and one for receiving (RX). AFAIK the Tiny25 doesn't have a RS232 interface (USART).
"I have not failed. I've just found 10,000 ways that won't work." - Thomas Edison
uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm
Location: metric world

Re: Simple Serial communication with a attiny 2313

by adafruit_support_bill on Thu Aug 05, 2010 8:43 pm

At a minimum, RS-232 requires a ground as well.

adafruit_support_bill
 
Posts: 78956
Joined: Sat Feb 07, 2009 10:11 am

Re: Simple Serial communication with a attiny 2313

by uhe on Fri Aug 06, 2010 6:32 am

Since fiber optic is the only wired connection I know of that will work without a GND connection, I left it out. Of course there is always a "+one ground wire" even if the interface is called "1-Wire" ;)
"I have not failed. I've just found 10,000 ways that won't work." - Thomas Edison
uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm
Location: metric world

Re: Simple Serial communication with a attiny 2313

by raykholo on Fri Aug 06, 2010 10:53 am

Allow me to clarify. Yes, I was talking about i2c. When I said "two wires" I was referring to the number of physical wires required. The tiny25 will be on a separate pcb that will plug in to the main module with arduino inside it via usb connectors. Hence, power, ground, and the two wires required for i2c - clock and data.

Programming wise, will I need to drastically change the above example, or only make some minor changes?

Thanks
raykholo
 
Posts: 26
Joined: Fri Feb 19, 2010 6:54 pm

Re: Simple Serial communication with a attiny 2313

by uhe on Fri Aug 06, 2010 1:50 pm

You can't use it since it's about RS232 (USART) and not i2c.
"I have not failed. I've just found 10,000 ways that won't work." - Thomas Edison
uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm
Location: metric world

Re: Simple Serial communication with a attiny 2313

by raykholo on Fri Aug 06, 2010 11:27 pm

Oh, now I understand what you were/ are saying. Thanks for pointing that out.
raykholo
 
Posts: 26
Joined: Fri Feb 19, 2010 6:54 pm

Re: Simple Serial communication with a attiny 2313

by shashankkulkarni on Wed Aug 10, 2011 6:58 am

For a very basic yet conceptual tutorial on serial communication using RS232 on ATmega32/16...you can refer to the following link http://shashank-kulkarni.blogspot.com/2 ... a3216.html
shashankkulkarni
 
Posts: 1
Joined: Wed Aug 10, 2011 6:46 am

Please be positive and constructive with your questions and comments.