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 CCS Technical Support

How to unselect I2C-Module the CCS way???

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



Joined: 21 Aug 2017
Posts: 2

View user's profile Send private message

How to unselect I2C-Module the CCS way???
PostPosted: Mon Aug 21, 2017 9:59 am     Reply with quote

The code

#use i2c(MASTER, I2C1, FAST, FORCE_HW, STREAM= Motor)

connects the port pins to the i2c- module.

For diagnostic purposes the sda and scl pins of the bus should be analyzed if a i2c bus lookup event occurred. To get free access to these port pins,
the i2c- module is switched of "by hand" by disabling the i2c- module while
setting I2CEN(bit15) of the I2CxCON (i2c control register) to zero and switch back to i2c- module after checking with #use i2c(MASTER,.........).

Is there a more elegant way to unselect the hardware i2c- module in CCS- C during runtime?

device= PIC24FJ256GB210
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Mon Aug 21, 2017 11:20 am     Reply with quote

This is where the NOINIT option comes in.

Most of the peripherals on modern compilers can be setup using this option.
So:
Code:

#use i2c(MASTER, I2C1, FAST, FORCE_HW, STREAM= Motor, NOINIT)


Then when you want to use it, have:

i2c_init(Motor, TRUE);

Then to disable:

i2c_init(Motor, FALSE);

Similar commands exist for the serial, SPI etc..

Worth saying that using the peripheral name (I2C1), automatically implies FORCE_HW already.
Theodorus



Joined: 21 Aug 2017
Posts: 2

View user's profile Send private message

PostPosted: Mon Aug 21, 2017 11:53 am     Reply with quote

Thanks Ttelmah for pointing me in the right direction, that's the solution I was looking for. You made my day.
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