Mam problem z tranmisja AVR->PC. Uzywam ATmega32-16PU@10MHz, zew. krysztal. Fusy ustawione highbyte 0xC9, lowbyte 0xFF. Zasilanie 5V, kowerter poziomow to MAX232N, piny podpiete tak
ATMEGA MAX232 input MAX232output PC RS
TXD T2IN T2OUT RX ( pin 2)
RXD R2OUT R2IN TX (pin3)
GND (pin5)
Kod programu testowego:
Hyperterminal/Putty milcza, zarowno na lapie jak i na przejsciowce USB-RS na moim kompie. Zegar jest dobry, bo jak zrobie 4 x delay 250ms to diodka swieci sie przez sekunde. Blad zegara USART to 1.7%, czyli znosnie. Nie wiem juz co mam z tym zrobic.
Poprawiłem tytuł - regulamin p.11.1
Przeniosłem do właściwego działu.
[zumek]
ATMEGA MAX232 input MAX232output PC RS
TXD T2IN T2OUT RX ( pin 2)
RXD R2OUT R2IN TX (pin3)
GND (pin5)
Kod programu testowego:
#define BAUDRATE 64 // 9600 at 10MHz
#define LED 0
#define LED2 6
#define F_CPU 10000000
//tranmission led
#define LED_ON() PORTC |= (1<<LED)
#define LED_OFF() PORTC &= ~(1<<LED)
//power led
#define LED2_ON() PORTD |= (1<<LED2)
#define LED2_OFF() PORTD &= ~(1<<LED2)
#include <avr/io.h>
#include <util/delay.h>
void rsInit(unsigned char baud) {
//UBRRH = 0;
UBRRL = baud;
UCSRC = (1<<UCSZ0) | (1<<UCSZ1); // 8N1
UCSRB = (1<<RXEN) | (1<<TXEN); // enable tx and rx
}
void rsSend(unsigned char data) {
while( !(UCSRA & (1<<UDRE)));
UDR = data;
}
unsigned char rsRecv() {
while( !(UCSRA & (1<<RXC)));
return UDR;
}
void portInit() {
//DDRD = (1 << LED);
// PORTC = 0xFF;
DDRC = 0xFF;
DDRD = (1 << LED2);
}
volatile unsigned char bytes[16];
int main(void){
unsigned int i=0;
asm("cli");
portInit();
_delay_ms(100);
rsInit(BAUDRATE);
LED2_ON();
bytes[0]=0x30;
bytes[2]=0x40;
bytes[3]=0x42;
bytes[4]=0xFF;
bytes[5]=0x48;
bytes[6]=0x40;
bytes[7]=0x60;
bytes[8]=0x70;
bytes[9]=0x80;
bytes[10]=0xF0;
bytes[11]=0xF0;
bytes[12]=0xF0;
bytes[13]=0xFA;
bytes[14]=0xFA;
bytes[15]=0xFA;
while(1){
for(i=0;i<16;i++){
rsSend(bytes[i]);
}
LED_ON();
_delay_ms(250);
_delay_ms(250);
_delay_ms(250);
_delay_ms(250);
LED_OFF();
_delay_ms(250);
_delay_ms(250);
_delay_ms(250);
}
return 0;
}
Hyperterminal/Putty milcza, zarowno na lapie jak i na przejsciowce USB-RS na moim kompie. Zegar jest dobry, bo jak zrobie 4 x delay 250ms to diodka swieci sie przez sekunde. Blad zegara USART to 1.7%, czyli znosnie. Nie wiem juz co mam z tym zrobic.
Poprawiłem tytuł - regulamin p.11.1
Przeniosłem do właściwego działu.
[zumek]