XMEGA UART read problem

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
jeff188
Posts: 30
Joined: 23 Feb 2015 07:16

XMEGA UART read problem

#1 Post by jeff188 » 05 Dec 2015 00:21

Having problems reading from an Xmega with a very basic setup. LCD display works properly but the display of the UART input is incorrect. There are characters of the same repeating pattern length as the source - but the letter shown on the LCD is incorrect.

The same basic source code was ported from a working ATmega128 project. Serial feed is the same for the XMEGA as the ATmega and is known working.

Hardware is Mikroe Xmega fed by a 3.3V ADI variant of the MAX232 level shifter.

Not sure what I am overlooking. This is my first project with the XMEGA but I've done many with ATmega in the past.

I'm assuming the default hardware configuration is external clock @ 8 mhz. Maybe that's incorrect and the board is running at some other speed.

Suggestions?


Main psudocode ----------------------------------------------------

Assumes project is 8Mhz.

char x;

LCD_init(); // setup LCD
UARTD1_Init(4800); // initialize UART D1
Delay_ms(100); // wait for uart to stabalize

while(1) {
if (UARTD1_Data_Ready() == 1) { // if D1 ready
x = UARTD1_read(); // read the received data,
Lcd_Out_CP(x); // write to LCD
}
}
Attachments
Display should show a repeating sequence "FAxxxxxxxx;" - where x is a number.
Display should show a repeating sequence "FAxxxxxxxx;" - where x is a number.
lcdfrag.png (837.83 KiB) Viewed 1730 times

jeff188
Posts: 30
Joined: 23 Feb 2015 07:16

Re: XMEGA UART read problem

#2 Post by jeff188 » 07 Dec 2015 07:25

SOLVED

There are 2 problems with this original setup.

The hardware was fine. The problems were in the code and are as follows:

1. The wrong LCD function was used initially. LCD_OUT_CP is for a string. The correct function is LCD_CHR_CP.

2. The uP runs at 2 Mhz. I've not independently tested the specific frequency. However, the UART polling does work with this frequency specified and it did not at the original setting of 8 Mhz. Given 2 Mhz is one of the internal RC clocks, that makes sense.

The default 10 Mhz that MikroeC starts a project with and the 8 Mhz on-board crystal (?) confused me.

I need to find the code that uses the 8 Mhz external crystal and uses the PLL x4 capability to run the uP @ 32 Mhz. If anyone has Xmega Mikroe C code for that - I would appreciate seeing it.

Post Reply

Return to “mikroC PRO for AVR General”