View previous topic :: View next topic |
Author |
Message |
qipan
Joined: 28 Apr 2010 Posts: 3
|
Problem with I2C slave with PIC16F1827 |
Posted: Wed Apr 28, 2010 2:53 am |
|
|
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
|
|
Posted: Wed Apr 28, 2010 1:28 pm |
|
|
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
|
|
Posted: Thu Apr 29, 2010 2:09 am |
|
|
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
|
|
Posted: Thu Apr 29, 2010 8:14 am |
|
|
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
|
Does your i2c has one more ground line? |
Posted: Sat Aug 21, 2010 9:11 am |
|
|
Does your i2c has one more ground line?
When debugging, there is a ground between your chip and the computer. |
|
|
|