bradb
- 6th September 2011, 22:19
I had a program I wrote w/ PBP2.5 using a PIC 18F4550, everything worked great. I am ditching USB and going zigbee, so I'm changing from the 18F4450 to an PIC18F46K22. In the process I have also upgraded to PBP3.
This code from PBP2.5 on an 18F4450 works flawlessly:
Define OSC 48
C0B0W CON %10100000 'Chip 0, Bank 0, Write
C0B1W CON %10101000 'Chip 0, Bank 1, Write
C0B0R CON %10100001 'Chip 0, Bank 0, Read
C0B1R CON %10101001 'Chip 0, Bank 1, Read
DEFINE I2C_SLOW 1 'have to use slow for the i2c LCD
I2CLCD CON 80
SDA VAR PORTB.0
SCL VAR PORTB.1
I2CADDRESS VAR WORD
SECONDS VAR WORD
i2CTEST VAR BYTE[8]
TESTLCD VAR BYTE[8]
Main:
I2CADDRESS = 0
I2CWRITE SDA,SCL,C0B0W,I2CADDRESS,[65,66,67,68,69,70,71,72,73]
pause 50
i2cread SDA,SCL,C0B0R,I2CADDRESS,[STR I2CTEST\8]
pause 50
HSEROUT ["<TEST>", STR I2CTEST\8, "</TEST>"]
Seconds = Seconds + 1
arraywrite TestLCD ,[DEC4 Seconds]
I2CWRITE SDA,SCL,I2CLCD,[$FE,$45,$40,STR TestLCD\4]
Goto Main
This code, on the 18f46k22 does NOT work. I can write the to I2C LCD, but I can NOT read/write to the i2c eeproms.
Define OSC 64
C0B0W CON %10100000 'Chip 0, Bank 0, Write
C0B1W CON %10101000 'Chip 0, Bank 1, Write
C0B0R CON %10100001 'Chip 0, Bank 0, Read
C0B1R CON %10101001 'Chip 0, Bank 1, Read
DEFINE I2C_SLOW 1 'have to use slow for the i2c LCD
I2CLCD CON 80
SDA VAR PORTC.4
SCL VAR PORTC.3
I2CADDRESS VAR WORD
SECONDS VAR WORD
i2CTEST VAR BYTE[8]
TESTLCD VAR BYTE[8]
Main:
I2CADDRESS = 0
I2CWRITE SDA,SCL,C0B0W,I2CADDRESS,[65,66,67,68,69,70,71,72,73]
pause 50
i2cread SDA,SCL,C0B0R,I2CADDRESS,[STR I2CTEST\8]
pause 50
HSEROUT ["<TEST>", STR I2CTEST\8, "</TEST>"]
Seconds = Seconds + 1
arraywrite TestLCD ,[DEC4 Seconds]
I2CWRITE SDA,SCL,I2CLCD,[$FE,$45,$40,STR TestLCD\4]
Goto Main
I have 3 bread boards.
Breadboard 1 has an 18f4550 and all the related hardware specific to make the chip run.
Breadboard 2 has an 18F46k22 and all the related hardware specific to make the chip run.
Breadboard 3 has all my I2c eeproms and LCDs connected to it, so I can move it between breadboard 1 and 2.
The only difference between breadboard 1 and 2 as far as the I2C goes, the ports for SDA/SLC are different on the chips.
Both Setups work to the LCD via i2c. Both chips count up and display correctly to the LCD correctly, so I know I2C is working.
Only the 18F4550 Reads and writes to the eeprom. I get <TEST>ABCDEFGH</TEST> back via the serial line on the 18F4550.
On the 18F46K22 I get <TEST>........</TEST> (the .'s are hex 00)
The Eeprom is 24FC1025.
I have tried to isolate this as much as possible, but I'm lost. Any clue? Is something different on PBP3 vs PBP2.5 as far as I2C?
This code from PBP2.5 on an 18F4450 works flawlessly:
Define OSC 48
C0B0W CON %10100000 'Chip 0, Bank 0, Write
C0B1W CON %10101000 'Chip 0, Bank 1, Write
C0B0R CON %10100001 'Chip 0, Bank 0, Read
C0B1R CON %10101001 'Chip 0, Bank 1, Read
DEFINE I2C_SLOW 1 'have to use slow for the i2c LCD
I2CLCD CON 80
SDA VAR PORTB.0
SCL VAR PORTB.1
I2CADDRESS VAR WORD
SECONDS VAR WORD
i2CTEST VAR BYTE[8]
TESTLCD VAR BYTE[8]
Main:
I2CADDRESS = 0
I2CWRITE SDA,SCL,C0B0W,I2CADDRESS,[65,66,67,68,69,70,71,72,73]
pause 50
i2cread SDA,SCL,C0B0R,I2CADDRESS,[STR I2CTEST\8]
pause 50
HSEROUT ["<TEST>", STR I2CTEST\8, "</TEST>"]
Seconds = Seconds + 1
arraywrite TestLCD ,[DEC4 Seconds]
I2CWRITE SDA,SCL,I2CLCD,[$FE,$45,$40,STR TestLCD\4]
Goto Main
This code, on the 18f46k22 does NOT work. I can write the to I2C LCD, but I can NOT read/write to the i2c eeproms.
Define OSC 64
C0B0W CON %10100000 'Chip 0, Bank 0, Write
C0B1W CON %10101000 'Chip 0, Bank 1, Write
C0B0R CON %10100001 'Chip 0, Bank 0, Read
C0B1R CON %10101001 'Chip 0, Bank 1, Read
DEFINE I2C_SLOW 1 'have to use slow for the i2c LCD
I2CLCD CON 80
SDA VAR PORTC.4
SCL VAR PORTC.3
I2CADDRESS VAR WORD
SECONDS VAR WORD
i2CTEST VAR BYTE[8]
TESTLCD VAR BYTE[8]
Main:
I2CADDRESS = 0
I2CWRITE SDA,SCL,C0B0W,I2CADDRESS,[65,66,67,68,69,70,71,72,73]
pause 50
i2cread SDA,SCL,C0B0R,I2CADDRESS,[STR I2CTEST\8]
pause 50
HSEROUT ["<TEST>", STR I2CTEST\8, "</TEST>"]
Seconds = Seconds + 1
arraywrite TestLCD ,[DEC4 Seconds]
I2CWRITE SDA,SCL,I2CLCD,[$FE,$45,$40,STR TestLCD\4]
Goto Main
I have 3 bread boards.
Breadboard 1 has an 18f4550 and all the related hardware specific to make the chip run.
Breadboard 2 has an 18F46k22 and all the related hardware specific to make the chip run.
Breadboard 3 has all my I2c eeproms and LCDs connected to it, so I can move it between breadboard 1 and 2.
The only difference between breadboard 1 and 2 as far as the I2C goes, the ports for SDA/SLC are different on the chips.
Both Setups work to the LCD via i2c. Both chips count up and display correctly to the LCD correctly, so I know I2C is working.
Only the 18F4550 Reads and writes to the eeprom. I get <TEST>ABCDEFGH</TEST> back via the serial line on the 18F4550.
On the 18F46K22 I get <TEST>........</TEST> (the .'s are hex 00)
The Eeprom is 24FC1025.
I have tried to isolate this as much as possible, but I'm lost. Any clue? Is something different on PBP3 vs PBP2.5 as far as I2C?