4 Wire SPI with Shiftin/Shiftout ?


+ Reply to Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Feb 2013
    Posts
    853

    Default 4 Wire SPI with Shiftin/Shiftout ?

    Hello.
    I'm trying to connect GT21L16S2Y Font ROM IC to PIC16F886.
    I have soldered connections, but have not written code yet, because this chip has separate IN/OUT pins for SPI.

    Below is the draft code which I think should work (have not tried it yet).

    Code:
    SCLK	VAR	PORTB.5 'CLOCK
    TC	VAR	PORTC.0 'TO CHIP - WRITE
    FC	VAR	PORTC.6 'FROM CHIP - READ
    RST	VAR	PORTB.4 'RESET
    I VAR BYTE 'COUNTER VAR
    X VAR BYTE 'TEMP VAR
    FONT VAR BYTE [8] 'FONT ARRAY
    
    
    
    
    
    
    Reader: 'Font reading outline
    LOW RST         ' Ready for transfer
       Shiftout TC, SCLK, 5, [$03,$0] ' Send write command, set start offset 
    For I=0 to 7 'read 8 bytes of data
       Shiftin FC, SCLK, 5, [x]
    FONT[I]=X 'WRITE TO ARRAY
    next
    HIGH RST        ' Reset IC
    Return
    And here is screenshot from the datasheet. It is in chinese, but diagrams show things clearly.

    So I'm on the proper way or not?

    Name:  GTL.jpg
