CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

18F2550 master and atmega328p slave i2c
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
eng.mohamedtoumi



Joined: 13 Jan 2018
Posts: 23
Location: Tun

View user's profile Send private message Visit poster's website

18F2550 master and atmega328p slave i2c
PostPosted: Sun Jan 14, 2018 6:26 pm     Reply with quote

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: 20381

View user's profile Send private message

PostPosted: Sun Jan 14, 2018 7:02 pm     Reply with quote

Run this i2c bus scanner program on your 18F2550 and tell us what it
reports for the i2c slave address of the AtMega:
http://www.ccsinfo.com/forum/viewtopic.php?t=49713
temtronic



Joined: 01 Jul 2010
Posts: 6247
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 14, 2018 7:25 pm     Reply with quote

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: 20381

View user's profile Send private message

PostPosted: Sun Jan 14, 2018 8:02 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 16, 2018 12:21 pm     Reply with quote

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: 20381

View user's profile Send private message

PostPosted: Tue Jan 16, 2018 12:58 pm     Reply with quote

Did you run the i2c scanner program in the CCS code library ?
If your Atmel slave is running correctly, the i2c scanner program
will find it.
http://www.ccsinfo.com/forum/viewtopic.php?t=49713
Run that program.
eng.mohamedtoumi



Joined: 13 Jan 2018
Posts: 23
Location: Tun

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 16, 2018 1:41 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 16, 2018 6:46 pm     Reply with quote

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: 20381

View user's profile Send private message

PostPosted: Tue Jan 16, 2018 7:36 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Jan 17, 2018 9:19 am     Reply with quote

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: 6247
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 17, 2018 9:20 am     Reply with quote

Can I now have to assume this is a Proteus project NOT real hardware ?
Ttelmah



Joined: 11 Mar 2010
Posts: 13517

View user's profile Send private message

PostPosted: Wed Jan 17, 2018 10:10 am     Reply with quote

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: 20381

View user's profile Send private message

PostPosted: Wed Jan 17, 2018 10:19 am     Reply with quote

It makes me think he is using an Arduino-based scanner.
Ttelmah



Joined: 11 Mar 2010
Posts: 13517

View user's profile Send private message

PostPosted: Wed Jan 17, 2018 11:19 am     Reply with quote

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: 6247
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 17, 2018 6:13 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group