Witam wszystkich. Chciałem napisać program który odbierze znak po rs232 i go odeśle. Kod pochodzi z datasheeta atmegi16. Port w komputerze jest dobrze skonfigurowany. Do komunikacji używam terminala v1.8. Atmega niestety nie odpowiada.
Czy ktoś ma jakieś sugestie?
#include <avr/io.h>
#define F_CPU 8000000L // zegar w Hz
#define RS_BAUD 4800
#define RS_UBRR F_CPU / 16 / RS_BAUD - 1
void USART_Init( unsigned int ubrr)
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 1stop bit */
UCSRC = (1<<URSEL)|(1 << UCSZ0) | (1 << UCSZ1);
}
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
}
unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSRA & (1<<RXC)) )
;
/* Get and return received data from buffer */
return UDR;
}
void USART_STRING(const char *s )
{
while (*s)
USART_Transmit(*s++);
}
int main(void)
{
uint8_t c;
USART_Init(RS_UBRR);
USART_STRING("ATMega16 UART test\r\n");
USART_STRING("mikrokontroler.info\r\n");
while(1)
{
c = USART_Receive();
USART_Transmit(c);
}
}Czy ktoś ma jakieś sugestie?