Has anybody ever used the Parallel Master Port function in PIC18F series? not Parallel Slave Port!
Traditional C is also OK if you have. I have spent about one week on it but still can not run it...

Thanks!

PCM programmer

Joined: 06 Sep 2003Posts: 20333

Posted: Sun Dec 10, 2017 2:57 am

The setup_psp() function has parameters to setup either the master or
the slave. The constants used with this function are in the 18F87J11.h file.

Tell us what you want the Parallel Master Port to do in your project.

norman_tan

Joined: 30 Jan 2008Posts: 21

Posted: Tue Dec 12, 2017 2:38 am

Hi PCM Programmer,
I want the PMP of 18F87j11 works under "Master Mode 2" with 8-bit DATA + 13-bit ADDRESS. my version of PCWHD is 5.018, and in the 18F87J11.h file all PMP settings/functions are listed here:

The basic setups don't configure all the pin masks. Think about it there are individual bits to enable each bit of the address, so potentially up to 65536 different patterns. All you do is set these to mask what you want. So:

Code:

#WORD PMPEN=getenv("SFR:PMEL")

PMPEN=0x1FFF; //enables the low 13bits of the address

Unfortunately I think you will have to write to the configuration registers generally yourself. The way I do it above shows a good portable way to define the registers and use them. My memory was that the register numbers selected by the inbuilt functions was wrong when I was looking at them, and this was on a close 'relative' of your chip, and fairly close on compiler versions.
The 32 bit value is meant to be sent to the PMMODE register (upper 16bits), and PMCON (low 16bits), but when I tried it the values were going to completely the wrong registers.
So something like:

Now 'no guarantees', I haven't got that source code now, and it was a couple of years ago

norman_tan

Joined: 30 Jan 2008Posts: 21

Posted: Wed Dec 13, 2017 3:46 am

Dear Ttelmah,
Thanks for your reply!
In fact, I can not understand well the define such as "#define PMP_ENABLED 0x02008000" in 18F87J11.h file. Why setting value as a word? hehe. No studying it carefully.
About 8 year ago, I ever met question as this time, then I could not control the 128*128 LCD in CCS, but I used the original method to operate the SFRs the same as below and successful (but fail this time):

This uses five address lines and a single chip enable. The 0x401f is the address mask for these five address lines, A0-4, and the CS, which gives the 40xx part.

I am a little confused by the reference to LEDs in your code, and also by your bit-banging of WR enable. The PMP is a full bus interface designed to interface with things like external memories, complex addressable peripheral devices (mine are GPIB and LAN ICs) and so on. It is not a latched LED driver. For that simple GPIO bits are all that's needed.

When its correctly set up, which admittedly is tricky, it will automatically generate read and write cycles with all the necessary chip selects, read and write strobes etc, for multiplex and non-multiplexed busses. If correctly set up all you should need to do is set the address and then write to the data register, which triggers the write cycle. Reads are more "fun" as the peripheral is arranged mainly for block access, i.e. reading several words in sequence. Hence when you read the data register you get the result of the previous read and trigger a new one. Reading words on their own, i.e. true random access reads needs a little thought. Here is my (random) read code:

// This works for up to eight address lines, PMA0-PMA7. Note we do not
// set the high byte, that's fixed.
PMP_ADDRL = Address;

// Read the PMP data register, this initiates a read cycle, but doesn't give us the correct result.
// it actually give us the result of the last read, or even the last byte written!
PMP_Byte = PMP_Data;
// Wait for the cycle to finish.
while(PMP_BUSY);
PMP_Enable = 0; // disable PMP
// Read the data again, this gets the byte read in the last cycle, but as the PMP is disabled, will not generate a second read cycle
PMP_Byte = PMP_Data;
PMP_Enable = 1; // re-enable the PMP
return PMP_Byte;
}

norman_tan

Joined: 30 Jan 2008Posts: 21

Posted: Thu Dec 14, 2017 2:18 am

Dear RF_Developer,
Thanks for your reply!

About the LEDs I added in code: I only wanted to show whether I have controlled the data port successful - LEDs will blink a little if data write operation is right, (though data port can not be taken as a GPIO). Of course measuring the data port with a scope maybe better than LEDs.

