CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

streaming parallel port
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
michelcla



Joined: 29 May 2008
Posts: 3

View user's profile Send private message

streaming parallel port
PostPosted: Thu May 29, 2008 3:41 pm     Reply with quote

Hello
I need help, I have to do a connection between 2 PICs using the 18f4550
and I do the code in C but the problem is that I do not know how to start
and which codes I have to use.

Yes I really need to us the SPP


Last edited by michelcla on Fri May 30, 2008 11:58 am; edited 1 time in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 29, 2008 5:15 pm     Reply with quote

The PIC18F4550 has a Streaming Parallel Port (SPP) which is great for high speed USB data transfer but requires 11 I/O pins. Do you really need the high speed? SPI uses 4 wires and I2C only 2 wires and for those a lot more example code can be found on this forum.
michelcla



Joined: 29 May 2008
Posts: 3

View user's profile Send private message

streaming parallel port
PostPosted: Fri May 30, 2008 12:18 pm     Reply with quote

ckielstra wrote:
The PIC18F4550 has a Streaming Parallel Port (SPP) which is great for high speed USB data transfer but requires 11 I/O pins. Do you really need the high speed? SPI uses 4 wires and I2C only 2 wires and for those a lot more example code can be found on this forum.


Yes I really need to use the SPP please help me
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Fri May 30, 2008 2:52 pm     Reply with quote

All the info you need will be in the CCS manual, CCS example code, and the PIC18F4550 datasheet.

Do you have a specific question or problem?
michelcla



Joined: 29 May 2008
Posts: 3

View user's profile Send private message

streaming parallel port
PostPosted: Fri May 30, 2008 3:54 pm     Reply with quote

that I need is know which codes in c I can use for example to configure the register sppcon and sppcfg, because when I try that did not work.
If you have same programs done in c using the spp, that is that I need
thanks for answer me
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Fri May 30, 2008 6:13 pm     Reply with quote

CCS uses built-in high-level functions to access the SPP, so you don't need to set all the registers by hand. I personally have not had a project where I've used SPP so I can only say to view the examples CCS includes.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 29, 2008 5:42 pm     Reply with quote

Here is a test program that shows how to use the 18F4550's SPP port
(streaming parallel port) in micro-controller mode. I emailed
Microchip tech support and they sent me some sample C18 code to
do write operations. I then wrote CCS-style functions to use the SPP.
If you're familiar with the setup_spi() function, then you should be able
to use these SPP functions.

The test program shown below basically follows the timing diagram
shown in this section of the 18F4550 data sheet.
Quote:

FIGURE 18-2:
TIMING FOR MICROCONTROLLER WRITE ADDRESS, WRITE DATA AND
READ DATA (NO WAIT STATES)

The follow section explains how to do read operations:
Quote:
18.3.3 READING FROM THE SPP

The timing diagram in Figure 18-2 doesn't show the "previous" read
operation that was necessary to read the data. In the program below,
I do a "dummy read" to initiate the read operation. Refer to section
18.3.3 for more information. To test reading, I turned on the Port D
weak pull-ups, and then put a 4.7K pull-down resistor on one of the
data lines. For example, I put the pull-down on pin D7, and then read
back 0x7F. I then moved it to pin D6 and read back 0xBF. That proves
that I'm able to read the data bus.

The speed isn't as fast as you might think. There are 5 instruction
cycles between SPP write operations. Checking the SPPBUSY bit takes
two more cycles, for a total of 7 cycles. So with a 20 MHz oscillator,
it takes 1.4 us between SPP write strobes, coming out of the PIC.
That's a data rate of 714 KB/sec. Possibly you could hard-code a
delay by using delay_cycles(), and don't check SPPBUSY. Then you
could do a 1 MB/sec transmission rate at 20 MHz. I'm not sure if this
is safe, so I only did a little bit of testing on it.
Code:

#include <18F4550.h>
#fuses HS, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

// The following constants may be bitwise OR'ed together
// and used as the parameters for the setup_spp() function.
#define SPP_ENABLED     0x0100
#define SPP_DISABLED    0x0000
#define SPP_OWNER_USB   0x0200
#define SPP_OWNER_MICRO 0x0000

