I cannot get SPI to work using the examples in Documentation ves 9.8
I originally started a post called "SPI Digital Pins what are they" but SPI does not work seems more appropriate.
If I try to convert a Mega328P SPI example for PIC16f887, I can get it to compile but then PICKit2 complains that configuration is wrong and shows "Data Protect" greyed out.
I've tried various permutations of SPITransfer on a Program that works with a different compiler.
A sample program from MMotte also works see
The attached code as 3 variations of SPItransfer all flag up errors
The original code is also at "SPI Digital Pins what are they"
1) There are no SPI examples for any PIC MIcrocontrollers. If there are any, they are not in the SPI folder.
2) It would probably not be a very good idea to try to use the AVR (Arduino) SPI demo as a template for PIC considering that it is specific to Arduino by using "digital_X" nomenclature rather than "Port.pin". This is also a somewhat advanced demo, showing use of both hardware SPI (HWSPI.h) as well as bit-banged SPI (provided in subroutines in the Demo source code. It seems we have no straight forward and simple demo for HWSPI anywhere.
3) In your case, rather than try to convert an Arduino demo to PIC, I would suggest starting from scratch, using the HELP as a guide. (disregarding the Arduino specific stuff)
Are you actually asking for help getting your code working or rather pointing out a problem?
If you want help then please be as specific as possible. What device are you wanting to connect to your PIC 18F877? ShaIl we assume that you want to use hardware SPI as opposed to software (bit-banged ?
What is the "different compiler" you are refering to? (You will not be tortured or excommunicated for naming a different compiler here)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Wiliam
I did give up on trying to convert M328P and started from scratch.
I apologise for opening 2 threads, but "SPI Digital Pins what are they" didn't seem to explain my current problems.
Mmotte has made a suggestion on the other thread that I'll try.
I can't see any referance to soft SPI in GCB. Also most of the examples are for M328P.
I have used M328P but I've had too many "sponaneous" can't find chip ID when programming them so I switched back to PIC. OK 32K sounds good but the biggest program I ever wrote was less than 8K so 24K going to waste.
The other compiler is Oshonsoft. Here's another odd one I tried Proton Basic (Free) last night, that has a Max7219/21 code example. It didn't work either.
I find most code examples are to clever i.e. complcated. Often coders include counters or other types of calculation to show what can be done, but for me that's just an extra level of complication to unravel. Oshonsoft is especially bad for that.
Sometimes I can't even understand what the code is trying to do let alone deciphering the code.
I won't ask for more help until I've checked out what MMotte has given me.
But to answer the question "Are you actually asking for help getting your code working or rather pointing out a problem? "
Both I would say. I use SPI quite alot so when evaluating a potential new compiler I usually try out SPI by converting known working code into the new compiler. If I can't get it to work relatively easily I move on.
There seems to have been a big shift in GCB to Arduino based stuff, PIC has almost disappeared. I'm not biased one way or the other, I chose my chips to suit my application.
OK I'm fixed thanks. Using PORTA.5 for CS/Load instead of PortD.3 seems to be the major discovery. Why is another question.
Just Checked the 16f886/7 DS and SS is shown as RA5 but rather strangely RA4 will work too!!!
Last edit: David Thompson 2017-10-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot get SPI to work using the examples in Documentation ves 9.8
I originally started a post called "SPI Digital Pins what are they" but SPI does not work seems more appropriate.
If I try to convert a Mega328P SPI example for PIC16f887, I can get it to compile but then PICKit2 complains that configuration is wrong and shows "Data Protect" greyed out.
I've tried various permutations of SPITransfer on a Program that works with a different compiler.
A sample program from MMotte also works see
The attached code as 3 variations of SPItransfer all flag up errors
The original code is also at "SPI Digital Pins what are they"
Last edit: David Thompson 2017-10-08
1) There are no SPI examples for any PIC MIcrocontrollers. If there are any, they are not in the SPI folder.
2) It would probably not be a very good idea to try to use the AVR (Arduino) SPI demo as a template for PIC considering that it is specific to Arduino by using "digital_X" nomenclature rather than "Port.pin". This is also a somewhat advanced demo, showing use of both hardware SPI (HWSPI.h) as well as bit-banged SPI (provided in subroutines in the Demo source code. It seems we have no straight forward and simple demo for HWSPI anywhere.
3) In your case, rather than try to convert an Arduino demo to PIC, I would suggest starting from scratch, using the HELP as a guide. (disregarding the Arduino specific stuff)
Are you actually asking for help getting your code working or rather pointing out a problem?
If you want help then please be as specific as possible. What device are you wanting to connect to your PIC 18F877? ShaIl we assume that you want to use hardware SPI as opposed to software (bit-banged ?
What is the "different compiler" you are refering to? (You will not be tortured or excommunicated for naming a different compiler here)
Hi Wiliam
I did give up on trying to convert M328P and started from scratch.
I apologise for opening 2 threads, but "SPI Digital Pins what are they" didn't seem to explain my current problems.
Mmotte has made a suggestion on the other thread that I'll try.
I can't see any referance to soft SPI in GCB. Also most of the examples are for M328P.
I have used M328P but I've had too many "sponaneous" can't find chip ID when programming them so I switched back to PIC. OK 32K sounds good but the biggest program I ever wrote was less than 8K so 24K going to waste.
The other compiler is Oshonsoft. Here's another odd one I tried Proton Basic (Free) last night, that has a Max7219/21 code example. It didn't work either.
I find most code examples are to clever i.e. complcated. Often coders include counters or other types of calculation to show what can be done, but for me that's just an extra level of complication to unravel. Oshonsoft is especially bad for that.
Sometimes I can't even understand what the code is trying to do let alone deciphering the code.
I won't ask for more help until I've checked out what MMotte has given me.
But to answer the question "Are you actually asking for help getting your code working or rather pointing out a problem? "
Both I would say. I use SPI quite alot so when evaluating a potential new compiler I usually try out SPI by converting known working code into the new compiler. If I can't get it to work relatively easily I move on.
There seems to have been a big shift in GCB to Arduino based stuff, PIC has almost disappeared. I'm not biased one way or the other, I chose my chips to suit my application.
OK I'm fixed thanks. Using PORTA.5 for CS/Load instead of PortD.3 seems to be the major discovery. Why is another question.
Just Checked the 16f886/7 DS and SS is shown as RA5 but rather strangely RA4 will work too!!!
Last edit: David Thompson 2017-10-09