Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Avr code debugging error...

Status
Not open for further replies.

tushki7

Full Member level 4
Joined
Jul 6, 2010
Messages
232
Helped
50
Reputation
100
Reaction score
47
Trophy points
1,318
Location
india
Activity points
2,789
hello,
Please correct the error !!!
avr problem.jpg

Here is my code:
Code:
#include <avr/io.h>

#define F_CPU 8000000 // CPU @ 8MHZ
#define USART_BAUDRATE 9600 // SERIAL Communication @ 9600 baud
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) // baudrate formula
#include <util/delay.h> // header file defining delay
int main(void)  // main code begins
{
DDRB = 0xff; // PORT D as output
DDRD = 0xfc; // PORT D PIN 2-7 as output.
UCSRB |= (1 << RXEN) | (1 << TXEN); // Enable Rx & Tx of USART
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // 8bit, 1 Stop bit, no parity
UBRRL = BAUD_PRESCALE; // setting baud rate @ 9600 baud
UBRRH = (BAUD_PRESCALE >> 8);
while(1) // loop forever
{
//bot1 code
unsigned char s=0; // for use as a counter
unsigned char a[] = {0x23, 0x02, 0x30, 0x52, 0x00}; // Tx packet in the forrmat of //char array a[] = {0x23, 0x02, 0x30, 0x52, 0x00}, where 0x00 is not the part of ac-tual //tx packet but is rather used to indicate within this code the end of packet.
while (a[s] != '\0') // Loop to send tx packet through USART while scanning for ‘\0’
{
while ((UCSRA & (1 << UDRE)) == 0); // Loop until UDR buffer is ready to re-ceive // next byte to be transmitted.
UDR = a[s]; // Add next byte to be transmitted to the UDR buffer
s++; // Increment the counter
_delay_ms(50); // delay of .02ms
}
_delay_ms(2000); // delay of 2 sec
s=0; // reset counter
a[3] = 0x53; //modify char array to a[] = {0x23, 0x02, 0x30, 0x53, 0x00},
	while (a[s] != '\0') // Loop to send tx packet through USART while scanning for ‘\0’
{ // While loop opened.
while ((UCSRA & (1 << UDRE)) == 0); // Loop until UDR buffer is ready to re-ceive // next byte to be transmitted.
UDR = a[s]; // Add next byte to be transmitted to the UDR buffer
s++; // Increment the counter
_delay_ms(50); // delay of .02ms
}

avr2.png
 

The error says URSEL is not defined, have you defined the mcu you are using in the project properties?
If not then the header that includes this info is not added.

Alex

---------- Post added at 16:27 ---------- Previous post was at 16:26 ----------

Maybe your header is missing it, which mcu are you using?
 
  • Like
Reactions: tushki7

    tushki7

    Points: 2
    Helpful Answer Positive Rating
The error says URSEL is not defined, have you defined the mcu you are using in the project properties?
If not then the header that includes this info is not added.

Alex

---------- Post added at 16:27 ---------- Previous post was at 16:26 ----------

Maybe your header is missing it, which mcu are you using?

Thank you
i was using attiny2313 as device.. but when i changed it to atmega8 it worked..
But i want to run this code in my attiny2313v can't i do this?? what is the problem?
 

URSEL is bit 7 in the UCSRC register of mega 8,
there is no such name in tiny2313, the bit 7 in UCSRC is unused
 
  • Like
Reactions: tushki7

    tushki7

    Points: 2
    Helpful Answer Positive Rating
Any idea how to make it work for attiny2313???
 

In m8 the URSEL bit is used to select between the UBRRH/UCSRC because

The UCSRC Register shares the same I/O location as the UBRRH Register. See the “Accessing
UBRRH/UCSRC Registers” on page 146 section which describes how to access this register.

In tiny2313 there is no such problem so there in no need to use URSEL
 
  • Like
Reactions: tushki7

    tushki7

    Points: 2
    Helpful Answer Positive Rating
oh Thanks alot..
so i can write:
this:
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // 8bit, 1 Stop bit, no parity
as:
UCSRC |= (1 << UCSZ0) | (1 << UCSZ1); // 8bit, 1 Stop bit, no parity
 

Yes, I haven't use tiny but I think this will work fine

UCSRB |= (1 << RXEN) | (1 << TXEN); // Enable Rx & Tx of USART
UCSRC |= (1 << UCSZ0) | (1 << UCSZ1); // 8bit, 1 Stop bit, no parity
UBRRL = BAUD_PRESCALE; // setting baud rate @ 9600 baud
UBRRH = (BAUD_PRESCALE >> 8);
 
  • Like
Reactions: tushki7

    tushki7

    Points: 2
    Helpful Answer Positive Rating
It is debugging well, Lets see if it is working in attiny or not!!!
Will give my feed back to you soon..

Thanks :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top