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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Bert Van Den Berg
06/13/12 20:41
Read: 1299 times
Henderson
New Zealand


 
#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      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