PinguinoIDE / pinguino-libraries

Pinguino librairies, keywords and other useful files.
24 stars 27 forks source link

18F4550 Fails on slave mode using example slave.pde #6

Closed Visionario closed 9 years ago

Visionario commented 9 years ago

Hi.

I am working with the example slave.pde ( https://github.com/PinguinoIDE/pinguino-libraries/blob/master/examples/04.Communication/i2c/slave.pde ) and connecting a raspberry Model B ver.1 using level shifters to use I2C.

I2C lines come from raspberry (SDA:3 SCL:5) to level shifters and using pull up resistors 2.2k, so, the SDA and SCL lines go to RTC DS1307 and to PIC in SDA:RB0 / SCL:RB1.

The actual example has an address 0x2c for PIC in slave mode but from raspberry it responds with 0x16 and 0x1e simultaneously!!, doing "i2cdetect -y 0" in raspberry the led on RB7 goes to intermittent (blinking) and communication failed, however, PIC still respond with same adresss (0x16 and 0x1e), after that it is neccesary to turn off and turn on the pic to start or pressing the switch to change to programming mode bootloader.

In the code (slave.pde) you can read:

  for(i=0;i<6;i++)  // to show the slave is started waiting interrupts and commands
    {LA7=!LA7; delay(500);}

but it is in setup section not in the loop, besides only blink 2 times in the start.

Calling another adress or other device, then PIC hang up again.

After turn on the PIC i can call it and works fine

pi@Arbolito ~ $ i2cget -y 0 0x16 0x00 
0x01
pi@Arbolito ~ $ i2cget -y 0 0x16 0x01
0x02
pi@Arbolito ~ $ i2cget -y 0 0x16 0x02
0x03
pi@Arbolito ~ $ i2cget -y 0 0x16 0x55
0x56

calling to RTC..

pi@Arbolito ~ $ sudo hwclock -r
Fri 13 Feb 2015 06:52:55 PM VET  -0.496562 seconds

pi@Arbolito ~ $ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- 16 -- -- -- -- -- -- -- 1e --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

After this, then stop communication..

pi@Arbolito ~ $ i2cset -y 0 0x16 0x90
Error: Write failed

and so on

This is the diagram and connections in protoboard: http://goo.gl/ZpYFRq GitHub Logo! NOTES: a) Using a board PinguinoVE got same results. b) Changing PIC for another and another with bootloader 4.14 and 2.12 got same results c) With pull up resistors or without got same results d) Led on RB6 never turn on sending command 0x90 like example e) All grounds are connected

x) Please excuse my english ;-)

Best Regards

@Visionario Asdrubal R. Velasquez Puerto Ordaz - Venezuela

gtcbreizh commented 9 years ago

I loaded the example slave.pde on a 18f4550 and with another 18f4550 I looked for the I2C devices connected to it. The slave was found with 2C as address. It is difficult for me to test your configuration. Nevertheless I shall try more tests during the next days. As you own 2 18f4550 (or 18f2550) would you try the 2 examples master.pde and slave.pde to know if the 2 boards communicate as expected.

Best regards André

gtcbreizh commented 9 years ago

The response 0x16 is in fact 0x2c shifted to the right 0x2c = 0B00101100 when 0x16=0B00010110 I prefer to use directly the 8bits address 00101100 rather than the 7bits address 0010110 which needs a left shift

gtcbreizh commented 9 years ago

Slave.pde is coded to reply to a master program according a specific protocol. Look at master.pde to better understand this protocol : When the slave receives as first character : 0x80 it replies sending its address 2C and the version number 1 0x81 it replies a message (length 4 bytes) : hi!? just for the fun 0x90 followed by 1 the slave switches on a led connected to RB6 0x90 followed by anything else 1 (0 for instance) switches off this previous led 0x90 alone the slave send the RB6 led status 1 for on, 0 for off other character different than 0x80 ,81, 90 it echoes this character +1 ( if "a" is received the reply will be "b". This example is intended to show what is possible. After trying it you have to imagine your own code. Best Regards André