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 Sep 01, 2014 9:56 am

Entropic_3105 wrote:Hi,

Recently, I was surfin' the interweb and came across you webpage about using the pi as a pic programmer. It just so happens though that I have a load of pic microcontrollers that I have no means of programming. They are called Pic16c84. Would it be possible to program them using this method at all. I'm asking before I start and learn its a waste of time.

Thanks,

Patrick
Hi, I don't have knowledge about the "c" (16c84) series so I don't know how to answer your question...

If it is the same electrical programming model as the 16F84, then you can probably make it work for the 16c84... take a look at the datasheet to see if they have the same algorithm...

Hope it help...

Valter

danjperron
Posts: 2703
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Raspberry Pi PIC Programmer using GPIO

Mon Sep 01, 2014 12:59 pm

HiPatrick,
Hi Valter,

I wasn't able to find the DS30189D document at the Microchip site but I found it there

http://www.romstore.ru/pdf/PIC16C84.pdf

It should be easy to adapt the code for it. You need to have a VPP between 12 to 14V. and VDD need to be 5V.

Daniel

sanusb
Posts: 1
Joined: Sun Mar 08, 2015 3:40 pm

Re: Raspberry Pi PIC Programmer using GPIO

Sun Mar 08, 2015 3:43 pm

Online PIC progrmming via USB port of a Raspberry Pi: https://www.youtube.com/watch?v=S30wVi9RWEs. Programs available in https://www.dropbox.com/s/whwolbzf0cwkkb9/SanUSBrpi.zip

nvk44
Posts: 3
Joined: Mon Apr 27, 2015 5:47 am

Re: Raspberry Pi PIC Programmer using GPIO

Mon Apr 27, 2015 8:35 am

Hi Valter,

I have a Raspberry Pi B+ and thought I will try to program PIC 16F628A using this method. This is my first attempt to program a PIC Chip. I am getting the following error and need suggestions/help to resolve.

When I run sudo ./rpp1 -r (rpp1 is the folder where I have stored the compiled output)

Raspberry Pi PIC Programmer, v0.1

device _id = 0x3fff

Error : Unknown device or programmer not connected

The same message is displayed with or without connecting to the programmer and I have tried this with the 3 pieces of 16F628A I have.

(Voltage at PIN 14 Vdd is around 5 volts and at PIN 4 MCLR is around 13 volts)

I tried using the modified version posted at http://mujweb.cz/tlc/rpp/

and in this case the error is

Raspberry Pi PIC Programmer, v0.3 (March 2013)

device _id = 0x0000

Error : Unsupported device or programmer not connected

and the funny thing in this case is that the Pi B+ hangs up and stops responding and I need to reboot.

I am an electronic hobbyist and am pretty sure the assembled circuit is fine.


NVK

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

Re: Raspberry Pi PIC Programmer using GPIO

Mon Apr 27, 2015 9:46 am

Hi NVK.
I can comment this:
device _id = 0x0000
Error : Unsupported device or programmer not connected
and the funny thing in this case is that the Pi B+ hangs up and stops responding and I need to reboot.
This looks to me that you have not modified GPIO ports.
My version 0.3 at http://mujweb.cz/tlc/rpp/ uses GPIOs which are no longer on GPIO header at "plus" versions of Pi.
And one of GPIO used as default in my code is now maintaining USB - that is why Pi hangs up if you do not modify GPIOs for "plus" versions of Pi. Can you check if in your code are the right GPIOs to which is your circuit connected to? And please notice that GPIO numbering in rpp uses Broadcom GPIO numbering, no wiringPi numbering...

You can try my new version 0.4 at http://mujweb.cz/tlc/rpp/ - it has an autodetection of Pi version so it should not freeze Pi+ as previous version (it has different default set of GPIOs for "non-plus" and "plus" Pi versions). But still you have to modify GPIO numbers, to which you have your circuit connected to.

Tomas

nvk44
Posts: 3
Joined: Mon Apr 27, 2015 5:47 am

