Hot!Please help with most basic c code for spi slave read of pic16f690 to pic16f690

Author
brian@1234
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2010/06/21 13:01:41
  • Location: 0
  • Status: offline
2017/10/06 09:30:42 (permalink)
0

Please help with most basic c code for spi slave read of pic16f690 to pic16f690

Hello all,
 
I've read tons of forums and changed my code so many times now that I can't keep track anymore.  I'd really appreciate if somebody could look at my master and slave code for my pic16f690 spi communication.  I've confirmed the master clock and data going into the slave appear correct, but my slave pic can't read the data from SSPBUF to LCD (NHD-0420D3Z-NSW-BBW-V3).  I feel its got to be novice mistake.  Thanks so much in advance to anybody that can help!
#1

3 Replies Related Threads

    mbrowning
    Just a Member
    • Total Posts : 603
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Please help with most basic c code for spi slave read of pic16f690 to pic16f690 2017/10/06 12:12:12 (permalink)
    0
    There are no config bit settings - default is external RC oscillator, but you set IRCF bits to divide internal oscillator by 4 (2MHz) but comment says 4MHz.
     
    Main problem is spi_write and spi_read never check the BF bit.
    spi_write should check that BF=0 before writing the next byte to prevent collisions. Clearing the WCOL bit is not sufficient.
    spi_read should check that BF=1 to see if data has been received. Otherwise it just reads whatever garbage is in the shift register.
     
    Also, with SPI it's best to use chip select (SS) so ensure synchronization between tx and rx.
     
    Lots of errors in comments not matching the code.
     
     

    Can't remember. I've slept since then - Mark
    #2
    brian@1234
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2010/06/21 13:01:41
    • Location: 0
    • Status: offline
    Re: Please help with most basic c code for spi slave read of pic16f690 to pic16f690 2017/10/06 17:08:33 (permalink)
    0
    I appreciate the feedback.  Like I said I changed the code around allot so comments and other stuff is going to be off.  I've started working with the code as you suggested, but am still having problems.  I'll sleep on it tonight and hopefully figure it out tomorrow.  Plan to post working code for any other novices; hopefully preventing similiar reposts.
     
    thanks,
    Brian
    #3
    brian@1234
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2010/06/21 13:01:41
    • Location: 0
    • Status: offline
    Re: Please help with most basic c code for spi slave read of pic16f690 to pic16f690 2017/10/14 12:19:42 (permalink)
    0
    Any idea why adding the master clock to slave would disable the slave pic.  The attached slave code outputs RC2 until I add master clock.  I then have to disconnect clock and redownload the program into the slave to get RC2 to output.
    #4
    Jump to:
    © 2017 APG vNext Commercial Version 4.5