Hej, to jes5t kod z postu do którego odnośnik powyżej
#include <avr/io.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <inttypes.h>
#define PARITY_NONE 0
#define PARITY_EVEN (1<<UPM1)
#define PARITY_ODD ((1<<UPM1)|(1<<UPM0))
#define STOP_BITS_1 0
#define STOP_BITS_2 (1<<USBS)
#define DATA_BITS_5 0
#define DATA_BITS_6 (1<<UCSZ0)
#define DATA_BITS_7 (1<<UCSZ1)
#define DATA_BITS_8 ((1<<UCSZ1)|(1<<UCSZ0))
#define DATA_BITS_9 ((1<<UCSZ2)|(1<<UCSZ1)|(1<<UCSZ0))
#define F_CPU 15000000 // 15MHz zegar procesora
#define UART_BAUD 115200
#define _UBBR_ ((F_CPU/(16*UART_BAUD))-1)
unsigned char byte;
int USART_Transmit( unsigned char data )
{
while ( !( UCSRA & (1<<UDRE)) );/* Wait for empty transmit buffer */
UDR = data;/* Put data into buffer, sends the data */
return 0;
}
//void USART_Init( unsigned int baud_reg )
/* UBRRH = (unsigned char)(baud_reg>>8);
UBRRL = (unsigned char)baud_reg;*/
// To jest to, co najbardziej kocham w AVR-gcc -
// - brak elastyczności preprocesora w obliczeniach... ;)
// W tym przypadku wywala : "warning: integer overflow in expression"
// i oczywiście wstawia bzdury, więc wszystko muszę ręcznie wyliczać...
// Dlaczego AVRasm2 nie ma z tym problemu i w nim moge pisać łatwo kod na różne
// częstotliwości oscylatorów, bez chrzanienia się z wyliczeniami... ? ;)
void USART_Init( void )
{
UBRRH = 0x00;
UBRRL = 0x07;
UCSRB = (1 << RXCIE) | (1 << RXEN) | (1 << TXEN);
UCSRC = (1 << URSEL) | DATA_BITS_8 | PARITY_NONE | STOP_BITS_1;
sei();
}
int main (void)
{
// USART_Init(_UBBR_);
USART_Init();
DDRB |= (1 << PB1);
while(1)
{
}
return 0;
}
SIGNAL (SIG_UART_RECV)
{
PORTB ^= (1 << PB1);
byte = UDR;
USART_Transmit(byte);
}
Zmieniłem:
#define F_CPU 15000000 // z 4MHz na 15MHz
#define UART_BAUD 115200 // z 19200 na 115200
UBRRL = 0x07; // z 0x0C na 0x07
czy coś jeszcze trzeba zmienić dla Atmega32 ?? bo w AVRStudio mi to nie chce iść ??