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

SPI pin assign

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Shishido



Joined: 09 Mar 2014
Posts: 10

View user's profile Send private message

SPI pin assign
PostPosted: Fri Apr 24, 2015 3:04 am     Reply with quote

Currently, I am using PIC18F27J53 for SPI memory module according with data sheet

http://ww1.microchip.com/downloads/en/DeviceDoc/39964B.pdf
Code:

#define EEPROM_SELECT PIN_A2 // CS
#define EEPROM_CLK    PIN_B4 // SCL
#define EEPROM_DI     PIN_B5 // SDI
#define EEPROM_DO     PIN_C7  //SDO
#define EEPROM_ADDRESS unsigned int32

So, I want to upgrade CPU PIC24FJ64GB002 or PIC32MX..
However, I can't find out specified PIN of SPI from the datasheet.

http://ww1.microchip.com/downloads/en/DeviceDoc/39940d.pdf

Then, how should assign CLK, SDI, SDO? Otherwise, can I assign SPI pin used by such as
Code:
#use spi(DO = PIN_B0,  DI = PIN_B1,   CLK = PIN_B2)               

as my choices ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Apr 24, 2015 4:31 am     Reply with quote

You don't.....

You need to learn about PPS.

On these later PIC's the peripherals are not 'hardware mapped' to specific pins. Instead there are PPS registers, which specify where each peripheral is mapped.
The sequence is:
Code:

#PIN_SELECT SDI1=PIN_xx  //where xx, is one of the RP pins
#PIN_SELECT SDO1=PIN_yy //again an RP pin
#PIN_SELECT SCK1OUT=PIN_zz //again chose a suitable RP pin

#use spi(SPI1, baud=nnnn, mode=v, STREAM=SPI_STREAM)
//suitable baud rate, and mode numbers for your device

Critically, you _must not specify the pin numbers in the SPI setup_. Just the physical SPI peripheral to use. The select statements setup the PPS registers to connect the pins to the peripheral.

Then use spi_xfer (rather than spi_read and spi_write), with the stream name to perform the transfers.
Shishido



Joined: 09 Mar 2014
Posts: 10

View user's profile Send private message

Thank you very much
PostPosted: Sun Apr 26, 2015 7:21 am     Reply with quote

Thank you very much, I will try it.
BTW, have you experienced Dual SPI or Quad SPI mode used by PIC?

– Dual SPI: CLK, /CS, IO0, IO1
– Quad SPI: CLK, /CS, IO0, IO1, IO2, IO3


Ttelmah wrote:
You don't.....

You need to learn about PPS.

On these later PIC's the peripherals are not 'hardware mapped' to specific pins. Instead there are PPS registers, which specify where each peripheral is mapped.
The sequence is:
Code:

#PIN_SELECT SDI1=PIN_xx  //where xx, is one of the RP pins
#PIN_SELECT SDO1=PIN_yy //again an RP pin
#PIN_SELECT SCK1OUT=PIN_zz //again chose a suitable RP pin

#use spi(SPI1, baud=nnnn, mode=v, STREAM=SPI_STREAM)
//suitable baud rate, and mode numbers for your device

Critically, you _must not specify the pin numbers in the SPI setup_. Just the physical SPI peripheral to use. The select statements setup the PPS registers to connect the pins to the peripheral.

Then use spi_xfer (rather than spi_read and spi_write), with the stream name to perform the transfers.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Apr 26, 2015 10:27 am     Reply with quote

Problem is that the CCS supported PIC's don't have hardware for this (unless there is a new one with this?). Hence you end up having to use software SPI.
Given that faster PIC's allow the SPI to be clocked off Fosc/2, a 60MIPS chip, can transfer 7.5MB/sec. Using the quad mode, uses extra pins, and gains nothing. Using the hardware, you can use DMA, with software you lose this.

Some of the 32bit PIC's do have hardware for this, but you are then not talking CCS.

PIC32MZ1024ECM124 for example.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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