#define SPP_CLK1_ODD_CLK2_EVEN_ADDR 0x80
#define SPP_CLK1_WR_CLK2_RD         0x40
#define SPP_CLK1_ADDR_CLK2_DATA     0x00

#define SPP_RB4_CS   0x20
#define SPP_RE0_CLK1 0x10

#define SPP_0_WAIT_STATES 0x00
#define SPP_2_WAIT_STATES 0x01
#define SPP_4_WAIT_STATES 0x02
#define SPP_6_WAIT_STATES 0x03
#define SPP_8_WAIT_STATES 0x04
#define SPP_10_WAIT_STATES 0x05
#define SPP_12_WAIT_STATES 0x06
#define SPP_14_WAIT_STATES 0x07
#define SPP_16_WAIT_STATES 0x08
#define SPP_18_WAIT_STATES 0x09
#define SPP_20_WAIT_STATES 0x0A
#define SPP_22_WAIT_STATES 0x0B
#define SPP_24_WAIT_STATES 0x0C
#define SPP_26_WAIT_STATES 0x0D
#define SPP_28_WAIT_STATES 0x0E
#define SPP_30_WAIT_STATES 0x0F

// 18F4550 Register addresses and bits
#byte PORTE  = 0xF84
#byte SPPCON = 0xF65
#byte SPPEPS = 0xF64
#byte SPPCFG = 0xF63
#byte SPPDATA = 0xF62
#bit  SPPEN  = SPPCON.0
#bit  SPPOWN = SPPCON.1
#bit  SPPBUSY = SPPEPS.4
#bit  RDPU = PORTE.7

//------------------------------------
void setup_spp(int16 config)
{
if((config & SPP_ENABLED) == 0)
  {
   SPPEN = 0;
   return;
  }

SPPCFG = (int8)config;

set_tris_d(0xFF);

output_low(PIN_E1);
output_low(PIN_E2);

if(config & SPP_RB4_CS)
   output_low(PIN_B4);

if(config & SPP_RE0_CLK1)
   output_low(PIN_E0);

SPPCON = config >> 8;
}


//-----------------------------
// Write one address byte to the SPP port.
// Only the lower 4-bits can be used for the address.
void spp_write_addr(int8 addr)
{
addr &= 0x0F;    // Mask off upper bits for safety
while(SPPBUSY);  // Wait until ready
SPPEPS = addr;   // Transmit addr
}

//-----------------------------
// Write one data byte to the SPP port.
void spp_write_data(int8 data)
{
while(SPPBUSY);  // Wait until ready
SPPDATA = data;  // Transmit data
}


//-----------------------------
// Read one data byte from the SPP port.
int8 spp_read(void)
{
while(SPPBUSY);   // Wait until ready
return(SPPDATA);  // Read data
}



//-----------------------------
// The 18F4550 data sheet mentions Port D pull-ups as
// an option for use with the SPP module. Here is a
// function to enable or disable them.
void port_d_pullups(int8 value)  // parameter: TRUE OR FALSE
{
if(value)
   RDPU = 1;
else
   RDPU = 0;
}

 
//==================================
void main()
{
int8 value;

output_low(PIN_C0);  // Init Logic analyzer trigger
getc();   // Wait for keypress to start


setup_spp(SPP_ENABLED |
          SPP_OWNER_MICRO |
          SPP_RB4_CS |
          SPP_RE0_CLK1 |
          SPP_CLK1_ADDR_CLK2_DATA |
          SPP_0_WAIT_STATES);

port_d_pullups(TRUE);  // Enable pullups on SPP port
delay_us(10);  // Allow time to pull up before starting test

output_high(PIN_C0);  // Trigger for logic analyzer

spp_write_addr(0x05);
spp_write_data(0xAA);

value = SPPDATA;     // Dummy read to start the read cycle
value = spp_read();  // Now get the data that was read

printf("Read %X \n\r ", value);

while(1);
}

urefowei



Joined: 21 Feb 2009
Posts: 10
Location: Philippines

View user's profile Send private message Send e-mail

Steraming Parallel Port
PostPosted: Fri Feb 27, 2009 3:20 pm     Reply with quote

dear PCM programmer sir,
There were part of the code that were not clear enough for me..
Please help..!

