Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic Printable version Log in to check your private messages View next topic
Author Message
clawson
PostPosted: Jul 14, 2011 - 04:40 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 71055
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

can't download the tutorial pdf ,please help


Were you logged in when you tried? You can only download attachments when logged in. If it still doesn't work what's actually happening? If it happens to be downloading the file with the name "index.php" then after download just rename that to "uart.pdf" and it should work.

Moderator

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Jul 14, 2011 - 06:40 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21965
Location: Lund, Sweden

abhay289 wrote:
can't download the tutorial pdf ,please help

Just tested it, and it works fine for me. Do you get any error message, or is the download corrupt, or what...?
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
chriissis
PostPosted: Jul 27, 2011 - 10:42 PM
Newbie


Joined: Aug 09, 2010
Posts: 16


I can't download the pdf from the first post either. it says "141770/0b, stopped", without stopping it (tried more than once)
 
 View user's profile Send private message  
Reply with quote Back to top
mpernpei
PostPosted: Aug 02, 2011 - 09:55 AM
Newbie


Joined: Apr 08, 2010
Posts: 6
Location: Munich, Germany

Hey Guys,

I'm new with AVR and the STK600.
The tutorial is awesome (great job Dean).
I tried the Code, but it's not possible to receive or send data.

I'm using the STK600 with an ATMega1280 and the AVRStudio (Version 4.1Cool.
If I connect the Board via USB to my PC, I can adjust VTarget (5V), Clock Generator (8MHz) and the fuses.
After that I switch everything to the JTAGICEmkII. In the HW Settings the VTarget is still 5V but the Clock Generator is now blank. So what is my Clock now?
I guessed it's still 8MHz, so I choose for F_CPU 8MHz (CKDIV8 fuse non-selected).
Terminal works, because if I short the RX/TX pins of the RS232 Spare, I get an answer.

Here's my code, maybe there is a mistake in there..
Code:

#include <avr/io.h>


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

int main (void)
{

   char ReceivedByte;

   UCSR0B = (1<<RXEN0) | (1<<TXEN0);    //Turn on the transmission and reception circuitry
   UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);    //Use 8-bit character sizes - URSEL bit set to select the UCRSC register
   UBRR0L = BAUD_PRESCALE;            //Load lower 8-bits of the baud rate value into the low byte of the UBRR register
   UBRR0H = (BAUD_PRESCALE >> 8);         //Load upper 8-bits of the baud rate value into the high byte of the UBRR register

   for (;;)               //Loop forever
   {

      while ((UCSR0A & (1 << RXC0)) == 0 )
      {};               //Do nothing until data have been received and is ready to be read from UDR
      
      ReceivedByte = UDR0;         //Fetch the received byte value into the variable "ByteReceived"

      while ((UCSR0A & (1 <<UDRE0)) ==0 )
      {};               //Do nothing until UDR is ready for more data to be written to it
      
      UDR0 = ReceivedByte;         //Echo back the received byte back to the computer
   }      
   return 0;
}


I connected the RX/TX pins of the RS232 Spare to PE0 and PE1.
The switch for the different types of clock is set to ext, as I use the programmable clock generator (I guess...)

Thanks for your help!!

Cheers,
Michael
 
 View user's profile Send private message  
Reply with quote Back to top
mpernpei
PostPosted: Aug 03, 2011 - 06:44 AM
Newbie


Joined: Apr 08, 2010
Posts: 6
Location: Munich, Germany

Okay, problem solved, but I don't know why...
I tried to switch the LED's in the upper code on like:
Code:

DDRB = 0xFF;
PORTB = 0xF0;

but it didn't work. So I tried to toggle the LED's without uart and it worked.
After that I copied line for line of the upper code in the working code and tried after each line if the LED's are still working.
At the end everything works!!

Murphy's law....
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Aug 03, 2011 - 09:18 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 71055
Location: (using avr-gcc in) Finchingfield, Essex, England

We really shouldn't be using this tutorial thread for general fault diagnosis but you are aware, are you not, that the STK500 and STK600 LEDs use inverse logic so 0=lit and 1=off?

Anyway the question is rhetorical as I'm now going to lock this thread. If anyone has genuine feedback to improve the article in the first post then contact js, plons or clawson and ask one of us to temporarily unlock this thread so you can add your feedback. (one of us may then be able to edit the original article).

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
jokkebk
PostPosted: Apr 12, 2012 - 10:08 AM
Rookie


