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

[SOLVED] about TCA9535

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



Joined: 13 Aug 2004
Posts: 59
Location: Turkey

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

[SOLVED] about TCA9535
PostPosted: Wed Oct 05, 2016 8:20 am     Reply with quote

Hi,

I have connected a TCA9535 to my pic18F6310
using ccs 4.135.
Every setup of my i2c is ok. I can read from my eeprom etc.
I think I have initiating problem of TCA9535.

When I read the input of the TCA9535 I get all 1, what could be the problem?
My code is as follows:
Code:

void main(void)
{
char a;
init_prog();
sleep();
IOpin.modulepower=0;
enable_interrupts(INT_TIMER1);
//------------------------------------------------------------------------------
for(;;)
{
// set port0 as input   
i2c_start();
   i2c_write(0x40);
   i2c_write(0x06);
   i2c_write(0xFF);
   i2c_stop();

// set port1 as input   
   i2c_start();
   i2c_write(0x40);
   i2c_write(0x07);
   i2c_write(0xFF);
   i2c_stop();

// set port0 as no polarity
   i2c_start();
   i2c_write(0x40);
   i2c_write(0x04);
   i2c_write(0x00);
   i2c_stop();

// set port1 as no polarity   
   i2c_start();
   i2c_write(0x40);
   i2c_write(0x05);
   i2c_write(0x00);
   
do{
// read port0   
i2c_start();
   i2c_write(0x41);
   i2c_write(0x00);
   i2c_start();
   rfdata1=i2c_read(1);
   i2c_stop();

//read port1   
   i2c_start();
   i2c_write(0x41);
   i2c_write(0x01);
   i2c_start();
   rfdata2=i2c_read(1);
   i2c_stop();

printf("rfdata1=%u\r\n",rfdata1);
printf("rfdata2=%u\r\n",rfdata2);
}while(1==1);
}

_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.


Last edited by scanan on Wed Oct 05, 2016 8:54 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Oct 05, 2016 8:50 am     Reply with quote

Look at Figure 29. You are not handling the read correctly.

In I2C, the standard sequence for read, is:

Send start
Send write address of chip
Send register address you want to talk to.
Send restart
Send read address of chip
Then you start actually reading.

This is what figure 29 shows.
Code:

// read port0   
   i2c_start();
   i2c_write(0x40); //I2C write address of chip
   i2c_write(0x00); //write the register address
   i2c_start(); //now the restart
   i2c_write(0x41); //only now select the 'read' I2C device
   rfdata1=i2c_read(1);
   i2c_stop();


You are trying to write the register address to a device set to read. With I2C, as soon as the address byte is transferred with the R/W bit set 'read', the bus switches round.
scanan



Joined: 13 Aug 2004
Posts: 59
Location: Turkey

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

PostPosted: Wed Oct 05, 2016 8:54 am     Reply with quote

many thanks works fluently Smile
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.
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