Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Raspberry Pi PIC Programmer using GPIO

Thu Aug 16, 2012 11:27 am

Hello peeps!

I've been working on a programmer for Microchip PIC 8-bit microcontrollers that uses the GPIO connector and a simple hardware interface. All in all, it has reached a state where it's usable so I thought I'd write a page about it and put it online. Here's the link if you're interested: http://holdenc.altervista.org/rpp/ .

Any feedback is highly appreciated!

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: Raspberry Pi PIC Programmer using GPIO

Thu Aug 16, 2012 11:42 am

Why are you running the PIC at 5v? The circuit would be much simpler if you ran the PIC at a lower voltage.

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Thu Aug 16, 2012 11:56 am

bredman wrote:Why are you running the PIC at 5v? The circuit would be much simpler if you ran the PIC at a lower voltage.
Some commands, like "Begin Programming Only Cycle" or "Bulk Erase Setup[12]", only work in the 4.5V-5.5V voltage range for "old" devices like pic16f876 (see http://ww1.microchip.com/downloads/en/D ... 39025f.pdf , page 6). For newer devices, like pic16f628a, you can program the device at lower voltages, but all Bulk Erase operations must take place with VDD between 4.5-5.5V.
So, short answer, I had to choose 5V to be able to bulk erase the chips.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Thu Aug 16, 2012 3:54 pm

I have not tested it yet, but this is something that i will find very usefull.
Thanks for the work you put in and your write up.
I am working on bare metal stuff for the PI, i may try to port it to bare metal, as its very independent code.
Batteries not included, Some assembly required.

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Thu Aug 16, 2012 5:42 pm

DexOS wrote:I have not tested it yet, but this is something that i will find very usefull.
I'm very glad you find it useful. When you test it, I'd like to know if you found any problem with the hardware or the software. Or in general, any advice on how to improve things is always very welcome.
DexOS wrote:Thanks for the work you put in and your write up.
No worries, I will try to expand it and improve the documentation as well.
DexOS wrote:I am working on bare metal stuff for the PI, i may try to port it to bare metal, as its very independent code.
I admit my ignorance and say I don't know what that is, but I'll read up on that.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Thu Aug 16, 2012 6:28 pm

I have ordered some pic's and parts, as soon as they arrive i will test it and report back :) .
Bare metal coding is coding on the PI without linux, like you do a pic, its like coding a supper fast arduino.
See here: http://www.dex-os.com/DexBasic/DexBasic.htm

I like that your examples are in ASM, i use 100% asm in all my work, including 100% asm OS.
Batteries not included, Some assembly required.

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Fri Aug 17, 2012 11:28 am

DexOS wrote:I have ordered some pic's and parts, as soon as they arrive i will test it and report back :) .
Great! I'm looking forward to it :)
DexOS wrote:Bare metal coding is coding on the PI without linux, like you do a pic, its like coding a supper fast arduino.
See here: http://www.dex-os.com/DexBasic/DexBasic.htm
This seem very interesting, added to my list of things I want to read!
DexOS wrote: I like that your examples are in ASM, i use 100% asm in all my work, including 100% asm OS.
Yes, I must be one of the few around that only uses assembly when writing programs for the PICs... everyone seems to be using C for microcontrollers these days.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Fri Aug 17, 2012 9:47 pm

Congratulations for getting on hackaday 8-) .
http://hackaday.com/2012/08/17/raspberr ... rogrammer/
Batteries not included, Some assembly required.

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Sat Aug 18, 2012 9:10 am

DexOS wrote:Congratulations for getting on hackaday 8-) .
http://hackaday.com/2012/08/17/raspberr ... rogrammer/
Thanks! I submitted my 'hack' but I didn't think they'd publish it :D If only they would take my comment now... well for everyone interested why the octal transceiver would not work, here it is:

"When programming the PIC, CLK and DATA have Schmitt Trigger inputs, and they need a minimum input high level of 0.8*VDD, that is 4V. If you operate the 74LVC245 at 3.3V, the VOH of this transceiver (3.3V at best) isn’t enough to be recognized as a valid high level from the PIC."

I will update my page to insert this considerations about the hardware interface.

User avatar
kehribar
Posts: 3
Joined: Sat Aug 18, 2012 10:39 am
Location: istanbul
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Sat Aug 18, 2012 10:43 am

Hi,

I recently programmed an Pic24f with Rpi via the additional help from my Little Wire project.

My post: http://blog.kehribar.me/?p=171

One can easily modify this program to work with only the GPIO pins of the Rpi.

Best,
ihsan.

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Sun Aug 19, 2012 11:09 am

kehribar wrote:Hi,

