ATmega88 USART Receive problem

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

I have a problem with the AVR receiver problem.
The project consists of an ATmega88 which comunicates via an RS232 interface with a pc.
When I send data from the micro to the pc the datas received well but in the other way the micro does not.

I have seen the datas on the micro RXD pin with the oscilloscope. Also, the pin is set as an input (without pull up). Debuging using the MKII (debug wire) I see that the micro is going to the USART0 interrupt routine (RXCIE0 is set), but the data is always 0x00. When I check the UDR0 data in the RAM area is see that is 0x00 (address 0xC6).

I have check the RXD input as a digital inpout using a test routine and it's working well. I mean that it recognizes the logic 0 and logic 1.

Does anybody have an idea what I am not doing well?

Thank you very much.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Until you post your code there's no way we can see what you're doing wrong.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

//ATMega88
//Ext crystal 7,3728MHz
//IAR C Compiler

//IO Setup
PORTC = 0x00;

//USART0 Setup
UBRR0H = 0;
UBRR0L = 47;
UCSR0C = (1<<UCZ01) | (1<<UCS00);
UCSR0B = (1<<RXCIE0) | (1<<RXEN0) | (TXEN0);

while(1);

//Receive complete interrupt
#pragma vecor = USART_RX_vect
__interupt void USART_RX_Interrupt(){
if (UDR0 == 0x55){
// program
}
}

//I have check that the compiler buids a code using the lds, sts commands when accesses the UDR0.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does it work by polling? If so, this proves xtal, baud rate divisor and electrical connection are ok.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All the electrical connections seem to be well. I have checked the data on the RXD pin with the oscilloscope and it is really the 0x55 (at 9600bps as I expect) with one stop bit.

The PC receives well the data send by the micro.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think it would be swell if avrfreaks had a place to put some example programs. Someone could put 'interrupt receive using iccavr' and then someone else would post a version for codevision, then winavr, iar, rowley, etc etc etc. Anyone else think that is worthwhile?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunatly I only know the WinAVR/GCC way to declare interrupts.
But is

#pragma vecor = USART_RX_vect 

correct? I would assume vector with t.

Michael

In the beginning was the Word, and the Word was with God, and the Word was God.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

[quote="icarus1

UCSR0B = (1<<RXCIE0) | (1<<RXEN0) | (TXEN0);

looks like a typo, you don't have 1<< in front of TXEN0

while(1);

ouch! infinite loop, will the remainder of your code get executed?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, guys. I am sorry for this it was a copy from one PC to the other, by reading and writing.
The compiler shows Ok and it builds the hex.

#pragma vector = USART_RX_vect
UCSR0B = (1<<RXCIE0) | (1<<RXEN0) | (1<<TXEN0);

is it Ok now???

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The problem still exists. Does anybody have an idea about this issue?

Thanks

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

just wondering are you interfacing through a RS232 driver and receiver chip like ST232 ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My interface uses the max232 chip.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Global interrupt enabled ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rather than posting a broken snippet - how about showing all the code (or at least a small stand alone test program that demonstrates the fault)?

Also can you check the code in the debugger and verify that word location 0x0012 in the flash DOES have an RJMP to the USART_RX_Interrupt() routine?

I know that it's obvious but you ARE including iom88.h rather than any other part specific header file aren't you? It has:

#define  USART_RX_vect        (0x24) /* USART Rx Complete */

so you could try

#pragma vector = 0x24 
__interupt void USART_RX_Interrupt(void) {
}

instead of using the sumbolic name for the vector in case the wrong value is being used for some reason.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I have check it.
At 0x0012 there is the rjmp instructions that send the cursor at the Receive complete ISR.
But, this is not the problem. The program gets in the ISR but the data is not received well. If you read up how I described the problem you will understand.

I have almost check electricaly the RX and TX pins as IO pins and they are working well.

Thanks

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah I see. So HOW are you "seeing" that the value in UDR0 is always 0x00 when the RX interrupt occurs?

(by the way - in the code you posted you are looking for 0x55 - that is 'U' - that IS what you are typing into the PC terminal is it? No chance you may be sending 'u' (0x75) instead?)

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The UDR register is a 2 level FIFO. If for some reason you read it twice that second read would give you the value in the receiver shift register, that would probably be empty (0x00). To make sure the debugwire interface does not read UDR before you inspect it you might want to store the value in UDR into a variable first and set your breakpoint after that. Then inspect that variable.

I remember having problems reading another USART register (on a mega 32, using JTAG), the USART was still functioning correctly though.

Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, I see. I will try all those, this afternoon. Althought, I have used the UART debuging the mega16 (via JTAG interface) in the past and I had no problem.
I also tried those you suggest me.

I will inform the freaks about my research.

Thank you.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try to connect pull-up resistor, say 10k, from RXD input to +5V.

Szymon