• AVR Freaks

Hot!Sending out 60bits uninterrupted with SPI

Page: 12 > Showing page 1 of 2
Author
charlieduru
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2019/03/30 11:59:21
  • Location: 0
  • Status: online
2020/03/17 17:56:15 (permalink)
0

Sending out 60bits uninterrupted with SPI

I am trying to communicate with a chip that requires 60 bits (50 hz data rate ) with SPI but SPI comes in 8,16, 32bits. i tried sending 64bits with a 16bit mode(4 consecutive transfers) but the chip seems to inteprete the wrong word, is there a way i can send data with a 60 bit clock on the PIC32?
#1

21 Replies Related Threads

    ric
    Super Member
    • Total Posts : 26943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/17 18:04:42 (permalink)
    0
    What is the device you are sending to?
    Not a WS2812?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    charlieduru
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/03/30 11:59:21
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/17 18:06:38 (permalink)
    0
    no Not that its the MS3110IC
     
     
    #3
    LostInSpace
    Super Member
    • Total Posts : 306
    • Reward points : 0
    • Joined: 2016/03/11 22:47:59
    • Location: 0
    • Status: offline
    Re: Sending out 60bits uninterrupted with SPI 2020/03/17 19:45:31 (permalink)
    4 (2)
    You could 'Bit-Bang' the output.
     
    Edit: I looked at that part and it should not care about a slight interruption in time between one 16 bit send and another.
    #1 - Make sure that the previous write is done before starting the next one.
    #2 - Make sure you have the right SPI Mode - The way I see it it needs to be mode 2 or, CPOL=0, CPHA=1
     
    post edited by LostInSpace - 2020/03/17 19:53:50
    #4
    Mysil
    Super Member
    • Total Posts : 3670
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Sending out 60bits uninterrupted with SPI 2020/03/17 22:11:36 (permalink)
    0
    Hi,
     
    PIC32 devices have 16 byte FIFO hardware buffers for both SPI transmit and receive,
    when ENHBUF is enabled.
    This should accomodate more than 60 bits without interruptions,
    but it will have to be in multiples of 8 bits, so there may have to be some padding bits.
     
        Mysil
    #5
    charlieduru
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/03/30 11:59:21
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/17 22:57:29 (permalink)
    0
    THansk for your time. Yeah i am already  4 x 16bits transfer but my concern is the last 4 bits which exceeds the 60bits limit. i feel like the chip reads it(as i dont get my desired output) and 
    i want a way to end the transaction at 60bits.
     
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 18655
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/17 23:13:52 (permalink)
    5 (1)
    Read the data sheet. Do the four dummy bits go at the beginning or the end?
    #7
    LdB_ECM
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 06:46:45 (permalink)
    5 (1)
    charlieduru
    THansk for your time. Yeah i am already  4 x 16bits transfer but my concern is the last 4 bits which exceeds the 60bits limit. i feel like the chip reads it(as i dont get my desired output) and 
    i want a way to end the transaction at 60bits.

    Yes it sees the extra bits you can't clock extra bits out
     
    So you either have to run software bit bang or send a write command follow by 3 dummy reads
    4 x 60 = 240bits
    240bits / 16bits = 15 Words
    So a write followed by 3 dummy reads can be done as 15 16 bit words on the SPI
     
    Shame it doesn't have an 8bit mode because you can do 120bits (1 write / 1 read) on 8 bit SPI.
     
     
     
    #8
    charlieduru
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/03/30 11:59:21
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 10:11:56 (permalink)
    0
    @LdB_ECM seems you got it all wrong i am looking to send 60 bits (seven - 8 bits words and one - 4bit word )literally 60 binary numbers
    and the pic 32 has an 8 bit mode just to clarify 
     
    i dont seem to understand your approach 
    #9
    charlieduru
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/03/30 11:59:21
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 10:15:33 (permalink)
    0
    @Nkurzman my point is there shouldnt be any 4 extra bits at all
     
    #10
    ric
    Super Member
    • Total Posts : 26943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 12:37:45 (permalink)
    4 (1)
    Did you try them at the start, as suggested?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #11
    NorthGuy
    Super Member
    • Total Posts : 6072
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 12:38:12 (permalink)
    4 (2)
    At 50 Hz? Bitbang it from the timer interrupt. Or transmit 56 bits then bitbang the last four.
    post edited by NorthGuy - 2020/03/18 13:04:09
    #12
    charlieduru
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/03/30 11:59:21
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 17:30:35 (permalink)
    0
    @NOrthGUy thanks kool idea. i may have to stick to bit banging as 50hz is too small to enough enough dividers to get to PBCLCK(36Mhz). do you have any snippet for a bit-banging spi code 
    Thanks in advance
    #13
    LdB_ECM
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 19:50:52 (permalink)
    0
    charlieduru
    @LdB_ECM seems you got it all wrong i am looking to send 60 bits (seven - 8 bits words and one - 4bit word )literally 60 binary numbers
    and the pic 32 has an 8 bit mode just to clarify 
     
    i dont seem to understand your approach 



    Someone said you had a 16bit SPI if you have 8bit it's easy send 120 bits instead of 60 ... two 60 bit commands at once. So you send 15 8 bit words ... which is twice your seven and a half you worked out above. If you have nothing useful to do just send the command twice or read something literally anything that needs a 60 bit command.
     
    So the eight byte out is made up of the last 4 bits of the first command and the first 4 bits of the second command.
    So you have 7 byte (56 bits) of first command 1 mix byte (4 bits for each) and 7 byte (56 bits) of last command ... that is two complete commands or exactly 120 bits.  AKA stop trying to send single commands send them as pairs.
     
    It's pretty obvious I don't get how you can't understand it ... it's called thinking outside the box.
    Now think how you would do the same thing on a 16bit SPI and go back and read my original post.
    The Least Common Multiple of 8, 60 = 120, The Least Common Multiple of 16, 60 = 240
     
    Anyhow this forum never ceases to entertain.
    post edited by LdB_ECM - 2020/03/18 20:12:41
    #14
    ric
    Super Member
    • Total Posts : 26943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 20:20:17 (permalink)
    0
    charlieduru
    no Not that its the MS3110IC

    So this device?
    http://www.ic72.com/pdf_file/m/145347.pdf
    Where does the "50 Hz" come from?
    That datasheet says the minimum clock period is 4us, so the maximum frequency is 250 kHz.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #15
    NKurzman
    A Guy on the Net
    • Total Posts : 18655
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 21:17:24 (permalink)
    5 (1)
    charlieduru
    @Nkurzman my point is there shouldnt be any 4 extra bits at all 

    My point is your peripheral manufacturer should know that most SPI masters work in chunks of 8 bits.
    #16
    LdB_ECM
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Sending out 60bits uninterrupted with SPI 2020/03/18 22:51:12 (permalink)
    5 (1)
    NKurzman
    My point is your peripheral manufacturer should know that most SPI masters work in chunks of 8 bits.

    Your point is mute it isn't an SPI bus it's a shift register like thousands of LCD chipsets it would be running alongside. Nowhere in the datasheet does it even remotely claim it's an SPI bus it describes what it is a clocked shift register. Typically it would be running from some FPGA or ASIC which may have an SPI controller (or a parrallel bus etc) driving it and the LCD controls. It would be very rare to have this hanging off an SPI bus.
     
    ric
    Where does the "50 Hz" come from?
    That datasheet says the minimum clock period is 4us, so the maximum frequency is 250 kHz.

    Reading his OP that is the frequency he wants to scan at, he can actually do 4167 at max (250,000 / 60) which is why repeating commands to use the SPI hardware is not an issue. Think about a touchpad on a laptop there is a scan rate you would poll it at same as you do with a mouse.
    post edited by LdB_ECM - 2020/03/18 23:07:03
    #17
    NKurzman
    A Guy on the Net
    • Total Posts : 18655
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/19 05:47:15 (permalink)
    0
    LdB_ECM
    Oh well never mind then.
    #18
    charlieduru
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/03/30 11:59:21
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/19 10:34:19 (permalink)
    0
    @ric for some reason i have a datasheet of different variation with different numbers will contact the manufacturer 
    Thanks for pointing that out.
    #19
    charlieduru
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/03/30 11:59:21
    • Location: 0
    • Status: online
    Re: Sending out 60bits uninterrupted with SPI 2020/03/19 10:35:44 (permalink)
    0
    @ldb_ECM well said it isnt SPI just confirmed from the manufacturer. 
     
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5