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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/14/12 02:41
Read: times


 
#187702 - Problem writing to C8051F504 flash from firmware
Hi,

Can't seem to post on the Silabs Forum at the moment so asking here.

The EraseFlashPage function below works but the WriteFlashByte function doesn't. It seems to cause a reset. Please check my code below and help if you can.

Regards,

Bert van den Berg


Enter either function with dptr set to flash address. Accumulator=data byte for WriteFlashByte

EraseFlashPage:
		mov	VDM0CN,#0A0h	;ERASE Flash Page @ dptr.  Enable VDD monitor and high threshold
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
		mov	FLKEY,#0A5h	;Key sequence 1
		mov	FLKEY,#0F1h	;Key sequence 2
      		mov	PSCTL,#3
		mov	VDM0CN,#0A0h	;Enable VDD monitor and high threshold
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
		clr	a
   		movx	@dptr,a  
		mov	A,PSCTL
		anl	a,#11111100b	;PSWE=0, PSEE=0
		mov	PSCTL,a
		ret
;



WriteFlashByte:				;Write the byte in accumulator to flash address in dptr
		push	acc
		mov	RSTSRC,#00h	;Disable VDD monitor as a reset source
		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
		mov	FLKEY,#0A5h	;Key sequence 1
		mov	FLKEY,#0F1h	;Key sequence 2
      		mov	PSCTL,#1
		mov	VDM0CN,#0A0h	;Enable VDD monitor and high threshold
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
      		pop	acc
		movx	@dptr,a
		mov	PSCTL,#0
		inc	dptr
		ret



List of 8 messages in thread
TopicAuthorDate
Problem writing to C8051F504 flash from firmware            01/01/70 00:00      
   Some comments            01/01/70 00:00      
      C code sample from Silab website            01/01/70 00:00      
         the dog bites            01/01/70 00:00      
      Responding to Bert's and Rob's prior messages            01/01/70 00:00      
         Wow            01/01/70 00:00      
            Wow to you!            01/01/70 00:00      
   Problem solved            01/01/70 00:00      

Back to Subject List