I am trying to get the I2C module working on a 18F26K40 with no success at all..
I'm using the following code, but get no output from the standard pins Rc3 and Rc4. I'm not using any pin re-assignments..
What am i missing? Also this PIC has two MSSP modules, how do i address them separately?
Cheers
Lee
Code: Select all
Device = 18F26k40
Clock = 64
Config
FEXTOSC = OFF, // Oscillator not enabled
RSTOSC = HFINTOSC_64MHZ,// HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
CLKOUTEN = OFF, // CLKOUT function is disabled
CSWEN = ON, // Writing to NOSC and NDIV is allowed
FCMEN = ON, // Fail-Safe Clock Monitor enabled
MCLRE = EXTMCLR, // If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
PWRTE = OFF, // Power up timer disabled
LPBOREN = OFF, // ULPBOR disabled
BOREN = SBORDIS, // Brown-out Reset enabled , SBOREN bit is ignored
BORV = VBOR_2P45, // Brown-out Reset Voltage (VBOR) set to 2.45V
ZCD = OFF, // ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
PPS1WAY = ON, // PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
STVREN = ON, // Stack full/underflow will cause Reset
DEBUG = OFF, // Background debugger disabled
XINST = OFF, // Extended Instruction Set and Indexed Addressing Mode disabled
//
//WDTCPS = WDTCPS_10, // Divider ratio 1:32768
// WDTE = ON, // WDT enabled regardless of sleep
// WDTCWS = WDTCWS_7, // window always open (100%); software control; keyed access not required
// WDTCCS = LFINTOSC, // WDT reference clock is the 31.0 kHz LFINTOSC
WDTCPS = WDTCPS_31, // Divider ratio 1:65536; software control of WDTPS
WDTE = OFF, // WDT enabled regardless of sleep
WDTCWS = WDTCWS_7, // window always open (100%); software control; keyed access not required
WDTCCS = SC, // Software Control
WRT0 = OFF, // Block 0 (000800-003FFFh) not write-protected
WRT1 = OFF, // Block 1 (004000-007FFFh) not write-protected
WRT2 = OFF, // Block 2 (008000-00BFFFh) not write-protected
WRT3 = OFF, // Block 3 (00C000-00FFFFh) not write-protected
WRTC = OFF, // Configuration registers (300000-30000Bh) not write-protected
WRTB = OFF, // Boot Block (000000-0007FFh) not write-protected
WRTD = OFF, // Data EEPROM not write-protected
SCANE = ON, // Scanner module is available for use, SCANMD bit can control the module
LVP = OFF, // HV on MCLR/VPP must be used for programming
CP = OFF, // UserNVM code protection disabled
CPD = OFF, // DataNVM code protection disabled
EBTR0 = OFF, // Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
EBTR1 = OFF, // Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
EBTR2 = OFF, // Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
EBTR3 = OFF, // Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
EBTRB = OFF
#option LCD_DATA = PORTA.0
#option LCD_RS = PORTA.4
#option LCD_EN = PORTA.5
#option LCD_RW = PORTA.6
// import libraries...
Include "I2C.bas"
Include "lcd.bas"
// target 24LC128 I2C EEPROM device...
Const I2C_EEPROM = $A0
// local variables...
Dim
Value As Byte,
Address As Word
WriteAt(1,1,"test")
// program start...
Address = 0
I2C.Initialize (I2C_100_KHZ)
// write some data...
I2C.Start
I2C.WriteByte(I2C_EEPROM)
I2C.WriteByte(Address.Byte1)
I2C.WriteByte(Address.Byte0)
I2C.WriteByte("Z")
I2C.Stop
// allow external EEPROM to write data...
DelayMS(10)
// read the data back...
I2C.Start
I2C.WriteByte(I2C_EEPROM)
I2C.WriteByte(Address.Byte1)
I2C.WriteByte(Address.Byte0)
I2C.Restart
I2C.WriteByte(I2C_EEPROM + 1)
Value = I2C.ReadByte
I2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
I2C.Stop
WriteAt(2,1,Value)