avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Fwd: First step


From: Kreyl
Subject: Re: [avr-chat] Fwd: First step
Date: Mon, 8 Feb 2010 00:44:31 +0300

    Hi!

You wrote Sunday, February 7, 2010, 9:00:00 PM:

2All: sorry for some cyryllic :-)

Привет! Пиши в личку, если что.

First: you should use "{}" instead of "()" in all functions implementation :-)

Second: your main() function must not return anything; moreover, it must not get out ever. For test purposes, you may use something like

int main(void){
    // do something valuable

    while(1); // loop forever
}

Third: no need to initialize completely and entirely all. For example, you don't need to mess with cli() & sei() as you do not use any interrupts.

Forth: information about your AVR (clock frequency, fuses etc.) would be critically helpful. 

Fifth: "does not respond" is too little to do with. What do you expect, what did you get instead of.

Well, as I suppose, with second code you did get your "+". If you did not with first one, then it loops forever trying to receive something. It must complete with it when you send something to your device, through your terminal program or what else.

But no. You have initialize your USART enabling it's receive interrupt. But you did not implement handler of the interrupt, something like 

// RX completed
ISR (USART_RX_vect) {
    uint8_t b = UDR0;
    // ...something else
}

So, when your device had received something, it calls unexisting interrupt, which means jump to the beginning of the code. And all starts again without any indication outwards.

Good luck!


 
                                          Best regards,
                                                        Kreyl

                                          mailto: address@hidden







-------- Original Message -------- 
Subject:  First step
Date:  Sun, 07 Feb 2010 23:34:20 +0600
From:  Максим Денисов <address@hidden>
To:  address@hidden




Hello everyone! Help make the first steps in the avr-libs.

I can not accept data from USART

# define F_CPU 20000000UL

# include <avr/io.h>
# include <avr/interrupt.h>


void port_init (void) (
 PORTA = 0x00;
 DDRA = 0x00;
 PORTB = 0x00;
 DDRB = 0x00;
 PORTD = 0x00;
 DDRD = 0x00;
)


/ / Desired baud rate: 2400
/ / Actual: baud rate: 2399 (0.0%)
void usart_init (void)
(
 UCSRB = 0x00; / / disable while setting baud rate
 UBRRH = 0x02; / / set baud rate upper
 UBRRL = 0x08; / / set baud rate lower
 UCSRA = 0x00;
 UCSRC = 0x06;
 UCSRB = 0x98; / / enable
)


void init_devices (void)
(
 cli (); / / disable all interrupts
 port_init ();
 usart_init ();

 MCUCR = 0x00;
 GIMSK = 0x00;
 TIMSK = 0x00;
 sei (); / / re-enable interrupts
)


void usart_transmit (unsigned char data) (

        while (! (UCSRA & (1 <<UDRE)))
                ;

        UDR = data;
)

unsigned char usart_receive (void) (

        while (! (UCSRA & (1 <<RXC)))
                ;

        return UDR;
)


int main (void) (
unsigned char data;
        init_devices ();

        data = "" ();
        usart_transmit ('+');


        return 0;
)

when sending data from the computer it does not respond.

but the following code works correctly and I get the data from the 
controller.


int main (void) (

        init_devices ();

        usart_transmit ('+');

        return 0;
)

why can not I accept this?


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4845 (20100207) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




  
reply via email to

[Prev in Thread] Current Thread [Next in Thread]