I recently programmed an Pic24f with Rpi via the additional help from my Little Wire project.
Hello, I gave it a read, interesting stuff... I've never worked with the 24f family myself though. I'm sure people will find it useful.

Ok, I have updated my page with an explanation of how the hardware interface works from an "EE" point of view, and added a simple spice simulation.

Werzi2001
Posts: 2
Joined: Fri Oct 12, 2012 7:14 am

Re: Raspberry Pi PIC Programmer using GPIO

Fri Oct 12, 2012 7:19 am

Hi Holden,

i took a look at your pic programmer and i find it is a very interessting project.
It is quite surely a electronic noob question but why does the level switching (3.6V to 5V) have to be "so complicated"? I did some testing with the attached circuit using LTspice and the results looked good. Is the only problem using my circuit the invertion of the levels (0V => 5V and 3.6V => 0V) or am i missing something? The invertion of levels could be easily solved in software.

Cheers
Werzi2001
Attachments
circuit.png
circuit.png (2.95 KiB) Viewed 18290 times

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Fri Oct 12, 2012 4:06 pm

Werzi2001 wrote: It is quite surely a electronic noob question but why does the level switching (3.6V to 5V) have to be "so complicated"? I did some testing with the attached circuit using LTspice and the results looked good. Is the only problem using my circuit the invertion of the levels (0V => 5V and 3.6V => 0V) or am i missing something? The invertion of levels could be easily solved in software.
The level shifter is complicated because I chose to keep things simple in software using a non-inverting level shifting. It also makes it easy to debug the interface with a digital oscilloscope if you need to, without having to deal with the inversion. Also, I thought I would replace this simple interface with one that used an integrated circuit in the future, without changing the software.
Of course you can use the simple inverter you propose, and then invert again in software. Some considerations:
1) For the first stage composed by Q1/Q2 (which drives the CLOCK pin of the microcontroller) this should be easy, you only need to be careful in software to handle the inversion correctly.
2) If you want to use the same technique for the second stage Q3/Q4 (DATA, which is both input and output for the microcontroller) you have to choose the resistors to make sure that when DATA is an input VOHmin and VOLmax are respected according to the datasheet, and when DATA is an output the 0/5V range is converted in 0/3V.
3) For the third stage, Q5/Q6, you have the disadvantage that you need to keep the transistor on when you are not programming the chip (thus consuming, say, 1 or 2mA when your programmer is doing nothing) and turn it off when you enter Program/Verify mode. This is of course a minor thing.

I hope this answer your question. Oh, and the Raspberry Pi gpio pins work at 3.3V, not 3.6V.

ps. I noticed a small mistake in the spice simulation of the interface (the command was sent msb first, not lsb first) so I have updated the netlist and the output of the simulation on my website.

Werzi2001
Posts: 2
Joined: Fri Oct 12, 2012 7:14 am

Re: Raspberry Pi PIC Programmer using GPIO

Fri Oct 12, 2012 7:57 pm

Thanks for your considerations.
I already thought about the input/output problem and have to do some further testing to find a solution. If i try to build the programmer i quite surely will build your version first and then try to modify it just for learning purpose.

User avatar
ValterFukuoka
Posts: 94
Joined: Sat Oct 01, 2011 11:39 pm
Location: Japan
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Sat Feb 16, 2013 6:32 am

Hi,
do you think it is possible to use your method with the 16F688?

I want to ask for help here, still have trouble to find 2 numbers (parameters):
1) erase_and_program_cycle_time
2) begin_erase_programming_cycle_cmd

PIC16F688,"pic16f688",0x1000,256,3000,6000,"????",6000,0x00,0x02,0x03,0x04,0x05,0x06,"????",0x08,0x09,0x0B

Or, there are more modifications needed?

I still need to buy the 2N3906 (PNP) and then I will try to program the 16F688...

BTW, I already have a PICKIT2, just want to try your method because I think it is VERY interesting...
Thanks.

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Sat Feb 16, 2013 4:04 pm

ValterFukuoka wrote:Hi,
do you think it is possible to use your method with the 16F688?
It should be possible, yes. Try to build the hardware interface for the programmer, and the run:

Code: Select all

sudo ./rpp
You should at least be able to read the device_id.
ValterFukuoka wrote: I want to ask for help here, still have trouble to find 2 numbers (parameters):
1) erase_and_program_cycle_time
2) begin_erase_programming_cycle_cmd

PIC16F688,"pic16f688",0x1000,256,3000,6000,"????",6000,0x00,0x02,0x03,0x04,0x05,0x06,"????",0x08,0x09,0x0B

