Some things to check - how does your library implement outp() and inp()
- do they hard code to assembler inp and outp instructions, or are they
C macros that do the right thing when the address > 0x3F? (The machine
instructions inp and outp only work on the lowest 64 bytes of the IO
space, all registers outside the lowest 64 IO space registers must be
addressed as regular RAM [even though they are still IO registers.])
outp(0x00, UCSRA); // USART:
outp(0x98, UCSRB); // USART: RxIntEnable|
RxEnable|TxEnable
outp(0x86, UCSRC); // USART: 8bit, no parity
outp(0x00, UBRRH); // USART: 38400 @ 8MHz
outp(12, UBRRL); // USART: 38400 @ 8MHz
You are enabling the transmitter and receiver and then configuring the
port. Good practice to get into on UART's is do all configuration with
the Transmitter and Receiver disabled.
If you would like some definitely working routines, take the ones out of
the ATmega8's datasheet. Initialization routines are page 139, transmit
routines are on page 140, polling receive routines are on page 143.
AVR Appnote 306 - AVR306 provides sample code for the 8515 - this
should, at most, just need some registers renamed.
Also, if you are testing un-proven hardware, you may want to setup main
to just continuously send the same character or a NULL. You can then
hook up a frequency counter, or a LED pulled up to VCC, to see if it
really is transmitting something from the MCU pin, maybe the problem is
in the circuitry and not the MCU?
John C
englsprogeny wrote:
>
> Hi everyone.
>
> I am trying to get an ATMEGA8 to talk to a terminal app on my PC by
> RS232. I have used the compiler [WinAVR] and programmer [PONY ISP]
> to compile and run other programs so I know that these parts of the
> issue are OK.
>
> Here is the source....
>
> Any ideas?
>
> I have an 8Mhz oscillator
>
> Note: if anyone has simpler source with makefile please send it to
> me. Thanks
>
> * >simcom -38400 /dev/ttyS0 */
>
> #include <avr/io.h>
> #include <avr/signal.h>
> #include <avr/interrupt.h>
>
> static void putchar(unsigned char ch){
> while ((inp(UCSRA) & 0x20) == 0) {};
> outp(ch, UDR);
> while ((inp(UCSRA) & 0x20) == 0) {};
> }
>
> SIGNAL(SIG_ADC){
> static int ctr1;
> static char lbyte,hbyte;
> ctr1++;
> lbyte = inp(ADCL);
> hbyte = inp(ADCH);
>
> if (ctr1>=1000){
> putchar(lbyte);
> //putchar('A');
> ctr1 = 0;
> }
>
> outp(BV(ADEN)|BV(ADSC)|BV(ADIE)|BV(ADPS2)|BV(ADPS1)|BV
> (ADPS0),ADCSR);
> // Internal Vref, right adjust
> // Enable ADC interrupts, Clock/128
> }
>
> SIGNAL(SIG_UART_RECV){
> char ch = inp(UDR);
> putchar(ch);
> }
>
> SIGNAL(SIG_OVERFLOW0){
> static int ctr;
> ctr++;
>
> if (ctr>=10){
> //putchar('O');
> ctr = 0;
> }
>
> }
>
> int main(){
> int i,j;
>
> outp(BV(TOIE0),TIMSK); // Enable TCNT0
> outp(0x00,TCNT0); // Reset TCNT00, CLK/1024
> outp(BV(CS02)|BV(CS00), TCCR0);
>
> outp(0x00, UCSRA); // USART:
> outp(0x98, UCSRB); // USART: RxIntEnable|RxEnable|TxEnable
> outp(0x86, UCSRC); // USART: 8bit, no parity
> outp(0x00, UBRRH); // USART: 38400 @ 8MHz
> outp(12, UBRRL); // USART: 38400 @ 8MHz
>
> /*outp(0xce, ADMUX); // Internal Vref, right adjust, read 1.22V
> (Vbg)*/
> outp(BV(REFS1)|BV(REFS0)|BV(MUX1),ADMUX); //ADC2
>
> // Enable ADC interrupts, Clock/128
> outp(BV(ADEN)|BV(ADSC)|BV(ADIE)|BV(ADPS2)|BV(ADPS1)|BV
> (ADPS0),ADCSR);
>
> putchar('M');
>
> sei();
>
> while (1) {
>
> /* putchar('L'); */
> for(i = 0;i<10000;i++){
> j = 1+1;
> }
>
> }
> }
>
>Message
Re: [AVR-Chat] MEGA8 RS232
2007-03-09 by John Clymer
Attachments
- No local attachments were found for this message.