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

I2C1 and I2C2

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PROMOD



Joined: 01 Feb 2018
Posts: 42

View user's profile Send private message

I2C1 and I2C2
PostPosted: Fri Nov 23, 2018 7:29 pm     Reply with quote

From the CCS C manual:


I2C1 = Set SDA and SCL to the first module
I2C2 = Set SDA and SCL to the second module

What is first and second module? Someone has told me that some PIC device have two module with SDA and SCL. I2C1 means Set SDA and SCL of DS1307 to first module, with SDA and SCL, of PIC device. If it is so then how will I identify which one is first module?
temtronic



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

View user's profile Send private message

PostPosted: Fri Nov 23, 2018 8:07 pm     Reply with quote

The 'module' really means the internal peripheral, in this case, the PIC will have two MSSP (I2C) hardware 'modules'.
If you look at the front page of any PIC datasheet, they will have a section called 'Perpheral Highlights', usually lower right column. They'll briefly describe what 'modules' are in the PIC.
Being really 'old school', I don't think of a PIC having 'modules', I prefer to call them 'peripherals' cause in the beginning PICs didn't have anything like UARTs, MSSPs, etc. Those devices were external to the PICs. Nowadays, they're builtin, on the same die (piece of silicon), around the core of the PIC.

The PIC you're using has 2 hardware I2C modules, so you can separate I2C device into 2 groups, I2C1 and I2C2. The HUGE benefit of 2 HW modules is that once data is sent to the 'module', the PIC can do other things and not have to 'bitbang' the data. You also get interrupt capability, something a SW (SoftWare) module can't easily do.

You could write an entire book about this and I'm guessing someone already has...
Jay

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 23, 2018 8:12 pm     Reply with quote

Look at the 18F46K22 data sheet:
https://ww1.microchip.com/downloads/en/DeviceDoc/40001412G.pdf
Look at this table on page 7:
Quote:
TABLE 3: PIC18(L)F4XK22 PIN SUMMARY

It shows that SCL1 and SDA1 are on pins C3 and C4 of the PIC.
This is the first i2c module.

It also shows that SCL2 and SDA2 are on pins D0 and D1.
This is the 2nd i2c module.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Nov 24, 2018 2:00 am     Reply with quote

Many things have 'multiples'. Think about it Port A on the PIC has 'multiple' pins A0, A1, A2 etc.. Which pin is 'A0', and which is 'A1', is identified in the data sheet.

The same is true for peripherals. Chips can have multiple I2C's (some DsPIC's have three), Multiple UART's (up to 5), multiple PWM's etc. etc.. In each case for the base PIC's the pins used are identified in the data sheet. More modern PIC's have the feature 'PPS' (Peripheral Pin Select), where _you_ as a programmer can decide which peripheral connects to which pins. You have to do this before using the peripheral concerned.

In your code, the line:

#USE I2C(I2C1, SLOW=100000, STREAM=DS1307)

Means to setup the hardware I2C1 peripheral, to run at 100KHz, using 'slow' timings for transitions etc., and allow this to be talked to by the name 'DS1307'. Stream names become 'essential', once you use more than one peripheral. Otherwise in your code, remembering 'which' port to use will become hard work.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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