About the WR enable: I added it compulsively in code after many times failure. hehe.

About

Quote:

The 0x401f is the address mask for these five address lines, A0-4, and the CS, which gives the 40xx part.

the value "0x401F" is defined by yourself/CCS according to the chip manual?

Quote:

When its correctly set up, which admittedly is tricky, it will automatically generate read and write cycles with all the necessary chip selects, read and write strobes etc, for multiplex and non-multiplexed busses. If correctly set up all you should need to do is set the address and then write to the data register, which triggers the write cycle. Reads are more "fun" as the peripheral is arranged mainly for block access, i.e. reading several words in sequence. Hence when you read the data register you get the result of the previous read and trigger a new one. Reading words on their own, i.e. true random access reads needs a little thought.

Thank you described them so detailed.

I have submitted new PCB file with PIC24FJxxxGB108 chip to pcb manufactory, this is the standby design scheme if PIC18F87J11 PMP function fails finally in my CCS C project....

RF_Developer

Joined: 07 Feb 2011Posts: 839

Posted: Thu Dec 14, 2017 4:56 am

Quote:

About "The 0x401f is the address mask for these five address lines, A0-4, and the CS, which gives the 40xx part. " the value "0x401F" is defined by yourself/CCS according to the chip manual?

The value is defined by the datasheet. It is the address mask that goes into PMAEN on the 24s and PMEH and PMEL on the 18F87J11 (the 18s have 8 bit registers, the 24s 16 bit registers). For the 18F87J11 look at pages 171 and 172. In my application there were five non-multiplexed address bits, A0-A4, that means the bottom five bits of the enable register have to be 1s, or 0x001F. You are using thirteen bits, so you need 0x01FF. The 4 in the top nibble of my application is to enable PMCS1, chip select one. Combine the two and for my app I got 0x401F, your probably need 0x41FF. The PMP will not control the other address bits, and they can be used for general IO.

With LEDs, the PMP does cycles so fast I don't think you'll see any visible blinking. An oscilloscope is the way to check its working.

Ttelmah

Joined: 11 Mar 2010Posts: 13260

Posted: Thu Dec 14, 2017 8:51 am

No. 13 bits. 0x1FFF.
You are a nibble short.
That's why I showed this value in my post higher up.

norman_tan

Joined: 30 Jan 2008Posts: 21

Posted: Fri Dec 15, 2017 2:26 am

Dear RF_Developer and Ttelmah,
I studied the manual of 18s again as you said. It is just the value 0x1FFF if combine PMEH and PMEL.

PMEL = 0xFF; // PMA<7:2> function as PMP address lines,PMA1 and PMA0 function as either PMA<1:0> or PMALH and PMALL

If change the PMEH = 0x1F (13-bit address) and combine PMEH & PMEL, it is 0x1FFF.

Thank you for explaining it so carefully!

Removed the LEDs board and I measured the Data Port & Address Port(checking the pin level change one by one) with an oscilloscope.
Obviously, signals of data port and address port are changed according to the settings. Duty cycle of Address port is 50%, and the duty cycle of data port is very small -- data is a narrow pulse.

But unfortunately, I can not measure the change at PMWR/CS pin (it is always is '0') though I have changed the setting of PTWREN from '0' to '1'.

I will return to study the 18s manual much carefully again to find what causes no action at PTWR/CS pin.

Ttelmah

Joined: 11 Mar 2010Posts: 13260

Posted: Fri Dec 15, 2017 3:13 am

OK.
Lets make a couple of other comments:

First note how I used '#word'. This allows you to write to a 16bit register as a single 'entity'. Very useful for this sort of thing.
If you are dealing with registers that are fundamentally '8bit' entities, then use #byte. If you are dealing with 16bit registers use #word. The compiler locates the register at the location given, and the next location 'up', so by locating the word at the 'low' register address I get a 16bit register where wanted. Much easier.

Then the key place to look is DS-70299C. From MicroChip. This gives examples of the settings needed for several typical modes, and these are a great starting point. You are looking at 8bit data demultiplexed address?.

