Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: ARM registers changed unexpectedly???
PostPosted: Sat Jan 24, 2009 9:51 am 
Offline

Joined: Fri May 30, 2008 5:18 am
Posts: 4
I am currently running my code from the internal flash of a AT91SAM7SE512, I have written the code in assembly language. I have done some progress however I got stuck in this weird behavior. In the code snippet below, I'm trying to send a stream of characters in the serial port(using register r4 as buffer for my data to send). The first character seemed to be successfully sent but somehow the next characters are not sent. But if I placed the "ldr r2, =UART0" inside the loop, it works well. So I'm thinking the r2 must have been messed up(even though I'm not using this register inside the loop), is this possible? Is it possible that some registers(r0-r12??) change even if not modified by my code?
Is there some initialization procedure that I missed that gives this behavior(the rest of my code involves clock setup and UART setup only)?


ldr r2, =UART0
SendAgain:
str r4, [r2, #UART0_THR]
WaitTHR:
ldr r1, [r2, #UART0_CSR]
ldr r5, =0x1A1A
and r1, r1, r5
cmp r1, r5
bne WaitTHR
...
...
[Getting data from memory to write to register r4]
[Storing new values for r4 here]
...
...
b SendAgain


Thanks


Top
 Profile  
 
 Post subject: Re: ARM registers changed unexpectedly???
PostPosted: Thu May 21, 2009 6:08 pm 
Offline

Joined: Sat Feb 02, 2008 11:35 pm
Posts: 15
Location: USA
1). You're starting a 32bit word in r4 to register THR but datasheet shows some of the upper bits are used for other purposes with the lower byte as transmit data,

str r4, [r2, #UART0_THR]

should be:

strb r4, [r2, #UART0_THR]

Unless you really don't care what you're storing.

2). You bitfield mask includes receive conditions aswell as transmit, check out the status register bits, ensure you're just waiting on transmit - assuming you didn't want to know about receiver.

As a side note, you're using the zero flag with the AND operation and so the CMP is redundant, i.e.

ands r1, r1, r5
bne WaitTHR

will do.

dc


Top
 Profile  
 
 Post subject: Re: ARM registers changed unexpectedly???
PostPosted: Sun Jan 31, 2010 4:37 pm 
Offline

Joined: Sat Jan 30, 2010 2:31 am
Posts: 1
Quote:
Is it possible that some registers(r0-r12??) change even if not modified by my code?

The same thing with the AT91SAM7SE512. Not used register (R4 in my case), suddenly changes to value 0xFFFFFFFC. I think, it connected with entering to interrupt handler. With the debugger, I see that before return from interrupt handler, this register normally restores from stack. Then my code (for(...) that not use R4) executes and when next interrupt happens, this register is changed.
One strange thing: If I set breakpoint on the first command of interrupt handler, trouble disappearing (someone knows, what SAM-ICE (J-Link) from Segger make with code to set breakpoint?). If breakpoint on the second command, register is already corrupted.
If I move code, effect disappearing too. (But I afraid, in this case not fixes, just hiding)
What Is It ?!
!HELP PLEASE!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: