I2C on Pic 12f675

Status
Not open for further replies.

dr_when

New Member
Hi,

New here, but thought I would try after not finding a solution as of yet. I have been using the Oshonsoft Basic Compiler for Pic for a number of years and have always managed to work around problems that I have had. I have gotten frustrated at times with how Vladimir has handled his dev tools but I keep reminding myself that the cost is pretty low.

I am currently trying to use a pcf8574t based LCD backpack that works just fine with Arduino boards. I am trying to get it to work with the 12f675. As I examine the data captures I have made with a Saleae Logic device, my low level commands are messed up. I cannot seem to send commands using a slave address of 0x27 which is what the pcf8574 wants. The address comes out as 0x13 and read/write depending on my sending 0x27 or 0x26. Before I resort to writing something in assembly to do this I thought I would reach out and see if anyone can shine more light on Vladimir's I2c commands. Perhaps I am doing something wrong

I have to say I have had some pretty complex pieces of code run with no issues but this has me stumped. Any ideas? Thanks in advance.

Here is what I have tried. Also changed 0x27 to 0x26 for read/write.

UPDATE: If I use an I2C slave address of 0x4e, it gets shifted in as 0x27 and works correctly. This has the feeling of a bug. Attached is a capture of what I get when sending 0x4e instead of 0x27 which is the real slave address.


Define CONFIG = 0x0194

'attempt i2c lcd backpack on 12f675

'*************************************************
'adjust osccal
ASM: Call 0x03ff
ASM: bsf status,5
ASM: movwf OSCCAL
ASM: bcf status,5
'*************************************************
CMCON = 7
ANSEL = 0

Symbol SCL = GPIO.2
Symbol SDA = GPIO.1

Dim slave_addr As Byte

slave_addr = 0x27

'*************************************************************************

I2CPrepare SDA, SCL

WaitMs 500

I2CStart
I2CSend slave_addr
I2CSend 0x30
I2CStop

WaitUs 500

I2CStart
I2CSend slave_addr
I2CSend 0x34
I2CStop


End
 

Attachments

  • capture wave.png
    7.8 KB · Views: 511
Last edited:
Ah!! confusion... An I2C address is 7 bit... always is.. the LSbit is the read/write bit

7,6,5,4,3,2,1,RW <-- 8 bits so 0x27 << 1 = 0x4E then 0x4F to read..

BUT!!!! I've used the PCF8574, and I don't remember that being the address... If the A0~A2 pins are low its just 0x40 for write and 0x41 for read..
 
Last edited:
Thanks for the reply. I just needed to look at this table better!!!
 

Attachments

  • table.png
    46.1 KB · Views: 467
Just an update . The Pcf8574 works fine using any two pins on the 12f675 (except mclr of course) and the size of the code isn't bad either. No optimization, merely parroting the .cpp code in the Arduino for that same backpack. Usable for the project I am working on. I have attached the code for a simple demo. There are sure to be some bugs and it is set for a 2 line-16 char display.
 

Attachments

  • i2c_lcd_rev1.bas
    3.9 KB · Views: 475
Arduino 'wire' shifts the address << 1 then somehow includes the W/R bit .. Device data sheet addresses can be either .. Wait till you get to I2C the PIC18FxxK42 series. that is fun !
 
Yes, what the Arduino did, threw me for a bit. I have stumbled on this kind of thing before.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…