Or, there are more modifications needed?
I can try to look at the programming specification for that chip and provide a patch with the correct values in the following days. Hopefully only small modifications will be needed.
ValterFukuoka wrote: BTW, I already have a PICKIT2, just want to try your method because I think it is VERY interesting...
Thanks!

User avatar
ValterFukuoka
Posts: 94
Joined: Sat Oct 01, 2011 11:39 pm
Location: Japan
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Sun Feb 17, 2013 1:20 am

Holden wrote: I can try to look at the programming specification for that chip and provide a patch with the correct values in the following days. Hopefully only small modifications will be needed.
Thanks!
Thanks.
For the first time I am reading the "Programming Datasheets" of PICs, trying to compare what you did on the samples that already is supported so that I can understand what is needed for the new ones...

The B.O.M. of your method is very attractive (around U$0.60 for me here in Japan)...

User avatar
ValterFukuoka
Posts: 94
Joined: Sat Oct 01, 2011 11:39 pm
Location: Japan
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Mon Feb 18, 2013 10:16 am

ValterFukuoka wrote:
Holden wrote: The B.O.M. of your method is very attractive (around U$0.60 for me here in Japan)...
Oops, my mistake... that's only for the transistors and resistors... still need to account for the regulator and capacitors... lol...

tlc
Posts: 18
Joined: Mon Mar 04, 2013 10:49 am

Re: Raspberry Pi PIC Programmer using GPIO

Mon Mar 04, 2013 11:14 am

Hi Holden!

Nice piece of work - I'm going to build the electronic equipmet part in a few days and test your rpp PIC programmer. I'm looking forward to be able to program PIC devices from Raspberry... I have been always using assembler to write the code for PIC - for me this is the only way to be sure that PIC is doing precisely what I want it to do :-)
In the meantime - because I'm quite often using PIC12F629/675 - will it be possible for you to add support for those PICs into rpp, please? I have found Memory Programming datasheet at Microchip website: http://ww1.microchip.com/downloads/en/d ... 41191d.pdf
But 629/675 programming is a bit complicated - OSCCAL and BG has to be preserved:
The OSCCAL word and BG bits must be read prior to erasing the device and restored during the programming operation. OSCCAL is at location 0x3FF and the BG bits are bits 12 and 13 of the Configuration Word (0x2007).
Thanks a lot,
Tomas

saranga2000
Posts: 12
Joined: Fri Dec 14, 2012 3:42 pm

Re: Raspberry Pi PIC Programmer using GPIO

Fri Mar 08, 2013 6:40 pm

Hi,
I am trying to see if I can program a PIC16F628a based on your circuit and software. I think I have wired up everything correctly. I added 4 led's( each with a 1KOhm resistor) for debugging: 3 green led's in parallel with the Clock, Data, and VPP, and 1 yellow led in parallel with the T3/Gpio8 for read.

But when I run sudo ./rpp - the device is not recognised.

Code: Select all

 sudo ./rpp
Raspberry Pi PIC Programmer, v0.1

device_id = 0x0000
Error: unknown device or programmer not connected.
The 3 green led's blink momentarily when I run "sudo ./rpp", like expected.The yellow led does not blink ( probably meaning that no data was read).

I also tested each individual green led, by high/low of pins 4, 7, 9 successfully.
Maybe I have not connected the PIC correctly - I am a newbie, and your post did not have detailed instructions on how to connect the pic, hence I connected
1. T5/Clock to RB6/T1OSO/T1CKI/PGC
2. T6/Data to RB7/T1OSI/PGD
3. T7/VPP to RA5/MCLR/VPP.
Based on what I read online on PIC programming, I also connected
4. 5V ( from the L7806 VR) to VDD,
5. Vss to ground ( all the grounds where connected to each other and to the ground of RPi)
6. I also tried with and without RB4/PGM connected to ground.

http://kannvin.freeshell.net/wiki/doku. ... ojects:rpi is a picture of my circuit on breadboard. I will happily provide more details, more comments on the pic, or any other information if needbe.

Can you please tell me how to debug this further and get it to work?
Thanks

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Sun Mar 10, 2013 2:31 pm

tlc wrote:In the meantime - because I'm quite often using PIC12F629/675 - will it be possible for you to add support for those PICs into rpp, please? I have found Memory Programming datasheet at Microchip website: http://ww1.microchip.com/downloads/en/d ... 41191d.pdf
But 629/675 programming is a bit complicated - OSCCAL and BG has to be preserved:
The OSCCAL word and BG bits must be read prior to erasing the device and restored during the programming operation. OSCCAL is at location 0x3FF and the BG bits are bits 12 and 13 of the Configuration Word (0x2007).
Hello, in theory I think it should be possible to add support for those devices, but I don't have much free time these days to work on it sadly... also I cannot even do a quick test since I don't have those parts. Other than that, let me know if you manage to read/write one of the supported devices.

