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

I2C 16F690 MCP23017

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



Joined: 12 May 2009
Posts: 2

View user's profile Send private message

I2C 16F690 MCP23017
PostPosted: Tue May 12, 2009 7:49 am     Reply with quote

Hello.

I try to use a 16bits I/O expander (MCP23017) with a PIC 16F690 (as Master).
I have two MCP, one on address 0 (A2/A1/A0 =0), the other on address 1 (A0=1).
Each MCP has 2 8-bits ports (PortA and PortB), address 0x12 and 0x13 for the GPIOA and GPIOB registers.

If I send I2C data to MCP0, it works Smile .
If I send data to MCP0, then to MCP1, the outputs of MCP0 are set to 1 Sad ?

I suspect a timing trouble, but it felt even with a tempo (delay_cycles(50) between each I2c_write() _stop() and _start() ).

Do you have any explanation?
Thanks in advance for your help!

My code:
Code:

#include <16F690.h>

#FUSES NOWDT                    //No Watch Dog Timer
// Clock Out pour DEBUG
//#FUSES INTRC                    //Internal RC Osc
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOCPD                    //No EE protection
#FUSES PUT                      //Power Up Timer
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled

#use delay(clock=8000000)

...
Code:

/*********************************************************/
/* Configuration I2C  16F690: SDA=RB4 SCL=RB6            */
/*********************************************************/
#use i2c(master, scl=Device_SCL, sda=Device_SDA /*, FORCE_HW*/)

// adresses des registres du MCP23017 en mode BANK 0
#define GPIOA   0x12
#define GPIOB   0x13

...
Code:

/////////////////////////////////////////////////////////////////////////
// Ecriture d'un octet dans un registre du MCP23017
/////////////////////////////////////////////////////////////////////////
void Write_PCF(int adresse,int registre,int data)
{
   i2c_start();
   delay_cycles(50);
   i2c_write(64+(adresse*2));
   delay_cycles(50);
   i2c_write(registre);   // numero du registre
   delay_cycles(50);
   i2c_write(data);      // valeur à mettre dans le registre
   delay_cycles(50);
   i2c_stop();
   delay_cycles(50);

   output_float(Device_SCL);
   output_float(Device_SDA);
   delay_cycles(100);

}

...
Code:

////////////////////////////////////////////////////////////////////////
// Initialisation du module DISPLAY
/////////////////////////////////////////////////////////////////////////
void Init_DISPLAY(void)
{
   enable_interrupts(INT_SSP);

// Initialisation des composants I2C (MCP23017 16IO expander)
   Write_PCF(0,IODIRA,00);   // IODIRA   composant 1
   Write_PCF(0,IODIRB,00);   // IODIRB
   Write_PCF(1,IODIRA,00);   // IODIRA   composant 2
   Write_PCF(1,IODIRB,00);   // IODIRB

   Write_PCF(0,GPIOA,0xFF);   // segments/leds éteints
   Write_PCF(0,GPIOB,0xFF);   // segments/leds éteints
   Write_PCF(1,GPIOA,0xFF);   // segments/leds éteints
   Write_PCF(1,GPIOB,0xFF);   // segments/leds éteints
}


...
and the "main" code, in a 20ms-period loop:
Code:

   Write_PCF(0,GPIOA,255-Img_Aff1);
   Write_PCF(0,GPIOB,255-Img_Aff2);
   Write_PCF(1,GPIOA,255-Img_Aff3);
   Write_PCF(1,GPIOB,255-Img_Leds);

with Img_Affx the 8 bits value to be displayed on a 7-segment display (1 bit per segment).

If I use only one of the above lines, it works.
The 4 lines causes only MCP n°1 to have the good output, the MCP0 seems to be "off"...
Even if I execute a 1 single write per 20ms (ie the 4 Writes every 80ms), it "blocks" the MCP n° 0!

Any idea?

By the way, I'm not able to use the i2c_poll() fonction, not recognized by the CCS compiler???

Version CCS: PCWH 4.011
Code:
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 12, 2009 3:17 pm     Reply with quote

Quote:
Version CCS: PCWH 4.011
I'm surprised you got the compiler to produce working code for even a single MCP.
CCS always has two compiler versions available for download, a stable version for production quality code. And the latest version with all the new features but also many bugs. CCS has the bad habit of not marking this difference clearly.
v4.011 was one of the first releases of the v4.xxx compiler and contained lots and lots of bugs. It took about another 50 releases for the compiler to become usable again around v4.060. Versions v4.070 and higher are good, except for the new PCD compiler which at 4.092 still has some open issues.

I didn't look at you program. Even if there is a programming error, the compiler version you use is so broken that it will be just a waste of time. Sorry. If your download rights have expired you can ask CCS to send you the older compiler version that was stable at your time of purchase.
ft77



Joined: 12 May 2009
Posts: 2

View user's profile Send private message

PostPosted: Wed May 13, 2009 1:26 am     Reply with quote

Thank your for your quick reply.

I've tried this morning a Check for SW updates, but the result is
Quote:
No updates are currently available at this time
Evil or Very Mad

So I'm very afraid by your information about the bugs of my version!

I bought this compiler more than one year ago, but if this is the kind of support available, I will look on Microchip' compiler side Laughing (too bad, no version for the 16X family!).

For my MCP problem, I have to confess a beginner's mistake:
First of all, I only have a pull-up resistor on Reset pin, no capacitor to the ground, and it seems that the reset of the circuit was wrong.
Fortunately, I have a free Pin available on the PIC, I use it to tied down the reset when the PIC is starting.
And it seems to be much better!
The second point is maybe the available current: each port have to drive a 7-segment display, and I think the total current is too important. So I have to switch each display half of the time. What I do not understand, I have a common anode, so the MCP has to tied to ground, so an open-drain output should not need such a current?
But It's not a CCS problem, I will look at this point by myself...

Thanks for your support.
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