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

Hardware I2C on 16F18313

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



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

Hardware I2C on 16F18313
PostPosted: Sat Nov 28, 2015 12:21 pm     Reply with quote

Datasheet say its on PIN RA1 SCK and RA2 SDA

Compiler "ver 5.050" gives me this error Error#99 Option invalid Wrong pins for H/W
Tried to swap many pin combination all say the same, ICD disabled

How would I make this work using HW i2c.
Any tip ?
Ty


Code:

//#device ICD=TRUE
#FUSES RSTOSC_HFINTRC_PLL   
#FUSES NOCLKOUT                 //I/O function on OSC2
//#FUSES CKS                   
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOLPBOR                  //Low-Power Brownout reset is disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV24                   //Brownout reset at 2.4V
#FUSES PPS1WAY                  //Allows only one reconfiguration of peripheral pins
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#use delay(internal=32MHz)

#use i2c(Slave,Slow,sda=PIN_A2,scl=PIN_A1,force_hw,address=0x20)


Main code has almost nothing just the #include h and a blank void main()
_________________
I'm could be wrong many time's, at least I know what I'm doing Smile
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 28, 2015 12:42 pm     Reply with quote

while I don't use that PIC it does have 'peripherial pin selection' so I assume you need to do that before you use the I2C???

Also you've selected as a slave I2C device, so can we assume this PIC will be a slave to another PIC as a master ??


Jay
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Sat Nov 28, 2015 12:48 pm     Reply with quote

Yes it will be a slave.

"peripheral pin selection" yup, how to use it ? I guess than the compiler wont take care of that by itself, should I just figure out how to set up the I2C and than remove the "force_hw"
_________________
I'm could be wrong many time's, at least I know what I'm doing Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Sat Nov 28, 2015 2:57 pm     Reply with quote

The normal way with PPS, is to use #pin select to set all the peripheral pins you are using to the peripheral, and then use the hardware peripheral name in the #use (not the pins).
The peripheral pins, and the chip pin names available should be at the start of the include file for the processor.

Currently not got a compiler available, so can't look in the file to check that this is how it should be done for this chip.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Sun Nov 29, 2015 2:10 am     Reply with quote

Can confirm. Got back to a compiler this morning, and it does behave like all the other chips with PPS:
Code:

#pin_select SDI1=PIN_A2
#pin_select SCL1IN=PIN_A1
//Beware here. For a _slave_ you need to program the two input pins
//For a master, the output pins SDO1, and SCL1

#use i2c(Slave,I2C1,address=0x20)
//select hardware I2C1, a slave does not have a 'speed'
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