EEPROM write with USB


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: EEPROM write with USB

    Quote Originally Posted by Demon View Post
    Just make sure you don't have a big pause after USB started, probably going to lose connection.

    Robert
    I should have mentioned that my USBSERVICE is interrupt driven so PAUSE does not matter.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jun 2011
    Posts
    19

    Default Re: EEPROM write with USB

    Ok, I finally have it somewhat working. I can now read my variables, I can read what's programmed into the eeprom. The only problem is when I send values to my eeprom in my write loop it only programs the value of "50" to the memory. What am I missing?

    Code:
    ' program for pic18f14k50
    '                     u = Program EEPROM
    '                    k = Dump EEPROM
    '                     f = verify connection
    '                     c = send last I/O values to PC
     Include "cdc_desc.bas" ' Include the HID descriptors
     Define  OSC     48
     Define  ADC_BITS 10
     Define  ADC_clock 6
     Define  ADC_sampleus 3
    ' initial EEPROM values (output = input)
    DATA WORD 0,WORD 16,WORD 32,WORD 48,WORD 64,WORD 80,WORD 96,WORD 112,WORD 128
    DATA WORD 144,WORD 160,WORD 176,WORD 192,WORD 208,WORD 224,WORD 240,WORD 256
    DATA WORD 272,WORD 288,WORD 304,WORD 320,WORD 336,WORD 352,WORD 368,WORD 384
    DATA WORD 400,WORD 416,WORD 432,WORD 448,WORD 464,WORD 480,WORD 496
    DATA WORD 512,WORD 539,WORD 566,WORD 593,WORD 620,WORD 647,WORD 674,WORD 701,WORD 727
    DATA WORD 754,WORD 781,WORD 808,WORD 835,WORD 862,WORD 889,WORD 916,WORD 943
    DATA WORD 970,WORD 997,WORD 1024,WORD 1024,WORD 1024,WORD 1024,WORD 1024,WORD 1024
    DATA WORD 1024,WORD 1024,WORD 1024,WORD 1024,WORD 1024,WORD 1024,WORD 1024
    DATA WORD 1024
    EEPROM 230, [254,0,210,0,190,0,100,0,60,0,40,0,30,0,0,0] 'temp out table word size ohm out values
    'eeprom 244, [147,147,130,130,125,125,125,120,120,115,115,115,115,115,115,115] 'desired afr table
    'eeprom 250, [122,0] 'displacement scalar
    'eeprom 252, [ 50] 'min load for auto tune
    eeprom 253, [ 64] 'tube size  scalar  tube area
    eeprom 255,[ 254] 'autotune check bit
     
    EWRITE var byte
    EPROMDUMP var byte
    BUFFER Var Byte[16]
    CNT Var Byte[16]
    MAFIN var word      ' 10 bit a/d input value
    MAFOUT var byte[6]  ' string for usb debugging
    OUTPUTVAL VAR WORD  ' output value to DAC
    TEMPVAL VAR WORD    ' input temporary
    TABLEHIGH VAR WORD  ' high table value
    TABLELOW VAR WORD   ' low table value
    TEMPVAL2 VAR WORD   ' input temporary #2
    FLOW var word       ' flow value from input lookup table
    inputtable con ext
    MAFSCALAR var word  ' scalar for input flow value correction
    FLOWINVAL var word  ' output temporary
    FLOWINVAL2 var word ' output temporary #2
    FLOWFINAL var word  ' flow value after mafscalar correction
    ACTION var byte
    CHAR var byte
    inbyte var byte
    X var byte
    TRISC = %11000000 'make port c6,7 input make port c 012345 input
    ADCON2 = %10000000
    
    ANSELH = %00000010
    
     USBInit   ' Get USB going
     HIGH PORTC.2      ' Serial D-A chip select off
     
    startloop:
     
    
     goto overdata
    '0-5v input sensor transfer function in 2.9 tube adc counts to flow
    asm
    inputtable
     DW 0, 0, 0, 0, 0, 7, 12, 16, 20, 24, 28, 33, 39, 45, 53, 62, 72, 83, 94, 107
     DW 121, 136, 152, 169, 188, 208, 229, 252, 277, 304, 332, 363, 395, 430, 468
     DW 507, 549, 594, 641, 691, 743, 798, 855, 915, 977, 1043, 1110, 1181, 1255
     DW 1331, 1410, 1493, 1579, 1668, 1761, 1858, 1960, 2065, 2175, 2289, 2408, 2532
     DW 2659, 2791, 2925, 2925
    endasm
    overdata:
     usbservice
    doloop:
           inbyte = 1
           USBin 3, action, inbyte, doloop2        ' Get a char from serial port
    verify:
           IF action = 102 THEN   ' Verify connection
           USBout 3, action, 1, verify
           ENDIF    ' end of verify action
           IF action = 117 THEN  ' Write EEPROM
           
           X = 0
    writeloop:
          USBSERVICE
          USBin 2, EWRITE, inbyte, writeloop
          
          WRITE X, EWRITE
          USBout 2, EWRITE, 1, writeloop
          X = X+1
          IF X < 10 THEN writeloop   ' this will get changed to 255 when it works.
    USBSERVICE
          
          
           ENDIF ' end of Write action
    valuesout:
           IF action = 99 THEN    ' Return last input and output
           USBout 3, mafout, 6, valuesout
           ENDIF ' end of IO action
           IF action = 107 THEN   ' Dump EEPROM
           X = 0
    dumploop:
           
      FOR X = 1 TO 20      'this will get changed to 255 to dump the whole eeprom when it all works
        READ X, epromdump
        USBOut 3, epromdump, 1, dumploop
     pause 100
     usbservice
            NEXT
     ENDIF
    
         
    tlabel6:
         
         
         '  ENDIF ' end of Dump action

  3. #3
    Join Date
    Jun 2011
    Posts
    19

    Default Re: EEPROM write with USB

    Any ideas?

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts