Author Topic: I2C not working on PIC18F  (Read 2722 times)

0 Members and 1 Guest are viewing this topic.

Offline woody

  • Frequent Contributor
  • **
  • Posts: 423
  • Country: nl
Re: I2C not working on PIC18F
« Reply #25 on: October 31, 2024, 01:11:57 pm »
I made a simple program to use i2c to read the time from a DS3231 slave (client) to a PIC18f46K40 master (host).

The code works fine on a breadboard and contains no delays and/or strange tests on BF bits etc.

I attached a zip file containing:

main.c : the program
main - Commented.lst : a list file with added comments to explain what happens where, at least as far as I understand it. I might be wrong on some details.
DS3231MPMB1/pdf : datasheet of the breakout board of the DS3231 I used.
Breadboard.jpg : picture of the breadboard with the test.
quicksave_1_screen.png : screenshot of the scope showing the reading of 3 registers from the slave (client).
quicksave_2_screen.png : screenshot of the scope showing the reading of 3 registers from the slave (client), 4 seconds later.

(the time in the DS is not set to the correct time of day)

AKAICS a lot of your code is the same, excluding all the while statements. The problem might also be in the display code (that I completely left out) or in other parts of your code that are invisible to me.  Anyway, you have a working example now so I hope this helps you to get it going.

As I said earlier, this problem intrigued me. I went a bit overboard on it, but hey, I always learn something along the way. If you have questions just ask, but now I need to point my attention to some money-making activities ;D
 
The following users thanked this post: newtekuser

Offline newtekuserTopic starter

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: us
Re: I2C not working on PIC18F
« Reply #26 on: November 01, 2024, 05:33:23 am »
I made a simple program to use i2c to read the time from a DS3231 slave (client) to a PIC18f46K40 master (host).

The code works fine on a breadboard and contains no delays and/or strange tests on BF bits etc.

I attached a zip file containing:

main.c : the program
main - Commented.lst : a list file with added comments to explain what happens where, at least as far as I understand it. I might be wrong on some details.
DS3231MPMB1/pdf : datasheet of the breakout board of the DS3231 I used.
Breadboard.jpg : picture of the breadboard with the test.
quicksave_1_screen.png : screenshot of the scope showing the reading of 3 registers from the slave (client).
quicksave_2_screen.png : screenshot of the scope showing the reading of 3 registers from the slave (client), 4 seconds later.

(the time in the DS is not set to the correct time of day)

AKAICS a lot of your code is the same, excluding all the while statements. The problem might also be in the display code (that I completely left out) or in other parts of your code that are invisible to me.  Anyway, you have a working example now so I hope this helps you to get it going.

As I said earlier, this problem intrigued me. I went a bit overboard on it, but hey, I always learn something along the way. If you have questions just ask, but now I need to point my attention to some money-making activities ;D

Thanks a lot for giving this a try on your end! It is intriguing to see it is working for you, so I can't help but wonder if it's the XC8 compiler in my case issue vs CSS for you.
Will have to re-create my setup from scratch on a "virgin" breadboard as the one I'm using has all kinds of components and wires on it.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf