Reading from USART1 but wrong values?

General discussion on mikroBasic for AVR.
Post Reply
Author
Message
Reverant
Posts: 13
Joined: 11 Jul 2007 10:38

Reading from USART1 but wrong values?

#1 Post by Reverant » 09 Sep 2007 10:51

Hi,

I have written a program for my ATMega128 on BIGAVR with mikroBasic 4.0.2. The program runs and gets data only when it is sent, but the bytes received are wrong!

Examples:
Sent ASCII '0', received decimal byte 216
Sent ASCII '1', received decimal byte 217
Sent ASCII '2', received decimal byte 216 (again!)
Sent ASCII 'a', received decimal byte 209
Sent ASCII 'b', received decimal byte 208
Sent ASCII 'c', received decimal byte 209 (again!)

etc. The same happens from both a PC as well as from an embedded device that can send ASCII codes on demand. The serial settings are 19200,8,N,1.

An example program that does the above is:

program MTSRead

dim byte1 as byte
dim byteText as string[3]

main:

Glcd_Init(PORTE, 2, 3, 4, 5, 7, 6, PORTA)
Glcd_Set_Font(font5x7, 5, 7, 32)
Glcd_Fill($00)
USart1_Init(19200)
Delay_ms(10)

while (true)
while USart1_Data_Ready = 0
nop
wend

byte1 = USart1_Read
ByteToStr (byte1, byteText)
Glcd_Write_Text(byteText, 1, 0, 1)

delay_ms(2000)
Glcd_Fill($00)
Glcd_Write_Text(" ", 1, 0, 1)

wend
end.

Reverant
Posts: 13
Joined: 11 Jul 2007 10:38

#2 Post by Reverant » 13 Sep 2007 07:16

Anyone??

majdak
mikroElektronika team
Posts: 28
Joined: 28 Jun 2007 09:40

#3 Post by majdak » 13 Sep 2007 10:46

I was test your code and everything work fine. The received values are as I expect. Can you pack(zip, rar) and send me you project folder. Also send me picture of BIGAVR so I can see your jumper configuration.

Reverant
Posts: 13
Joined: 11 Jul 2007 10:38

#4 Post by Reverant » 13 Sep 2007 21:49

Hi,

program's folder is here.
BigAVR board pic is here.

Thanks,
Dimitris

Tess
Posts: 49
Joined: 27 Dec 2006 18:49

#5 Post by Tess » 14 Sep 2007 08:05

Did you try with an usart at 9600, it works better sometimes.

Tess.

Reverant
Posts: 13
Joined: 11 Jul 2007 10:38

#6 Post by Reverant » 14 Sep 2007 08:36

I just tried it with 14400, 9600, 4800 and 1200, it still does not work. I reinstalled MikroBASIC for AVR 4.0.2 Demo and still no go. Anything else I can try? Are the jumpers correct?

Thanks,
Dimitris

majdak
mikroElektronika team
Posts: 28
Joined: 28 Jun 2007 09:40

#7 Post by majdak » 14 Sep 2007 10:22

You can not connect both LCD and GLCD on the development board because they share
communication line. Remove LCD. Also remove jumpers from AD converter inputs.
Put all ports jumpers to pull-down position.
Enable Rx, Tx, RTS and CTS on RS232-B. You can find these switchs on SW3.

Reverant
Posts: 13
Joined: 11 Jul 2007 10:38

#8 Post by Reverant » 14 Sep 2007 10:38

Per your instructions:

1) I removed the text LCD
2) I removed the jumpers from J18 and J19 (ADC)
3) I placed all the jumpers for port A - port G to PULL DOWN.
4) All the switches on DIP switch SW3 were already ON.

It still does not work, I get the same results as before.

majdak
mikroElektronika team
Posts: 28
Joined: 28 Jun 2007 09:40

#9 Post by majdak » 19 Sep 2007 12:28

Here is right settings of USART terminal and AVRFlash for your project :

Image
Image

Reverant
Posts: 13
Joined: 11 Jul 2007 10:38

#10 Post by Reverant » 19 Sep 2007 12:33

Thanks, I had External Clock instead of External RC Oscillator!

Post Reply

Return to “mikroBasic for AVR General”