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

dsPIC33 remappable pins and SPI bus in hardware mode

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



Joined: 01 Jan 2007
Posts: 38
Location: Mississauga, Ontario, Canada

View user's profile Send private message

dsPIC33 remappable pins and SPI bus in hardware mode
PostPosted: Sun Oct 25, 2015 5:06 pm     Reply with quote

Hello - I'm using a dsPIC33FJ12GP202 chip for the first time with the Microchip 16-Bit 28-Pin Starter Development Board. I'd like to take advantage of the hardware SPI bus interface. Having a tough time finding the appropriate pins to use the SPI bus with. I figure I must use the re-mappable pins. My question is, will CCS compiler take advantage of the hardware SPI bus when I specify arbitrary pins as the MISO, MOSI, CLK, SS channels? I'd like to avoid using the software driven SPI bus. Thanks everyone.
Ttelmah



Joined: 11 Mar 2010
Posts: 19477

View user's profile Send private message

PostPosted: Mon Oct 26, 2015 2:26 am     Reply with quote

The way to use remapping, is always to setup the pins to the peripheral, and then setup the peripheral.
So the sequence becomes:
Code:

#pin_select SDO2=PIN_B6
#pin_select SDI2=PIN_B5
#pin_select SCK2=PIN_B4 //setup SPI2 for SD card
#pin select SS2OUT=PIN_B2
#use SPI(SPI2, //then the rest of the SPI settings)


So this sets up the SPI to use SPI2, on the pins given.

Now the peripheral pin names are given at the top of the .h file for the processor. So for your chip:

Quote:

// #pin_select function=pin
// Valid Pins:
// PIN_B0,PIN_B1,PIN_B2,PIN_B3,PIN_B4,PIN_B5,PIN_B6,PIN_B7,PIN_B8,PIN_B9,
// PIN_B10,PIN_B11,PIN_B12,PIN_B13,PIN_B14,PIN_B15
// Input Functions:
// INT1,INT2,T2CK,T3CK,T4CK,T5CK,IC1,IC2,IC3,IC4,IC5,OCFA,OCFB,U1RX,U1CTS,
// U2RX,U2CTS,SDI1,SCK1IN,SS1IN,SDI2,SCK2IN,SS2IN,C1RX,IC7,IC8,CSDI,CSCK,COFS,
// FLTA1,FLTA2,QEA1,QEB1,INDX1,QEA2,QEB2,INDX2,T1CK,FLT1,FLT2,FLT3,FLT4,FLT5,
// FLT6,FLT7,FLT8,SYNCI1,SYNCI2
// Output Functions:
// NULL,C1OUT,C2OUT,U1TX,U1RTS,U2TX,U2RTS,SDO1,SCK1OUT,SS1OUT,SDO2,SCK2OUT,
// SS2OUT,OC1,OC2,OC3,OC4,OC5,C1TX,CSDO,CSCKOUT,COFSOUT,UPDN1,UPDN2,CTPLS,
// C3OUT,SYNCO1,REFCLKO,CMP1,CMP2,CMP3,CMP4,PWM4H,PWM4L


This also lists what pins can be used (on some chips 'beware' there are two 'groups' of pins, and limitations on what can go to each group - data sheet...).

Once the pin is selected, you then configure the peripheral, but use the peripheral name, _not_ the pin numbers. Since you are setting the SPI to talk to the hardware peripheral, it is forced to use the hardware - no possibility of 'accidentally' selecting software.

I'm setting up SS2OUT (assuming you are master). On the slave you need to setup the input instead.
maxrate



Joined: 01 Jan 2007
Posts: 38
Location: Mississauga, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Oct 26, 2015 6:57 am     Reply with quote

Ttelmah - thank you for the explanation. I understand now that the pins are simply remappable (as long as the pin supports the function and direction - I/O) and will work with the parts onboard hardware peripheral driver(s).

I am not clear on your example in terms of why you are setting up SPI using SPI2. I'm not certain if you are attempting to illustrate that it is mandatory to use SPI2 vs SPI1 for the hardware peripheral or you were illustrating the flexibility of the part or if you were showing how to address the second SPI peripheral in the C code. Please forgive my ignorance here.

Looking forward to your reply.
Ttelmah



Joined: 11 Mar 2010
Posts: 19477

View user's profile Send private message

PostPosted: Mon Oct 26, 2015 7:51 am     Reply with quote

No, it was just an example.
In my case I'm using SPI1 for something else, and SPI2 for an SD card. I just copied the SPI2 settings. Very Happy
maxrate



Joined: 01 Jan 2007
Posts: 38
Location: Mississauga, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Oct 26, 2015 7:52 am     Reply with quote

Good to know, thanks again!
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