Menu

SPI comm and SS pin

Help
2008-10-30
2013-05-30
  • Nobody/Anonymous

    A couple of Q's on the SPI commands and the hardware assumptions:

    Do the GCbasic SPI commands use the Master SSP module, or is it bit-banged out a port? If so, what are the pin assignments?

    Does Slave mode look at or require the SS pin be driven low to go into slave mode?

    How does the command handle extra clock cycles (error)?

    If the SS pin is used or read on the slave, what output is used on the master to select it? If it is used, is the direction on the master and all setup handled by the compiler or is there other work to be done first/after?

    Depending on the answers to the above, how does one address multiple slaves in GCbasic? Even if not included as part of the command, what would be suggested wiring/software suggestions? I would want to be compatible with future enhancements to the language if I have to do things 'manually'.

    Are there any problems or recommendations on using interrupts for transfers? (SSP1 ready?)

    Is the SSP1 collision interrupt (on interrupt) fired if both master and slave start clocking at the same time, or is there another condition that triggers it? What would be the suggested way to recover from such in GCbasic?

    Thanks in advance,
    Skip

     
    • Nobody/Anonymous

      Bump...

      Any suggestions? Especially on the Slave Select pin usage through GCbasic, multiple slaves (ie, recognizing it's your turn as a slave) and interrupt handling with SPI in GCbasic (peculiarities and recommendations for this specific one).

      Thanks.

       
    • Nobody/Anonymous

      Does anyone have an answer to this? I'd like to know too.

       
    • Hugh Considine

      Hugh Considine - 2008-12-24

      GCBASIC SPI commands use the SSP module in the PIC.

      SPI uses 3 wires to transmit the data - a send line, a receive line, and a clock line. If you look at the pin diagram in the datasheet for your PIC, you'll see these labelled as SDO, SDI and SCK respectively. You'll need to set up the directions of these pins manually, SDO is always output, SDI is always input, and SCK is output on the master and input on the slave/s.

      Whether or not you need slave select connected depends on what you pass to the SPIMode command (http://gcbasic.sourceforge.net/help/spimode.htm). If you run SPIMode(Slave), then you do not need to connect anything to SS. If you use SPIMode(SlaveSS), then you'll need to connect the SS pin on the slave to some pin on the master, and then turn on the pin on the master when you want that slave to communicate.

      To have multiple slaves, there are 2 options:

      (1) Connect the slaves to the master, and use slave select. Each slave has its SDI connected to the master SDO, and the slave SDO to the master SDI. Then, connect each slaves SS pin to an output pin on the master, and keep that pin turned off except when you want to talk to a particular slave.

      (2) Daisy chain the slaves. Connect the SDO of the master to the SDI of the first slave, the SDO of the first slave to the SDI of the second, and so on, finally connecting the SDO of the last slave to the SDI of the master. Each time you call SPITransfer, each slave will send its value along to the next one.

      This works because SPI always transfers a value in as it transfers a value out - for each bit it sends on the SDO, it gets a bit in on the SDI.

      Whichever method you use, you need to connect the clock pin of all the slaves to the clock pin of the master.

      I don't believe that the slave can ever transmit a clock, I'm pretty sure that only the master ever generates the clock in SPI?

      For sending the data, you need to use the SPITransfer command (http://gcbasic.sourceforge.net/help/spitransfer.htm). On a master, this will start the transmission straight away, on the slave, it will wait for the master to transfer something (ie, it will lock up your program until the master sends). The SPI code in GCBASIC doesn't use interrupts.

      Finally, sorry for taking so long to answer, I've not really been paying proper attention to this forum lately!

       
    • Nobody/Anonymous

      Thanks for getting back to this.

      Any comments on the interrupt usage and SPI in GC Basic?

      Thanks again,
      Skip

       
    • kent_twt4

      kent_twt4 - 2009-01-03

      Haven't played with the SPI, but the MSSP/SSP module is shared by both the SPI and I2C.  Look at the SSP slave I2C code here https://sourceforge.net/forum/forum.php?thread_id=1803887&forum_id=629990 to determine a similar strategy for the SPI interrupt and collision handling.  The slave module interrupt routine would attempt to send its data to the master,  if the WCOL bit is set during the process, then try again till the WCOL bit is clear.

       
  • mick

    mick - 2010-06-18

    A SPI slave can never transmit the clock. The output driver is disconnected in slave mode.

    Something else that was asked earlier: you can't have 9-bit SPI in a PIC's SPI hardware as the buffer is only 8 bits wide. While the clock runs it outputs from one end of the buffer while sending from the other, shifting the data through. Of course, it may be possible to write your own SPI system in software with whatever shift register size you like!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.