Re: Raspberry Pi PIC Programmer using GPIO

Tue Apr 28, 2015 8:22 am

Hi Tomas,

Thanks for your quick reply. Will check out version 0.4 and come back during the weekend. Am using the BCM GPIO where GPIO 4 relates to PIN 7 on header, GPIO 7 relates to PIN 26 on header,GPIO 8 relates to PIN 24 on header and GPIO 9 relates to PIN 21 on header. Ground used at PIN No 6 of header.

I was under the impression that all models/versions of PI maintained the same GPIO PINOUT up-to PIN No 26 and hence no modification was required.

Reference used http://www.raspberrypi-spy.co.uk/2012/0 ... -and-pins/

Will cross check everything again and come back during the weekend.

NVK

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

Re: Raspberry Pi PIC Programmer using GPIO

Tue Apr 28, 2015 12:36 pm

Hi NVK.
I was under the impression that all models/versions of PI maintained the same GPIO PINOUT up-to PIN No 26 and hence no modification was required.
Pinout on 26 pin header is the same in all revisions (except for the very first B model rev. 1.0).
But my code in 0.3 version uses GPIO 28,29,30,31 which are not at the 26 pin header on Pi A/B rev. 2.0, they are at different, 8 pin (from the factory unsoldered) header.
And they are not at any header on Pi "plus" revisions.
So if you have not modified my source code, which defines GPIO like:
  • #define PIC_CLK 28 /* Output */
    #define PIC_DATA 29 /* Output */
    #define PIC_DATAIN 30 /* Input */
    #define PIC_MCLR 31 /* Output */
to your GPIOs (4,7,8,9) then compiled rpp will hang on Pi "plus" revisions.

Tomas

nvk44
Posts: 3
Joined: Mon Apr 27, 2015 5:47 am

Re: Raspberry Pi PIC Programmer using GPIO

Wed Apr 29, 2015 8:28 am

Hi Tomas,

Sorry I should have checked this in your code. Thanks for pointing this out. Will definitely check and revert. :oops:

DaveSemm
Posts: 156
Joined: Thu Jun 21, 2012 1:16 pm

Re: Raspberry Pi PIC Programmer using GPIO

Thu Apr 30, 2015 9:09 am

I know nothing about PICs: I needed a cheap ADC with 4 input MUX, and stumbled across the PIC12F675, so I ordered a few - and then found out getting the code into its flash needed some pricey hardware. So thanks to the good people here for making this project available to the public!

I'm going to get the parts this weekend and will give it a shot. If I get it to work, I have some other projects that could use a PIC - I might even try out some of the bigger versions.

DaveSemm
Posts: 156
Joined: Thu Jun 21, 2012 1:16 pm

Re: Raspberry Pi PIC Programmer using GPIO

Sun May 10, 2015 2:03 pm

Just want to say thanks to you guys: I'm new to the PIC and really bad at electronics (bad eyes, shaky fingers), but I made it and it works: the programmer detects my chip! Now to start making some PIC programs...

pi@Pi-LAN-5C-77 ~/rpp $ sudo ./rpp -D
Raspberry Pi PIC Programmer, v0.4 (March 2015)

Device tree NOT found.
Pi2: 0, Revision: 000e, BoardRev: 2
GPIO Base: 20200000
pic_clk: 28
pic_data: 29
pic_dataIn: 30
pic_mclr: 31
device_id = 0x0fcb
pic12f675 detected, revision 0x0b
pi@Pi-LAN-5C-77 ~/rpp $

DaveSemm
Posts: 156
Joined: Thu Jun 21, 2012 1:16 pm

Re: Raspberry Pi PIC Programmer using GPIO

Mon May 11, 2015 6:55 pm

Hi Thomas,

I am trying to program a PIC12F675. rpp-tlc recognizes it, and it reads the flash to a hex file, but it can't read my hex file. When I try, I get:

