View previous topic :: View next topic |
Author |
Message |
dezso
Joined: 04 Mar 2010 Posts: 102
|
Hardware I2C on 16F18313 |
Posted: Sat Nov 28, 2015 12:21 pm |
|
|
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 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Nov 28, 2015 12:42 pm |
|
|
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
|
|
Posted: Sat Nov 28, 2015 12:48 pm |
|
|
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 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sat Nov 28, 2015 2:57 pm |
|
|
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: 19549
|
|
Posted: Sun Nov 29, 2015 2:10 am |
|
|
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'
|
|
|
|
|