Code:
void setup_spp(int16 config)
{
if((config & SPP_ENABLED) == 0)
  {
   SPPEN = 0;
   return;
  }

SPPCFG = (int8)config;

set_tris_d(0xFF);

output_low(PIN_E1);
output_low(PIN_E2);

if(config & SPP_RB4_CS)
   output_low(PIN_B4);

if(config & SPP_RE0_CLK1)
   output_low(PIN_E0);

SPPCON = config >> 8;
}


So here was the routine,
I have not encountered
Code:
output_low(PIN_B4)

are these functions??

or

Code:
int8

Code:
int16


what are these, variables? typedefs? macros?

Please help me understand the code..
We are also doing SPP on PIC18F4550 to another PIC18F4550
_________________
EcPaCo
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 27, 2009 3:28 pm     Reply with quote

They are functions and data types. You need to learn the CCS compiler
before you work on this project. It's all in the manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
urefowei



Joined: 21 Feb 2009
Posts: 10
Location: Philippines

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 27, 2009 3:45 pm     Reply with quote

Right..
Now I get the codes..
they are actually built in functions and type specifiers..
so, what confuses me now is that, are all this operation related to the 11 pins connection and nothing more??
how about

Quote:
If CK1SPP is to be used:
• Bit TRISE<0> must be cleared (= 0)
If CSPP is to be used:
• Bit TRISB<4> must be cleared (= 0)


what is the relevance of this pins??
Can we still do SPP without this pins, because we are running out of PINS, we are using SPP at the same time SPI..
please help..
_________________
EcPaCo
urefowei



Joined: 21 Feb 2009
Posts: 10
Location: Philippines

View user's profile Send private message Send e-mail

Streaming Parallel Port
PostPosted: Fri Feb 27, 2009 3:47 pm     Reply with quote

The quoted information by the way came from
Quote:
18.1.1 ENABLING THE SPP

of the PIC18F4550 datasheet.
thank you
_________________
EcPaCo
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 27, 2009 3:59 pm     Reply with quote

I don't think the SPP module is designed to work between two PICs,
because it's a Master-only port. It can't be a slave port.

The 18F4550 data sheet says this:
Quote:
18.0 STREAMING PARALLEL PORT

PIC18F4455/4550 USB devices provide a Streaming
Parallel Port as a high-speed interface for moving data
to and from an external system.

This parallel port operates as a master port, complete
with chip select and clock outputs to control the movement
of data to slave devices.


I think that Microchip designed the SPP so data could be transferred
between a PIC and an FPGA.
urefowei



Joined: 21 Feb 2009
Posts: 10
Location: Philippines

View user's profile Send private message Send e-mail

Streaming parallel port
PostPosted: Fri Feb 27, 2009 4:09 pm     Reply with quote

Is it possible to make the other PIC18F4550 a slave device?
I am really running out of ideas..
Is their any way to do this??
We just want to pass data from the other PIC to a host controller and to a USB mass storage device..

Actually we are doing a stand-alone device that can transfer files from one USB mass storage device to another USB MSD..

the whole set up is like a USB MSD to a host controller to a PIC to the other PIC to a another host controller and to the other USB MSD..

So its like a mirror and SPP is in between..
Any idea sir?
Need help..
_________________
EcPaCo
urefowei



Joined: 21 Feb 2009
Posts: 10
Location: Philippines

View user's profile Send private message Send e-mail

Streaming parallel port
PostPosted: Fri Feb 27, 2009 4:17 pm     Reply with quote

Actually, SPI pins are already used for the USB host controller interface..
Please help us..

Are our idea idea stupid?
_________________
EcPaCo
urefowei



Joined: 21 Feb 2009
Posts: 10
Location: Philippines

View user's profile Send private message Send e-mail

Streaming parallel port
PostPosted: Fri Feb 27, 2009 4:27 pm     Reply with quote

My idea is that, if
Quote:
This parallel port
operates as a master port,

and
Quote:
provide a Streaming
Parallel Port as a high-speed interface for moving data
to and from an external system

then probably, SPP can communicate between two masters..

Can we do this sir?
Im going out. Please do reply..
Thank you for your ideas..
Out for now..
I'll wait for your reply..
thanks[/b]
_________________
EcPaCo
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group