pic12f675 detected, revision 0x0b
Reading hex file...
line 1 (32 bytes): ':0A0000008316FF23900083010F2AEE\n'
byte_count = 0x0A
address = 0x0000
record_type = 0x00 (data)
data = 0x8316
data = 0xFF23
data = 0x9000
data = 0x8301
data = 0x0F2A
data = 0x00EE
Error: cannot read data.

The first line is:
:0A0000008316FF23900083010F2AEE

I'm new to this, but I've worked out that 0A is the number of bytes (8316FF23900083010F2A), but the code is reading 4 nibbles at a time, expecting 10x 16 bit words:

for (i = 0; i < byte_count; i++) {
nread = sscanf(&line[9+4*i], "%4hx", &data);
if (nread != 1) {
fprintf(stderr, "Error: cannot read data.\n");
free_picmemory(&pm);
return NULL;
}

So it fails after reading past the end of the line.

Is my hex file in the wrong format? Or am I doing something wrong?

(==> Comparing my hex file with the output file, I see the byte count in my file is an actual byte count, but in the output file, it is a word count. I changed :0A with :05 (and :10 with :08 on the remaining lines) and now it reads the 1st line - and fails the checksum! Is there something I can do to fix the checksums?)

Otherwise, I am enjoying this and am learning very fast now...

DaveSemm
Posts: 156
Joined: Thu Jun 21, 2012 1:16 pm

Re: Raspberry Pi PIC Programmer using GPIO

Mon May 11, 2015 7:22 pm

Is the problem that the PIC12F675 is 8 bit and the code was made for 16 bit PICs?

I changed your code to ignore the checksums, and then it succeeded to read the file to the end, but failed to program the chip:

line 64 (16 bytes): ':01400E00C431BB\n'
byte_count = 0x01
address = 0x400E
record_type = 0x00 (data)
data = 0xC431
checksum = 0xBB
checksum clc= 0xBC
Error: checksum does not match.

line 65 (12 bytes): ':00000001FF\n'
byte_count = 0x00
address = 0x0000
record_type = 0x01 (EOF)
checksum = 0xFF
checksum clc= 0xFF

Reading chip's OSCCAL and BG bits...
Read OSCCAL from program memory:
addr = 0x03FF data = 0x3430
OSCCAL = 0x3430
Read BG from Configuration memory:
addr = 0x2007 data = 0x11FF
BG bits = 0x1000
Bulk erasing chip...
Erasing program and configuration memory...
Erasing data memory...
Writing back OSCCAL and BG bits...
Writing back OSCCAL to the program memory location 0x3FF:
addr = 0x03FF written = 0x3430 read = 0x3430
Writting BG bits to the configuration memory:
addr = 0x2007 written = 0x11FF read = 0x11FF
Reading chip's OSCCAL and BG bits...
Read OSCCAL from program memory:
addr = 0x03FF data = 0x3430
OSCCAL = 0x3430
Read BG from Configuration memory:
addr = 0x2007 data = 0x11FF
BG bits = 0x1000
Writing chip...
Write Program memory:
addr = 0x0000 written = 0x8316 read = 0x0316
Error: addr = 0x0000, written = 0x8316, read = 0x0316
Reading chip's OSCCAL and BG bits...
Read OSCCAL from program memory:
addr = 0x03FF data = 0x3430
OSCCAL = 0x3430
Read BG from Configuration memory:
addr = 0x2007 data = 0x11FF
BG bits = 0x1000

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Mon May 11, 2015 7:30 pm

This piece of assembly code might be useful for testing the programmer on 12f675

https://github.com/oh7bf/PiPIC/tree/master/asm

It might be a good idea to put the rpp-tlc under version control too. For example by using the github or something similar.

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

Re: Raspberry Pi PIC Programmer using GPIO

Tue May 12, 2015 10:20 am

Hi DaveSemm.
rpp-tlc is based on Heldon's rpp code and it expects INHX16 format of HEX file.
If you compile ASM on Raspberry using gpasm, please use -a INHX16 option to obtain right format for rpp.
There are more HEX file formats (INHX8, 16, 32) but rpp supports only INHX16 format.
Hope this will solve your problem.
Tomas
DaveSemm wrote:Hi Thomas,
I am trying to program a PIC12F675. rpp-tlc recognizes it, and it reads the flash to a hex file, but it can't read my hex file.

DaveSemm
Posts: 156
Joined: Thu Jun 21, 2012 1:16 pm

Re: Raspberry Pi PIC Programmer using GPIO

Tue May 12, 2015 6:12 pm

Hi Tomas,

I can't find anything on INHX16: I got the original HEX file from a project made by saaedsolutions - he used MPLAB and the HI-TECH C compiler. I downloaded the free MPLAB XC8 compiler, but it says it only supports INHX8M and INHX32 - no INHX16!

I compiled the c code with xc8 and got a very similar hex file, with :0A for 10 bytes (not 5 words) on the 1st line, and :10 for 16 bytes (not 8 words) on most of the following lines.

The xc8 compiler created two "as" files: startup.as and main.as. I tried gpasm -a INHX16 main.as, and just get lots of syntax errors, etc, so i assume they are not the format gpasm expects. main.as starts like this:

Code: Select all

opt subtitle "Microchip Technology Omniscient Code Generator (Lite mode) build 201502162209"

opt pagewidth 120

	opt lm

	processor	12F675
clrc	macro
	bcf	3,0
	endm
clrz	macro
	bcf	3,2
	endm
setc	macro
	bsf	3,0
	endm
setz	macro
	bsf	3,2
I don't know what tools to use: how do I compile a PIC C program, either on a PC or the Pi, and create an INHX16 file?

DaveSemm
Posts: 156
Joined: Thu Jun 21, 2012 1:16 pm

Re: Raspberry Pi PIC Programmer using GPIO

Tue May 12, 2015 7:05 pm

hampi: Thanks! The programmer worked, I think. After listing everything written to the PIC, the output ended with this:

Code: Select all

  Write Configuration memory:
  addr = 0x2007  written = 0x118C  read = 0x118C
Reading chip's OSCCAL and BG bits...
  Read OSCCAL from program memory:
  addr = 0x03FF  data = 0x3FFF
  OSCCAL = 0x3FFF
  OSCCAL is not RETLW (0x34nn) command!
  Read BG from Configuration memory:
  addr = 0x2007  data = 0x3FFF
  BG bits = 0x3000
And now I should be able to use the PIC! I'm going to wire it up and try it out over the weekend.

This was my main aim, so if the PIC works as an ADC I'l be fine for now. But I would like to know how to compile C code for the PIC and get it into INHX16 format for the programmer at some point.

Thanks again to everyone here. It has been an education.

DaveSemm
Posts: 156
Joined: Thu Jun 21, 2012 1:16 pm

Re: Raspberry Pi PIC Programmer using GPIO

Wed May 13, 2015 6:28 pm

It looks like programming the PIC12f675 with PiPic (pic12si2c.hex) didn't work after all. The rpp-tlc -r command creates a file with filled with 3FFF... I assumed that it verified by reading every location and comapring it with the hex input, so now I don't know.

Code: Select all

:080000003FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFF08
:080008003FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFF00
:080010003FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFFF8
:080018003FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFFF0
etc...
I noticed the OSCAL error yesterday, but thought someone said that was not an issue. So long as the program code verifies it should be ok.

I'm going to go over everything again, and try to learn more about PICs and PIC programming. I will keep a look out for C compilers that can produce the right format hex file.

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

Re: Raspberry Pi PIC Programmer using GPIO

Wed May 13, 2015 9:49 pm

The GPIO8 in the circuit diagram needs to be configured as floating input without pull up or down at Raspberry Pi. Otherwise the data read contains mostly high states, which gives in a 0xFF... in hexadecimal. I spent some hours to investigate this problem when the device tree was introduced back in January.

My wiring looks like this

https://github.com/oh7bf/PiPIC/wiki/PIC-programming

I use a separate 12 V battery or 12 V DC power supply during programming, but the 100 kohm resistors in the Holden's circuit should protect the GPIO anyway. The ground connection is an exception since it does not have any series resistance, so that wire should not be connected to any normal I/O or power supply.

metty
Posts: 1
Joined: Tue May 17, 2016 8:09 am

Re: Raspberry Pi PIC Programmer using GPIO

Tue May 17, 2016 8:12 am

Hello,
can i program a pic 18F4xK80 ? What is to change ?

danjperron
Posts: 2703
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Raspberry Pi PIC Programmer using GPIO

Tue May 17, 2016 11:09 am

The burnLVPx program should take care of the PIC18F46K80 or PIC18LF46K80.

Check the file CpuPIC18FXXK80.py
https://github.com/danjperron/burnLVP

Don't forget to disable 1wire and SPI unless you modify the code for other GPIO pins.

martenjacobs
Posts: 5
Joined: Fri Sep 26, 2014 9:04 am

Re: Raspberry Pi PIC Programmer using GPIO

Thu Nov 30, 2017 6:29 am

Hi all,
After reading through this thread, which stretches back in time for about 5 years now, I can't really work out what the current state of these projects is. Is anything still under active development/maintenance?
I'm trying to program a (completely empty, no bootloader or anything) PIC16F88. From what I read, either rpp or burnLVP should be able to do that, but documentation is sparse and I don't know what the current 'best-practice' is in this regard. Does anyone have any advice?

danjperron
Posts: 2703
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Raspberry Pi PIC Programmer using GPIO

Thu Nov 30, 2017 12:26 pm

Hi martenjacobs,

Well it is working fine. I will try to add the pic16F88 into the code.

But I need you to be my tester since I don't have the pic16F88.

Currently SPI and 1 wire should be disabled because I'm using the corresponding pins. (sudo raspi-config, disable SPI and 1 wire).

I quickly check the specification of the pic16f8x and it should be straight forward with the second algorithm.
http://ww1.microchip.com/downloads/en/D ... 39607c.pdf


best regards,
Daniel Perron

danjperron
Posts: 2703
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Raspberry Pi PIC Programmer using GPIO

Thu Nov 30, 2017 6:19 pm

If you don't use RB3 then it is possible to burn the chip using lvp mode with the PIC16F8x

I will need to add another class since the step to go into programming mode is different from other PIC cpus.

B.T.W. The PIC16(L)F1827 which could be programmed already is pin to pin compatible and run faster and have more peripherals.

martenjacobs
Posts: 5
Joined: Fri Sep 26, 2014 9:04 am

Re: Raspberry Pi PIC Programmer using GPIO

Thu Nov 30, 2017 8:08 pm

I'm fine with being a tester. I can wire up the PIC following the schematic in your github repo tomorrow. I'll probably solder a testing board with a DIP socket for the PIC so I can program it outside of the target PCB. I'm building a PCB from a BOM that included this specific IC, so I'd like to stick with it for now.
From what I see in your schematic and the programming spec you've linked, it seems we can only use programming algorithm #1 because we're supplying 3.3V to Vdd and not 5V (I'm guessing because we can destroy the Pi's GPIO's if we do?). I'll try to go through your other classes and see what I can do.

danjperron
Posts: 2703
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Raspberry Pi PIC Programmer using GPIO

Fri Dec 01, 2017 12:35 am

OK then looks like that to go to program mode it will be like the PIC18.

But I need to read more because looks like that bulk erase only works on 5V.

First did you need RB3?
Second looks like that I will need to pump up the voltage to 5V on the IO. This mean that we need to add Voltage converter.

I think that I will order a couple of PIC16F88 because it will be way more complicated.
I should get the chip monday night.

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

Who is online

Users browsing this forum: No registered users and 17 guests