mega8515, USART problem.

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

Hello,

I'm sure this has to be an error between the programmer and keyboard but I can not figure out what I'm missing or overlooking.

I’m trying to get a mega8515 to communicate to my laptop. I wrote a simple program to transmit 0x30 to 0x7f through the USART. I the USART up for 8 data bits, 1 stop bit, and no parity. The program works on the simulator but all I receive on my laptop is a bunch of 0x00.

Here is a list of the software/hardware I am using:

STK500
Mega8515
Radio shack USB to serial converter
AVR Studio 4
Bray's Terminal

Thank you for any help you may give.

.include "m8515def.inc"

.equ Fclk = 3690000
.equ BaudRate = 9600
.equ BaudSet = (Fclk/(16*BaudRate))-1

.def temp = r16
.def Txreg = r17
.def char = r18

.cseg
.org 0

rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset
rjmp reset

reset:
ldi temp, LOW(RAMEND) ;initialize stack
out SPL, temp
ldi temp, HIGH(RAMEND)
out SPL, temp

;initialize the USART

ldi temp, 0b11111111 ;set portd for all output
out DDRD, temp

ldi temp, BaudSet ;set Baud rate
out UBRRL, temp

ldi temp, 0b00011000 ;enable tx and rx, bit2 controls character size
out UCSRB, temp ;DataSheets page 154

ldi temp, 0b00000110 ;set character size to 8bits
out UCSRC, temp ;DataSheets page 156

MeatAndPotatos:
ldi char, 48

TxChar:
sbis UCSRA, UDRE ;poll to see if TX ok
rjmp TxChar

cpi char, 128 ;tx char 48 to 127
breq Finish
out UDR, char
inc char
rjmp TxChar

Finish:
rjmp finish

Attachment(s): 

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

Kidwidget wrote:
Hello,

.equ Fclk = 3690000


Are you sure the part is running at 3.686 mhz? Unless you've change the factory fuse settings, you're running at 1mhz.

Quote:

ldi temp, LOW(RAMEND) ;initialize stack
out SPL, temp
ldi temp, HIGH(RAMEND)
out SPL, temp

Won't effect your example, but you're loading SPL twice, instead of SPL, then SPH.

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

I have the fuse bit set to :
Ext. Crystal/Resonator High Freq.;Start-up time: 1k CK + 0ms
Should I have another one seleceted?

I have changed the seconded SPL to a SPH.

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

The only other thing I see is you don't set UBRRH, the upper baudrate register.

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

Hmm, actually you do:

ldi temp, 0b00000110 ;set character size to 8bits
out UCSRC, temp ;DataSheets page 156 

You need to set URSEL to set UCSRC. This sets UBRRH instead.

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

Thanks mckenney, I've been overlooking that.

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

mckenney wrote:
Hmm, actually you do:

ldi temp, 0b00000110 ;set character size to 8bits
out UCSRC, temp ;DataSheets page 156 

You need to set URSEL to set UCSRC. This sets UBRRH instead.


That's correct. However, note that 0b00000110 is the UCSRC initial reset value so this code isn't necessary.

Don

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

Kidwidget wrote:
I have the fuse bit set to :
Ext. Crystal/Resonator High Freq.;Start-up time: 1k CK + 0ms
Should I have another one seleceted?

hi,

I have the same problem, using the same setup. This part of your discussion was not very clear to me. The stk500 comes with default fuse settings of Ext. Clock and the largest startup time. So unless you use an external crystal for your clocking, why should you change the fuse settings at all?

thanx

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

Quote:

The stk500 comes with default fuse settings of Ext. Clock and the largest startup time. So unless you use an external crystal for your clocking, why should you change the fuse settings at all?

Because a new chip is set to use ~1MHz internal oscillator.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I did what mckenney said and now the program works fine. Donblake, I didn't realize UCSRC's initail reset value was 0b00000110. Thanks for letting me know.

Agian thanks for everybodies help.