Holden
Posts: 29
Joined: Thu Aug 16, 2012 10:54 am
Location: Italy

Re: Raspberry Pi PIC Programmer using GPIO

Sun Mar 10, 2013 2:43 pm

saranga2000 wrote:Hi,
I am trying to see if I can program a PIC16F628a based on your circuit and software. I think I have wired up everything correctly. I added 4 led's( each with a 1KOhm resistor) for debugging: 3 green led's in parallel with the Clock, Data, and VPP, and 1 yellow led in parallel with the T3/Gpio8 for read.

But when I run sudo ./rpp - the device is not recognised.
Please do not add the leds (they will draw a significant current and will probably give you slow edges) and test with the exact circuit I published on my website.
saranga2000 wrote: Maybe I have not connected the PIC correctly - I am a newbie, and your post did not have detailed instructions on how to connect the pic, hence I connected
1. T5/Clock to RB6/T1OSO/T1CKI/PGC
2. T6/Data to RB7/T1OSI/PGD
3. T7/VPP to RA5/MCLR/VPP.
Based on what I read online on PIC programming, I also connected
4. 5V ( from the L7806 VR) to VDD,
5. Vss to ground ( all the grounds where connected to each other and to the ground of RPi)
6. I also tried with and without RB4/PGM connected to ground.
This is all correct. I left RB4/PGM floating in my tests, but the correct thing to do is connect it to ground (directly or better yet via a 1K resistor).

tlc
Posts: 18
Joined: Mon Mar 04, 2013 10:49 am

Re: Raspberry Pi PIC Programmer using GPIO

Mon Mar 11, 2013 10:52 am

Holden wrote:
tlc wrote:... I'm quite often using PIC12F629/675 - will it be possible for you to add support for those PICs into rpp, please? ...
Hello, in theory I think it should be possible to add support for those devices, but I don't have much free time these days to work on it sadly... also I cannot even do a quick test since I don't have those parts. Other than that, let me know if you manage to read/write one of the supported devices.
Hello.
Thanks, I can highly understand that problem with free time :-)
I have successfully build the programmer circuit and have tested it with 16F627A PIC (with PGM connected to ground) and it works ok. I have made a quick modification to your source code (added basic support for 12F6xx PICs), but I have only time to compile it and test it with 16F627A to be sure, that previous function is still ok. I hope that during this week I will be able to test it with 12F629 PIC. I will report the progress here and I will send you the modified source code for review - I'm afraid that I'm not a very good "C" programmer...

saranga2000
Posts: 12
Joined: Fri Dec 14, 2012 3:42 pm

Re: Raspberry Pi PIC Programmer using GPIO

Mon Mar 11, 2013 7:24 pm

Hi Holden,
I tried without the led's. Previously I also had not connected capacitors across the power supply, I did that this time around.

Running sudo ./rpp still returns the same Error: unknown device or programmer not connected.
I once again connected led's to each of the outs, to check that they could be lit up by high/low of pins 4, 7, 9. Once I was sure these were working, I removed them like you had advised.

I am stumped, can you please help? How would I go about debugging this? Could the pic be faulty ( it is brand new)? Is there anything I'm missing? Is there any way to monitor the pulse profile ( the kind that you simulated on ngspice) when I run sudo rpp? Would that help?

Thanks

tlc
Posts: 18
Joined: Mon Mar 04, 2013 10:49 am

Re: Raspberry Pi PIC Programmer using GPIO

Wed Mar 13, 2013 9:26 am

Hi Holden!
I have successfully read PIC12F675 chip using modified rpp yesterday night. I want to fully backup the chip with my old ELNEC programmer before I try to erase it or write to it using rpp - but I have not enough time to do it yesterday. So I have only tested read the whole chip operation and my read OSCCAL and BG bits function. I hope I will be able to continue tommorow evening.

I have made a PCB for your rpp circuit and slightly modified a power source part.
If anyone wants to use it, I have published it at: http://www.volny.cz/tlc/rpp/

And here is output from rpp reading 12F675:

Code: Select all

Raspberry Pi PIC Programmer, v0.1

device_id = 0x0fcb
pic12f675 detected, revision 0x0b
Reading chip...
...
Writing hex file...
Reading chip's OSCCAL and BG bits...
  Read OSCCAL from program memory:
  addr = 0x03FF  data = 0x3438
  Read BG from Configuration memory:
  addr = 0x2007  data = 0x11FF
  BG bits = 0x1000

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 12 guests