Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Rob Klein
06/14/12 07:52
Read: 570 times
Zaandam
The Netherlands


 
#187704 - Some comments
Responding to: Bert Van Den Berg's previous message
Hi Bert,

When you say "it seems to cause a reset", where exactly in the code is this reset generated and what kind of reset is it? (I *do* assume you have stepped through your code with the debugger)

Some comments:
WriteFlashByte:				;Write the byte in accumulator to flash address in dptr
		push	acc
-->		mov	RSTSRC,#00h	;Disable VDD monitor as a reset source      <-- Why, if you are going to enable it again in the very next line?
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
		mov	VDM0CN,#0A0h	;Enable VDD monitor and high threshold

WFBc:		mov	r7,#0		;Wait for VDD monitor to stabilize
		djnz	r7,$
   		mov	a,VDM0CN
   		jnb	acc.6,WFBc	;Wait for the VDD voltage to be high enough
-->		mov	RSTSRC,#02h	;Enable VDD Monitor as a reset source       <-- Superfluous, this has been done already
		mov	FLKEY,#0A5h	;Key sequence 1                             
		mov	FLKEY,#0F1h	;Key sequence 2                              > This is in the wrong order as compared to the datasheet procedure
      		mov	PSCTL,#1                                                    /
-->		mov	VDM0CN,#0A0h	;Enable VDD monitor and high threshold      <-- Superfluous, this has been done already
-->		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source       <-- That's the third time!
      		pop	acc
		movx	@dptr,a
		mov	PSCTL,#0
		inc	dptr
		ret
 


Personally, I would do it something like this:

WriteFlashByte:				;Write the byte in accumulator to flash address in dptr
		push	acc
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
		mov	VDM0CN,#0A0h	;Enable VDD monitor and high threshold

WFBc:		mov	r7,#0		;Wait for VDD monitor to stabilize
		djnz	r7,$
   		mov	a,VDM0CN
   		jnb	acc.6,WFBc	;Wait for the VDD voltage to be high enough
      		pop	acc
      		mov	PSCTL,#1
		mov	FLKEY,#0A5h	;Key sequence 1
		mov	FLKEY,#0F1h	;Key sequence 2
		movx	@dptr,a
		mov	PSCTL,#0
		inc	dptr
		ret


 



Kind regards,
Rob.

List of 8 messages in thread
TopicAuthorDate
Problem writing to C8051F504 flash from firmware      Bert Van Den Berg      06/13/12 20:41      
   Some comments      Rob Klein      06/14/12 07:52      
      C code sample from Silab website      Bert Van Den Berg      06/14/12 12:13      
         the dog bites      Erik Malund      06/14/12 14:21      
      Responding to Bert's and Rob's prior messages        Brent Wilson      06/14/12 14:37      
         Wow      Rob Klein      06/14/12 15:08      
            Wow to you!      Brent Wilson      06/14/12 16:20      
   Problem solved        Bert Van Den Berg      06/14/12 17:49      

Back to Subject List