Announcement

Collapse
No announcement yet.

SHIFTIN does not work?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SHIFTIN does not work?

    Using PIC16F1825 running using internal oscillator 32 MHz
    Hardware serial RX/TX works fine at 115.2k.
    Try to use the SHIFTIN and SHIFTOUT to interface to a SPI EEPROM.

    SHIFTOUT looks like it is working OK, from scope probing of CLK, DI and CS
    However, when using SHIFTIN, I do not see the CLK signal toggle during its shift-in period.
    I have tried several pins, options, but so far SHIFTIN does not work.

    Please see code snippet below:

    ' PORT C pin Assignment
    COLLCLK VAR PORTC.0 ' Pin 10: EEPROM CLK Output
    COLLDI VAR PORTC.1 ' Pin 9: EEPROM DI, Output to EEPROM
    COLLCS VAR PORTC.2 ' Pin 8: EEPROM CS, Output
    COLLDO VAR PORTC.3 ' Pin 7: EEPROM DO, Input to PIC

    .....

    ReadEEPROM:

    HSEROUT ["====== Beginning of CID1 EERPOM Dump ======",13,10]
    counter = 0
    DO WHILE(counter < 128)
    COLLCLK = 0
    COLLCS = 1
    SHIFTOUT COLLDI, COLLCLK, 1, [6\3] ' MSBFIRST = Mode 1
    SHIFTOUT COLLDI, COLLCLK, 1, [counter\7]
    SHIFTIN COLLDO, COLLCLK, 2, [dump] 'MSBPOST = Mode 2
    COLLCS = 0
    COLLCLK = 0
    PAUSE 4

    HSEROUT [HEX counter,":", HEX dump,13,10]

    counter = counter +1

    LOOP
    HSEROUT ["====== End of EEPROM Dump ======",13,10]

    return


  • #2
    Have you disabled the analog features (ADC and comparator) that resides on those pins?

    Comment


    • #3
      Hi Henrik,
      Yes, I have disabled the Analog and Comparator features

      ' Initialize Registers
      OSCCON = $F0 ' Set Clock to Internal 32 MHz
      CM1CON0 = 0 ' Disable Comparator Inputs
      CM2CON0 = 0 ' Disable Comparator Inputs
      ANSELA = 0 ' Disable all ADC Input
      TRISC = %00101000 ' Set up PORTC, 1 = In
      TRISA = %00011000 ' Set up PORTA

      Because I have a scope probe on the COLLCLK line, I can see that the 2 SHIFTOUT code lines work correctly.
      The SHIFTIN instruction, that follows the SHIFTOUT does not toggle the COLLCLK signal, which is the same pin that work for the SHIFTOUT.
      I also have a scope probe on COLLCS line, which also shows that it was held HIGH through out the 2x SHIFTOUT and SHIFTIN instructions.

      One more thing to note:
      I have to move the COLLCS line to PORTA.5 for it to work correctly.
      When COLLCS signal was on PORTC.2, it did not held high through out the SHIFTx period.
      It only generates a short pulse at the beginning.

      Thank you,
      P.Sanpitak

      Comment


      • #4
        not much info [snippets are usually a waste of time ]

        what eeprom ?
        what OSC speed
        and as Henrik said disable analog feature on spi pins


        most eproms need a write command sent before writing and a read command before reading
        eproms often have a 16 bit address than must be sent before write transactions begin
        most eproms want cs to be low before transaction begins
        you set COLLCS = 1 ,is that meant to be cs for eprom?
        I would doubt that you can wtite and then read a byte in the same transaction



        I would try something like this
        Code:
        write_cmd con  xxx   [read data sheet]
        read_cmd con  yyy    [read data sheet]
        address var word
        address=0
        
        COLLCS = 0
        SHIFTOUT COLLDI, COLLCLK, 1, [write_cmd, address ] ' MSBFIRST = Mode 1
        for counter =0 to 128
        SHIFTOUT COLLDI, COLLCLK, 1, [counter ] ' MSBFIRST = Mode 1
        next
        COLLCS = 1
        pause 10 ;eprom write time if req
        COLLCS = 0
        SHIFTOUT COLLDI, COLLCLK, 1, [read_cmd, address ] ' MSBFIRST = Mode 1
        for counter =0 to 128
        SHIFTIN COLLDO, COLLCLK, 2, [dump] 'MSBPOST = Mode 2
        HSEROUT [HEX2 counter,":", HEX2 dump,9
        next
        
        COLLCS = 1

        Comment


        • #5
          ANSELA = 0 ' Disable all ADC Input

          dose not do that it only disables analog function on porta

          you need
          ANSELC = 0 ;disables analog function on portc


          Comment


          • #6
            Hi Richard,

            That is it!
            ANSELC = 0 fix it.

            BTW, the EEPROM is 93LC46A (128x8bit), so there is only 7-bit address
            The code sequence has already proven to work with the BS2.
            I'm porting to PBP.

            Thank you very much for your help.

            Comment

            Working...
            X