I can't seem to get the USART on my at645 to work properly.
I have this same code[attached] for a atmega8 (different registers, but same
flags) and it works great.
I'd like a verification that this doesn't work with the atmega645.
Or am I missing a register flags or something with the atmega645?
-Marc
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define FOSC 14765400
#define BAUD 57600
#define MYUBRR FOSC/16/BAUD - 1
#define RS232_MAXBUFF 35
int rs232_send_numbytes,
rs232_send_index;
unsigned char rs232_send[RS232_MAXBUFF];
int rs232_recv_index;
unsigned char rs232_recv[RS232_MAXBUFF];
/* ----------------------------------------------------------------------- */
void rs232_init(void)
/*
* rs232 Initialization routine
*/
{
/* Set Baud Rate */
UBRR0L = MYUBRR;
UBRR0H = 0;
UCSR0B =
_BV(TXCIE0) /* TX Complete Interrupt Enable */
| _BV(TXEN0) /* TX ENable */
;
UCSR0C = _BV(UCSZ01) /* 8 data bits */
| _BV(UCSZ00) /* .. */
;
/* set data direction register for PORTE for usart */
DDRE = _BV(DDE1);
rs232_send_numbytes = 0;
rs232_send_index = 0;
}
/* ----------------------------------------------------------------------- */
void usart_send(unsigned char *string)
/*
* this here function sets up the transmission by setting up the
* buffer.
*/
{
if (rs232_send_index)
{
return;
}
rs232_send_numbytes = sprintf(rs232_send, "%s", string);
UDR0 = rs232_send[0];
rs232_send_index = 1;
}
// BS wait function
void wait(void){
int32_t x,y;
for (x=0; x<25000; x++){
y++;
}
}
/* ----------------------------------------------------------------------- */
int main(void)
/*
* Main loop
*/
{
/* initialization routines */
rs232_init();
sei();
short lights = 0;
unsigned char buffy[RS232_MAXBUFF];
sprintf(buffy, "I was Here!\n");
usart_send(buffy);
while(1) /* Neverending loop */
{
PORTB = lights;
wait();
// sprintf(buffy, "I'm in loop\n");
// usart_send(buffy);
lights++;
}
return 0;
}
/* ----------------------------------------------------------------------- */
SIGNAL(USART0_TX_vect)
/*
* This here signal is called when a byte has been sent through the
* USART. If there are more bytes to be sent then do the next one
*/
{
if (rs232_send_index == rs232_send_numbytes)
{
rs232_send_index = 0;
}
else
{
UDR0 = rs232_send[rs232_send_index++];
}
}
_______________________________________________
AVR-chat mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-chat