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

#pin_select for SPI2 pic18f66j94

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



Joined: 25 Jan 2017
Posts: 1

View user's profile Send private message

#pin_select for SPI2 pic18f66j94
PostPosted: Wed Jan 25, 2017 8:56 pm     Reply with quote

I'd like to set SPI2 in slave mode, but I think that the code I'm using to configure the pin_select is wrong...

Code:

//#pin_select SCK2OUT=PIN_E2
#pin_select SCK2=PIN_E2
#pin_select SDO2=PIN_E0
#pin_select SDI2=PIN_E1


#use spi(SPI2)


I put a breakpoint before the main loop to see the control registers of SPI2 pins and the values of registers are:

RPINR10_11<7:4> = h'F
RPOR30_31<3:0> = h'5

the values below are correct if my SPI2 will work in Master mode, but if it needs to work in slave mode, SCK2 will receive clocks, so its need to work like an input...

I expected these values:

RPINR10_11<7:4> = h'7
RPOR30_31<3:0> = h'F

if I try to declare slave in #use spi(SPI2, slave) the compiler returns error...

where I'm making a mistake?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 26, 2017 12:31 am     Reply with quote

The following test program compiles with vs. 5.066.
This is not a complete spi slave example. Its only purpose is to get the
correct pin selects and #use spi() statement so it will compile and produce
code for a hardware spi slave. It has not been tested in hardware.
Code:

#include <18f66j94.h>
#fuses HS, NOWDT
#use delay(clock=4M)

#pin_select SCK2IN=PIN_E2
#pin_select SDO2=PIN_E0
#pin_select SDI2=PIN_E1
#pin_select SS2IN=PIN_E7   // Slave Select pin

#use spi(SLAVE, SPI2, MSB_FIRST, BITS=8, FORCE_HW)

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

temp = spi_xfer(0x55);

while(TRUE);
}
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