View previous topic :: View next topic |
Author |
Message |
eng.mohamedtoumi
Joined: 13 Jan 2018 Posts: 23 Location: Tun
|
18F2550 master and atmega328p slave i2c |
Posted: Sun Jan 14, 2018 6:26 pm |
|
|
hello i'm trying to interface an atmega328p as slave on i2c bus to a 18F2550 MCU
(data is sent correctly from the 18F2550 on I2C as shown on I2C debugger ) but there is no
data received on the atmega 328p ?? any help !!!
(there are some screenshots for the project in the links below)
[img]https://ibb.co/m2tUwm[/img]
[img]https://ibb.co/k3Bop6[/img]
[img]https://ibb.co/fjtONR[/img]
[img]https://ibb.co/nkabbm[/img] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Jan 14, 2018 7:25 pm |
|
|
I have to ask WHY you didn't use the hardware I2C of the PIC ?
Also what is Vdd ?
How do you program the PIC, ie what programmer ?
Have you confirmed PIC and ATMEGA are running at correct speeds?
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 14, 2018 8:02 pm |
|
|
The main thing that he needs to do, is to change his 18F2550 code
to talk to a slave address of 0x10. CCS uses 8-bit format (0x10).
Arduino uses 7-bit format (0x08). Make the change shown in bold below:
Quote: |
i2c_start();
i2c_write(0x10);
i2c_write(mode);
i2c_stop(); |
|
|
|
eng.mohamedtoumi
Joined: 13 Jan 2018 Posts: 23 Location: Tun
|
|
Posted: Tue Jan 16, 2018 12:21 pm |
|
|
hello ! ichanged the i2c adress to 0x10 but it is the same problem ... i think that the problem is from the program of the atmel since the data is sent correctly via I2c |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
eng.mohamedtoumi
Joined: 13 Jan 2018 Posts: 23 Location: Tun
|
|
Posted: Tue Jan 16, 2018 1:41 pm |
|
|
yes i found it ... its on address 0x10 while i programmed the Atmel(slave) on address 0x88(i don't know why) ?
... in addition when i try to print the data received from the pic, the Atmel it comes empty.
(it is transmitted correctly from the pic !! Verified with the i2c debugger ) ... i used the code of slave receiver and
i changed the i2c address to the same one that was scanned by the i2c scanner.
https://www.arduino.cc/en/Tutorial/MasterWriter |
|
|
eng.mohamedtoumi
Joined: 13 Jan 2018 Posts: 23 Location: Tun
|
|
Posted: Tue Jan 16, 2018 6:46 pm |
|
|
hello i tried to figure out the problem so i used this sketch for Arduino (i changed the addresses and both pic 18F2550 and Atmega
are connected (problem resolved with the pic i2c slave scanner)) so now the data sent by the pic is not received correctly ...
Like shown in the pictures it says that the number of bytes available in the buffer of i2c is 0 ...
While the i2c interrupt of the Atmega is working correctly ( x is incremented correctly as shown in the atmega sketch and the pictures) ...
So any solutions ?!
ps: mode is an 8 bit variable
https://ibb.co/gO5uGm
https://ibb.co/niNVp6 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 16, 2018 7:36 pm |
|
|
Quote: | i changed the i2c address to the same one that was scanned by the i2c scanner. |
What are they ? Tell us the address that you put into the Arduino
program, and the address used in the PIC program.
Are you aware that Arduino uses 7-bit format for the slave and CCS
uses 8-bit format ? You can not put in the same exact number in both
programs.
Post your slave address values for the Arduino and the PIC. |
|
|
eng.mohamedtoumi
Joined: 13 Jan 2018 Posts: 23 Location: Tun
|
|
Posted: Wed Jan 17, 2018 9:19 am |
|
|
Hello i runned I2c slave scanner on pic it says that the i2c slave is on
0x4F ... since the address of i2c slave on pic must be 8 bit so it is 0x9E in i2cwrite in the pic program ... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Wed Jan 17, 2018 9:20 am |
|
|
Can I now have to assume this is a Proteus project NOT real hardware ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Wed Jan 17, 2018 10:10 am |
|
|
eng.mohamedtoumi wrote: | Hello i runned I2c slave scanner on pic it says that the i2c slave is on
0x4F ... since the address of i2c slave on pic must be 8 bit so it is 0x9E in i2cwrite in the pic program ... |
Er. No.
The address returned by the I2C address program _is_ the address that the PIC needs. If you are using 0x9E, the PIC will not find the device.
However the program cannot return 0x4F as an address. If you look at it, it scans from 0x10 to 0xF0, in steps of 2. So it can't return an 'odd' number like 0x4F..... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 17, 2018 10:19 am |
|
|
It makes me think he is using an Arduino-based scanner. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Wed Jan 17, 2018 11:19 am |
|
|
Except he says:
Quote: |
Hello i runned I2c slave scanner on pic it says that the i2c slave is on
|
The whole thread rings of misleading statements.
You said right at the start for him to run the scanner from the code library, and he really needs to do this. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Wed Jan 17, 2018 6:13 pm |
|
|
I'd like to see a picture of the hardware, though since the numbers are reported on a 'schematic LCD' NOT a PC, I think it's all a simulation. |
|
|
|