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

Problem with I2C slave with PIC16F1827

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



Joined: 28 Apr 2010
Posts: 3

View user's profile Send private message

Problem with I2C slave with PIC16F1827
PostPosted: Wed Apr 28, 2010 2:53 am     Reply with quote

Hi

The MSSP2 serial port on the PIC16F1827 has been configured as an I2C slave and I believe the configuration is right after checking live numbers of SFRs in MPLAB. But it fails to acknowledge the master by pulling SDA2 line low to a valid slave address (0xA8), no matter how I try and change the configuration of relevant SFRs.

The port configuration is
Code:
   
SSP2ADD = 0xA8;   
SSP2MSK = 0xFE;
SSP2CON1 = 0x1E;
SSP2CON3 = 0x00;   
SSP2CON2 = 0x01;

The SDA2 and SCL2 pins have all been configured as inputs per datasheet.

Also the datasheet says the ACK response in slave mode is generated by the hardware if AHEN and DGEN bits are clear.

I use latest PCM compiler Ver4.107 and V8.50 MPLAB.

Anyone can help?

Thanks
_________________
Pan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 1:28 pm     Reply with quote

Post short little compilable test programs for the master and the slave
that demonstrate the problem.

Also, do you have 4.7K pull-up resistors on the SDA and SCL lines ?
qipan



Joined: 28 Apr 2010
Posts: 3

View user's profile Send private message

PostPosted: Thu Apr 29, 2010 2:09 am     Reply with quote

Sorry, here is the initialization for MSSP2

Code:
void I2C2Init(void)
{

   UINT8 backup;
    backup = GIE;    //save interrupt state for the time being
   GIE = 0;              //disable all interrupts

   SSP2EN = 0;           //disable I2C2

   // Init ISR variables
    Addressed = 0;
   I2C2Flags = 0;      //clear all flags

    // Configure I2C hardware and let it go
   SSP2ADD = 0xA8;      //LNB MCU address is A8
   SSP2MSK = 0xFE;      //do not mask address   
   SSP2BUF = 0x00;      //I2C Data Register/Buffer
    SSP2CON1 = 0x1E;   //enable clock, 7bit I2C slave, start/stop interrupt
   SSP2CON2 = 0x01;   //enable clock stretching for both transmit and receive
   SSP2CON3 = 0x00;   //test


   SMP2 = 1;         //SSPSTAT.7, select standard speed (100kHz/1MHz)
   CKE2 = 0;         //disable SM bus specific inputs
   SEN2 = 1;

   SSP2OV = 0;         //initialise overload indicator
   SSP2IF = 0;         //initialise interrupt flag

   SSP2IE = 1;         //enable SSP interrupt
   GIE = backup;    //restore interrupt
   SSP2EN = 1;           //enable I2C

}


There are pull-up resistors on SDA and SCL lines attached to the I2C master which is a National Instrument I2C interface box NI USB-8451.

On the same pcb board, apart from the 16F1827 slave, there are two more I2C slaves (16F886) linked to the same master. These two slaves work fine with the master and their I2C ISR is basically the same as that used for 16F1827.

The key issue here is why the 16F1827 slave does not respond to the first device address call by sending an acknowledge bit. This is supposed to be done entirely by the hardware according to the datasheet.

Thanks
_________________
Pan
qipan



Joined: 28 Apr 2010
Posts: 3

View user's profile Send private message

PostPosted: Thu Apr 29, 2010 8:14 am     Reply with quote

After more testing, I have some good news here. The PIC16F1827 I2C slave can actually work if the code is built and downloaded in MPLAB debugger mode with ICD3. However, if it is done in the programmer mode, the I2C port would not work, even though the code is the same.

Any ideas?
_________________
Pan
linqing171



Joined: 21 Aug 2010
Posts: 1

View user's profile Send private message

Does your i2c has one more ground line?
PostPosted: Sat Aug 21, 2010 9:11 am     Reply with quote

Does your i2c has one more ground line?
When debugging, there is a ground between your chip and the computer.
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