Views: 136
Size:  419.7 KB

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,413


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    I have soldered connections, but have not written code yet, because this chip has separate IN/OUT pins for SPI.
    Of course they have separate in/out pins, that's how SPI works.

    So I'm on the proper way or not?
    I think so. But for starters, looking at the image you posted you should send an 8 bit command followed by a 24 bit address (32bits in total), you're only sending 16.

  3. #3
    Join Date
    Feb 2013
    Posts
    853


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    Well, MAX7219, DS1302 we use only 3 pins.
    Yes, I'm missing two more bytes there, will add them later and post back

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,413


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    The MAX7219 is not capable of outputting any data, therefor no data out pin.
    DS1302 might work with SHIFTIN/SHIFTOUT but its interface isn't really SPI.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    So I'm on the proper way or not?
    not. the shiftout shiftin commands leave the clock line high on completion{mode 5} so when you swap between them the slave device will see
    a false rising edge and you lose a data bit .

    nearly all respectable pic16/18 chips have a mssp module why not just use it ?
    or write a bit banger to suit

    Well, MAX7219, DS1302 we use only 3 pins
    which are not spi anyway , its a stupid argument
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  6. #6
    Join Date
    Feb 2013
    Posts
    853


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    Yes, I tried with mode 5 and it does not works, it also does not works with mode 4 or others.
    MSSP or whatever it is, might be good, but are there direct support statements in PBP ?
    And also, I already have pre-wired devices and they're meant to be in that way.

    The code below does not works - it returns all 255.

    Code:
    ;----[16F886 Hardware Configuration]--------------------------------------------
    #CONFIG
    cfg1 = _INTRC_OSC_NOCLKOUT    ; INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
    cfg1&= _WDT_ON                ; WDT enabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; RE3/MCLR pin function is digital input, MCLR internally tied to VDD
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _CPD_OFF               ; Data memory code protection is disabled
    cfg1&= _BOR_OFF               ; BOR disabled
    cfg1&= _IESO_ON               ; Internal/External Switchover mode is enabled
    cfg1&= _FCMEN_ON              ; Fail-Safe Clock Monitor is enabled
    cfg1&= _LVP_OFF               ; RB3 pin has digital I/O, HV on MCLR must be used for programming
    cfg1&= _DEBUG_OFF             ; In-Circuit Debugger disabled, RB6/ICSPCLK and RB7/ICSPDAT are general purpose I/O pins
      __CONFIG _CONFIG1, cfg1
    
    
    cfg2 = _BOR40V                ; Brown-out Reset set to 4.0V
    cfg2&= _WRT_OFF               ; Write protection off
      __CONFIG _CONFIG2, cfg2
    
    
    #ENDCONFIG
    
    
    
    
    'chip configs
    TRISA=%01000000  'SET A TO OUTPUT   1=input
    TRISC=%00000000   'set half C for in/out
    TRISB=%00000000   'set PortB to output
    ANSELH=%00000000   ' ADC OFF B
    ANSEL=%000000000 'configure PortA as digital except first 2
    ADCON1=%10000000  'adc justify
    OSCCON=%01110101  'SET FREQUENCY TO 8MHZ
    WPUB=%00000000    'turn off Pullups
    CM1CON0=0         'DISABLE COMPARATORS
    CM2CON0=0         'SAME HERE
    
    
    DEFINE OSC 8   
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    'lcd config
    pause 10
    ' Set LCD Data port 
    DEFINE LCD_DREG PORTC  
    DEFINE LCD_DBIT 4  
    DEFINE LCD_RSREG PORTB  
    DEFINE LCD_RSBIT 0  
    DEFINE LCD_EREG PORTB  
    DEFINE LCD_EBIT 1  
    DEFINE LCD_BITS 4  
    DEFINE LCD_LINES 2  
    DEFINE LCD_COMMANDUS 1500  
    DEFINE LCD_DATAUS 44
    
    
    
    
    SCLK	VAR	PORTB.5 'CLOCK
    TC	VAR	PORTC.0 'TO CHIP - WRITE
    FC	VAR	PORTC.6 'FROM CHIP - READ
    RST	VAR	PORTB.4 'RESET
    I VAR BYTE 'COUNTER VAR
    X VAR BYTE 'TEMP VAR
    FONT VAR BYTE [8] 'FONT ARRAY
    
    
    Reader: 'Font reading outline
    LOW RST         ' Ready for transfer
       Shiftout TC, SCLK, 5, [$03,$100,$00,$0] ' Send write command, set start offset 
    For I=0 to 255 'read 8 bytes of data
       Shiftin FC, SCLK, 5, [x]
    LCDOUT $fE, $C0, DEC I,32, DEC X
    Pause 200
    next
    HIGH RST        ' Reset IC
    GOTO READER

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,413


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    I'd try mode 5 for SHIFTOUT and mode 6 for SHIFTIN.
    I would also add some code to make sure #CS is high for a while during startup. Then I would add a scope or logic analyzer to verify that what you think is happening is actually happening at the hardware level.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    I'd try mode 5 for SHIFTOUT and mode 6 for SHIFTIN.
    You can learn something everyday
    that seems to work with spi 25aa1024 eeprom
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  9. #9
    Join Date
    Feb 2013
    Posts
    853


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    Shiftout 6 changed nothing, so will hook up scope in logic analyzer mode and report.

  10. #10
    Join Date
    Feb 2013
    Posts
    853


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    Hooked scope to pins.
    There is series of pulses on SCLK and RST gets high and low as specified.
    However, there is no activity on serial input/output lines.
    To check the wiring, I wrote this simple code:

    Code:
    krd:
    high sclk
    high tc
    high rst
    high fc
    pauseus 500
    low sclk
    low tc
    low rst
    low fc
    pauseus 500
    goto krd
    And it works fine - I can see square pulses with scope on each pin, so there are no wiring issues.

    Any ideas?

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,413


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    One issue might be the fact that you have LCD datapins overlapping at least one of the pins that you're using with SHIFTIN/SHIFTOUT.
    This code does not match comment: TRISC=%00000000 'set half C for in/out.
    Also, note that my suggestion was to try mode 6 on SHIFTIN - not SHIFTOUT. Not that it would make any difference untill SHIFTOUT is outputting data.

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    not to mention. a 32bit address attempt ?

    Reader: 'Font reading outline
    LOW RST ' Ready for transfer
    Shiftout TC, SCLK, 5, [$03,$100,$00,$0] ' Send write command, set start offset
    For I=0 to 255 'read 8 bytes of data
    Shiftin FC, SCLK, 5, [x]
    LCDOUT $fE, $C0, DEC I,32, DEC X
    Pause 200
    next
    5.75 SHIFTOUT
    SHIFTOUT DataPin, ClockPin, Mode, [Var{\Bits}...]
    Synchronously shift out Var on ClockPin and DataPin. ClockPin and DataPin may be a constant, 0-15, or a variable that contains a number 0-15 (e.g. B0) or a pin name (e.g. PORTA.0).
    SHIFTOUT is a software-based command and does not require that the target device have synchronous serial capability. The ClockPin and DataPin parameters may be set to any digital I/O pins, and may be different in different commands within the same program.
    \Bits optionally specifies the number of bits to be shifted out. If it is not specified, 8 bits are shifted out, independent of the variable type. The Bits shifted out are always the low order bits, regardless of the Mode used, LSB or MSB. Up to 32 Bits can be shifted out of a single (long) variable. If more than 32 Bits are required, multiple variables or constants may be included between the square brackets.
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  13. #13
    Join Date
    Feb 2013
    Posts
    853


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    OK I moved these ports to C0 and C1.

    SCLK VAR PORTB.5 'CLOCK
    TC VAR PORTC.1 'TO CHIP - WRITE
    FC VAR PORTC.0 'FROM CHIP - READ
    RST VAR PORTB.4 'RESET

    Set all ports to output, except FC, which is set as input.

    And I don't get, what's wrong with $100 ?
    I'm sending 3 bytes, that's 24 bits.

  14. #14
    Join Date
    Feb 2013
    Posts
    853


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    It still does not works.
    I removed all LCD code
    I mapped output to different port - still can't capture anything with scope.
    And there are no issues with hardware - setting these pins high-low works perfectly.
    So it seems like shiftout not working?

  15. #15
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,413


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    Yes, you're sending 3 bytes (four atually if you count the command byte ($03)) but what Richard is saying is that $100 does not fit within a byte and according to the manual it will then get truncated to 8bits so in effect your shiftout statement send 3,0,0,0. Are you SURE you don't see a short pulse on the FC-pin? Try
    Code:
    DoIt:
      LOW RST
      SHIFTOUT TC, SCLK, 5, [$AA,$AA,$AA,$AA]
      HIGH RST
      Pause 2
    Goto DoIt
    Set the scope to trig on the falling edge of RST.

  16. #16
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    And I don't get, what's wrong with $100 ?
    how big is the biggest number that can be represented in a byte ?


    Code:
    Shiftout TC, SCLK, 5, [$03,$100,$00,$0] ' Send write command, set start offset
    an attempt to read from address 0x1000000 a non valid 25 bit address, except that shiftout will send address of 0x00 since the 8 bit default not over written

    maybe [3,1,0,0] or [3,100,0,0] or [3\8,$100\16,0\8] or [3,$100\16,0]
    Last edited by richard; - 10th November 2021 at 05:55.
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  17. #17
    Join Date
    Feb 2013
    Posts
    853


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    Guys, issue is different - shiftout does not output any data on data pin. So for sure, there will be nothing to read with shiftin.
    This is the issue.

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    should we just guess about the new connections and code ?
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  19. #19
    Join Date
    Feb 2013
    Posts
    853


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire SPI with Shiftin/Shiftout ?

    The code is posted above and connections are clearly seen from there and described

    took brand new all parts, will try on breadboard later

Similar Threads

  1. porta problems during shiftout/shiftin
    By eccessivo in forum Serial
    Replies: 2
    Last Post: - 19th July 2013, 19:00
  2. Shiftout - shiftin question
    By Lasse1 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th April 2010, 16:34
  3. 16f877A and shiftin shiftout
    By ghdsfier8 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd February 2008, 13:47
  4. shiftout and shiftin
    By Ron Marcus in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th April 2006, 15:01
  5. Shiftin/Shiftout
    By paul.mcallister in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th May 2005, 04:24

Posting Permissions

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