Now we come to the first big problem. Look at the data sheet. Figure 26-1. Note how it says 'up to 11bit address'. As far as can see, the module does not support a 13bit address mode. It allows up to 12bit if the chip select is not used, but only eleven bits with a CS. If you look at the pin diagrams, there is not a PMA11 or PMA12 bit... So your 13bit address has problems. Though the register has bits to apparently select these, the ones above A10, are non functional. If you look at the example, all 16 bits are shown as selected, though 11bits are being used....
A look at the PMAEN register in the data sheet shows it stopping at bit 10.

So if you want an address this large you are going to have to 'think again'. Either accessing the chip as pages, with a fixed output for the extra bits, or doing some form of multiplexing.

So a big part of your problem may simply be you are trying to ask the chip to do something it doesn't support.....

norman_tan

Joined: 30 Jan 2008Posts: 21

Posted: Fri Dec 15, 2017 8:39 pm

Dear Ttelmah,

In manual DS-70299C, it says "Up to 12 Programmable Address Lines",but this manual is used for "dsPIC33F/PIC24H FRM Section 35. Parallel Master port".

In manual DS39778E, it says "Up to 16 Programmable Address Lines", this is the manual for PIC18F87J11 FAMILY, and in section 12.3.4 ADDRESS MULTIPLEXING, it describes as below :
In Demultiplexed mode (PMCONH<4:3> = 00), data and address information are completely separated. Data bits are presented on PMD<7:0>, and address bits are presented on PMADDRH<7:0> and PMADDRL<7:0>.
I selected this mode here.

OF course for my "standby design scheme"(if PIC18F87J11 PMP function fails finally), I selected PIC24FJxxxGB108 FAMILY. In its manual(DS39897C) ,it says "Up to 16 Programmable Address Lines", “For more information, refer to the PIC24F Family Reference Manual”,Section 13 - Parallel Master Port(PMP) (DS39713)". so if I select the chip PIC24FJ128GB108 for "standby design scheme", it will be OK.

I am editing those CCS codes as advice from you and RF_Developer for a try

After copying all PMP settings from PIC24FJ128GB108.h to PIC18F87J11.h(they are very similar between these two chips) and disable all previous settings too, I add command line in code:
setup_pmp(PAR_ENABLE|PAR_CS_11|PAR_CONTINUE_IN_IDLE|PAR_PTBEEN_ENABLE|PAR_PTWREN_ENABLE|PAR_PTRDEN_ENABLE|PAR_MASTER_MODE_2,0x1FFF);

Compile result is:
Error 112: Function used but not defined: ...setrp_pmp 411 SCR=6578

It's a problem of 'nomenclature'. Some chips have the 'slave only' peripheral, while others have a peripheral that can be set as master or slave. The function was originally introduced to handle the slave peripheral, and kept it's name.

norman_tan

Joined: 30 Jan 2008Posts: 21

Posted: Sat Dec 16, 2017 9:44 pm

Dear Ttelmah,
setup_psp() in 18F87J11.h is: _bif void setup_psp(int32 mode);
setup_psp() in 24FJ1128GB108.h is: setup_psp(unsigned int32 mode, unsigned int16 address_mask);
if I call setup_psp(int32 mode) only then I can not set all address port;
if I call setup_psp(unsigned int32 mode, unsigned int16 address_mask) then "Error:58" happens;
the KEY issues in 18f67j11.h are: 1,Can not set the PMP address mode(0x1FFFF); 2, Use "INPUT_D(), OUTPUT_D()" for data operation; 3, Can not set address.

Though I can add some constants in it, example :
#define PAR_MASTER_MODE_1 0x03000000 // Master mode 1
#define PAR_MASTER_MODE_2 0x02000000 // Master mode 2
but I still worry there are some libraries/link ignored.

10 days ago I sent this issue by email to CCS support, but it is still the same answer as before: "The e-mail has been reviewed, however, an answer is not yet ready. A priority has not yet been determined for this issue."
Let it be.

Ttelmah

Joined: 11 Mar 2010Posts: 13260

Posted: Sun Dec 17, 2017 1:00 am

I showed how to set the address mask earlier. Use the register direct access for this. It is much easier.