Joined: Apr 07, 2011
Posts: 39


As a sidetrack of my SD/FAT tutorial, I wrote a post on UART with ATtiny2313 and MAX3232* in my blog:

http://codeandlife.com/2012/04/12/3-3v- ... ax3232cpe/

My tutorial includes an example breadboard setup for the MAX(3)232 images and a simple test code, so I thought it would be useful companion article for Dean's excellent USART tutorial.

*) MAX3232 is pin-compatible with MAX232 so the tutorial can also be followed without the 3.3V requirements if using MAX232 (with the non-ACPE model, you'll need 1.0 uF caps though instead of 0.1 uF).

_________________
http://codeandlife.com
 
 View user's profile Send private message  
Reply with quote Back to top
armoli
PostPosted: Apr 15, 2012 - 01:54 AM
Newbie


Joined: May 02, 2008
Posts: 12


Hi all, good night.
I a new with attiny2313 works. I´m trying to setup a PC to attiny communication in a way that if I issue the command LED1 the led on PORTD6 will light on. So far I´m learning how to use seral communication and I took an example code and modified a little bit by indroducing a if/else condition. The strange thing that I´m not undestanding is:
1) If I send 'S' (=83) the led turns on after the third time that the caracter is sent.
2) If I send an A, I have to send it 3 times befor I get back the letter B ( the code adds 1 to the letter sent).
Cand someone explain that to me? I´m posting the code here and I do not have any issue with fuses. It is working but with a strange behaviour.
[code]/*
* serialcom3.c
*
* Created: 11/04/2012 20:39:57
* Author: Alf
*/

#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 8000000 // Oscillator frequency.
#define BaudRate 9600
#define MYUBRR ((F_CPU / 16UL / BaudRate ) - 1 )


/* Prototypes */
void InitUART (unsigned char baudrate);
unsigned char ReceiveByte (void);
void TransmitByte (unsigned char data);


/* --------------------------------------------------------------
Main - program that recieves a character then transmits back the next character.
An example would be if you send in an A, the chip will return a B
---------------------------------------------------------------- */
int
main (void)
{
DDRD |= _BV(1) | _BV(6);


unsigned char i;
unsigned char data;
InitUART (9600); /* Set the baudrate to
9600 bps using a 8 MHz internal clock */
while (1)
{
//TransmitByte (ReceiveByte () + 1);
/* Echo the received character + 1. Example send in A then send out B */
ReceiveByte();

if (ReceiveByte()==83) {
for (i = 0; i < 200; i++);
PORTD ^= _BV(6);} // Turn on LED @ PD6

else
{
TransmitByte(ReceiveByte()+1);
}
}
}

/* Initialize UART */
void InitUART (unsigned char baudrate)
{
/* Set the baud rate */
UBRRH = (unsigned char)( MYUBRR >> Cool;
UBRRL = (unsigned char) MYUBRR;


/* Enable UART receiver and transmitter */
UCSRB = (1 << RXEN) | (1 << TXEN);

/* set to 8 data bits, 1 stop bit */
UCSRC = (1 << UCSZ1) | (1 << UCSZ0);

}

/* Read and write functions */
unsigned char ReceiveByte (void)
{

/* Wait for incomming data */
while (!(UCSRA & (1 << RXC)));

/* Return the data */

return UDR;
}

void TransmitByte (unsigned char data)
{
/* Wait for empty transmit buffer */
while (!(UCSRA & (1 << UDRE)));

/* Start transmittion */
UDR = data;
}
[code]
looking for any help
Alfredo
 
 View user's profile Send private message  
Reply with quote Back to top
jokkebk
PostPosted: Apr 15, 2012 - 07:23 AM
Rookie


Joined: Apr 07, 2011
Posts: 39


armoli wrote:

ReceiveByte();

if (ReceiveByte()==83) {
...


I think this question would be better asked somewhere else than this tutorial thread. But in any case:

Every time you call ReceiveByte(), your program will wait for another key over UART. Instead, you should use:

ch = ReceiveByte();

if(ch == 83) {
...

_________________
http://codeandlife.com
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Apr 15, 2012 - 01:04 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 71055
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

I think this question would be better asked somewhere else than this tutorial thread.

True. And for that reason I'll lock it. Suggest this continues elsewhere.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits