further testing showed that when sequences of commands to do read and writes over multi sectors , the the busy_chk routine requires to be checked not just for writes , but also for reads

if a read is done during a cycle of a sector erase,write , the read is not done at all

as such the code changed to

Code:

  Flash_Comand:
  ' assumes SDC_address long
  ' assumbe data_Length = Lookup table to fill 
  ' max 256 bytes per write 
  ' erase of the sector by byte  / bulk is needed prior to write , as a write only changes a 1 to 0 , and the erase chanse the 0 to 1 
   if  SDC_cmd = 0 then return           ' invalid command if value =0 
   
   Lookup SDC_cmd,[$00,$01,$02,$D8,$C7,$B9,$9E,$03,$0B,$9F,$AB],SDC_CmdCode ' asignes command code to flash chip  
  
      Flash_tmp = 0                        ' ensure 0 - counter for busychk loop
      gosub BSY_chk                        ' do for all commands 
            
     if SDC_cmd <=4 then                   ' do for writes, sector erase,bulk erase , write reg protect 
        FLASH_CE = 0                       ' Bring the FLASH chip select line low.
 	    SDC_data_out = Flash_Wr_en         ' Send  command byte that requires a write 
        Gosub Flash_spiw	               ' Write Byte SDC_data_out. , subroutine writes a byte on the SPI bus
   	    FLASH_CE = 1                       ' Bring the FLASH chip select line high to complete the write command 
 	    pauseus 1                          ' pause between prev command  - may not need 
     endif
	
     FLASH_CE = 0                          ' Bring the FLASH chip select line high to complete the write command 
     SDC_data_out =  SDC_CmdCode           ' Send the  command byte,
 	Gosub Flash_spiw	                   ' Write Byte SDC_data_out. , subroutine writes a byte on the SPI bus
    
     if SDC_cmd =>2 and SDC_cmd <=3 or _    ' if commands 2= Page write 3= Sector Erase,
        SDC_cmd =>6 and SDC_cmd <=8 then    ' or 6=Signature read( 3 dummybytes)  7= read data normalspeed or 8 read data at Highspeed then set given address 
          SDC_data_out = SDC_address.Byte2     ' set sector Address 0 to 15 for 8mb chip
 	      Gosub Flash_spiw		               ' Write Byte SDC_data_out.
 	      SDC_data_out = SDC_address.Byte1     ' set page address 0 to 255  
 	      Gosub Flash_spiw	                   ' Write Byte SDC_data_out.
 	      SDC_data_out = SDC_address.Byte0     ' set byte address 0 to 255
          Gosub Flash_spiw		               ' Write Byte SDC_data_out.
          if SDC_cmd = 8 then                  ' read High speed mode 
             SDC_data_out = $FF                ' used as dummy byte  for read High speed mode 
             Gosub Flash_spiw		           ' Write Byte SDC_data_out.
          endif
      endif
    
      if SDC_cmd <=2 or _                        ' if commands 1= write Register , 2= Page write , 
         SDC_cmd >=6 and SDC_cmd <= 9 then       ' or 6= read signature byte, 7=read data normalspeed, 8= read data at Highspeed , 9=read ID    
                 
          For SDC_index = 0 To Data_Length 
              if SDC_cmd <= 2 then                       ' if write or Write register then 
                 SDC_data_out = SDC_buffer[SDC_index]    ' send contents of indexed SDC_buffer 
                 gosub  Flash_SPIw  	                 ' write byte SDC_data_in from SPI bus.  Returns SDC_data_in.
              endif
            
              if SDC_cmd =>6 and SDC_cmd <=9 then       ' if 6= read signature byte, 7=read data normalspeed, 8= read data at Highspeed , 9=read ID
                 gosub  Flash_SPIR  	                 ' Read Byte SDC_data_in from SPI bus.  Returns SDC_data_in.
 	             SDC_buffer[SDC_index] = SDC_data_in
              endif
          Next SDC_index
      endif
    
     FLASH_CE = 1                          ' Bring the FLASH chip select line high.

  return
'----------------------------------------------------
 Bsy_chk:
        FLASH_CE = 0                                ' Bring the FLASH chip select line low  
        SDC_data_out = Flash_Rd_reg                 ' Send the read status register command byte
 	    Gosub Flash_spiw	                        ' Write Byte SDC_data_out. , subroutine writes a byte on the SPI bus 
        Flash_tmp = 0                               ' clear counter                  
       while  Flash_tmp <150                         '  loop test read        
         gosub Flash_SPIR  	                         ' Read Byte SDC_data_in from SPI bus.  Returns SDC_data_in.
         IF FLASH_Install = 1 then 
           Flash_Reg_val  = SDC_data_in               ' get value of read status reg value for use in flash install program checks for protection 
           HSEROUT ["STATUS REG = ",hex Flash_Reg_val,13,10]  ' show on terminal when doing flash install 
           HSEROUT ["Flash_tmp = ",dec2 Flash_tmp,13,10]     
         endif 
         Flash_tmp = Flash_tmp + 1 
         SDC_data_in =  SDC_data_in & $01 
        if SDC_data_in = 0 then Flash_tmp = 151   ' Test bit 1 if write not busy,force exit of loop
       wend                  
      
       FLASH_CE = 1                                    ' Bring the FLASH chip select line high
 return