zydis
Posts: 2
Joined: Tue Mar 08, 2016 7:22 am

Raspi and Pic i2c problem

Tue Mar 08, 2016 7:47 am

Hi, I am using raspi as master and pic18f67k22 as slave.
Here is my code to define i2c for pic.

Code: Select all

#use i2c(SLAVE, sda=PIN_d5, scl=PIN_d6, address = 0x40)
when I use this command at raspi terminal, address of pic is shown half of 0x40.

Code: Select all

pi@raspberrypi ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Then whenever I use "sudo i2cdetect -y 1" raspi return nothing.

Code: Select all

pi@raspberrypi ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Do you have any idea about this problem?

User avatar
brekee12
Posts: 335
Joined: Wed Feb 03, 2016 3:36 pm
Location: HU

Re: Raspi and Pic i2c problem

Tue Mar 08, 2016 10:32 am

Probably it is only a "ghost" signal. Check your I2C pins I can remember other pins.
Brekee12
on a Raspberry B+ with whezzy, two Zero with Jessie Light

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8931
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Raspi and Pic i2c problem

Tue Mar 08, 2016 10:59 am

I2C has an 8 bit slave address field. The top 7 bits are the device id, and the bottom bit is the read/write bit.
Some systems use the entire 8 bit value when referring to an address. Others (including Linux) only use the actual address bits.
It sounds like your PIC is taking 0x40 as the full 8 bit value, so Linux sees half of it when it has knocked off the bottom direction bit.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

zydis
Posts: 2
Joined: Tue Mar 08, 2016 7:22 am

Re: Raspi and Pic i2c problem

Tue Mar 08, 2016 1:48 pm

And also i2c address map on raspi is not permanent. After first search address of 0x20 is disapearing and "sudo i2cdetect -y 1" shows nothing.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8931
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Raspi and Pic i2c problem

Tue Mar 08, 2016 2:03 pm

zydis wrote:And also i2c address map on raspi is not permanent. After first search address of 0x20 is disapearing and "sudo i2cdetect -y 1" shows nothing.
I'm no expert on PICs, but typically you need to give it some data to send back on a read (which is what i2cdetect is using). Does it send anything if the transmit FIFO is empty? Quite possibly not.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

andornot
Posts: 4
Joined: Wed Mar 27, 2013 2:23 pm

Re: Raspi and Pic i2c problem

Sun Jun 11, 2017 9:43 pm

It looks like you are using the CCS PICC compiler. In your #USE statement the address must be 2 x the address you wish it to be. If you want the address to be 0x40, you must enter 0x80 in the address field of the #USE like this:

Code: Select all

#use i2c(SLAVE, sda=PIN_d5, scl=PIN_d6, address = 0x80)

Return to “Interfacing (DSI, CSI, I2C, etc.)”