PIC24 I2C issue - Page 1
Forum section: electronics / general

author: diyaudio
author_rank: Frequent Contributor
timestamp: March 31, 2014, 11:51:56 am
content: Hi GuysI have a issue with getting my I2C bus to transmit data on the PIC24FJ128GB210, no clock or data is present its probably a configuration issue that I haven't considered. I checked the datasheet and all seems okay from what I read. I didn't check the errata for the PIC24FJ128GB210 cannot seem to find it.Here are the code snippets.Code:// Clock is 16mhz, fcy = 8mhz// make TRISA14, TRISA14 inputs.TRISAbits.TRISA14 = 1;TRISAbits.TRISA15 = 1;// map SDI2 AND SCK2PPSUnLock;iPPSInput( IN_FN_PPS_SDI2, IN_PIN_PPS_RPI35 );iPPSInput( IN_FN_PPS_SCK2IN, IN_PIN_PPS_RPI36 );PPSLock;// Im sending test data as a test in the loop.void main(){__delay_us(100);// send datadata_send_i2c();}void data_send_i2c(void){// 1) Master sends STart //CloseI2C2(); // Disable I2C1 mdoule if enabled previouslyunsigned int config1 = (I2C_ON | I2C_7BIT_ADD );unsigned int config2 = 78;// I2CxBRG 100kHz bus with 16MHz oscillatorOpenI2C2(config1,config2); // configure I2C1IdleI2C2();// 1) Master sends STartStartI2C2();while(I2C2CONbits.SEN ); // Wait till Start sequence is completedMI2C2_Clear_Intr_Status_Bit; // Clear interrupt flag// 2) Master sends Slave ADdress with Write bit set //MasterWriteI2C2( 0xff ); //Write Slave address and set master for transmissionwhile(I2C2STATbits.TBF); //Wait till address is transmittedwhile(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle// dont ask the slave for any ack this is a test ? see anything on the scope yet???}This issue was keeping me busy all weekend with no luck. Please help.

author: jmag999
author_rank: Contributor
timestamp: March 31, 2014, 12:08:07 pm
content: It looks like you are mapping SPI ports to those pins. I2C pins do not go through the PPS matrix.

author: diyaudio
author_rank: Frequent Contributor
timestamp: March 31, 2014, 01:07:05 pm
content: Quote from: jmag999 on March 31, 2014, 12:08:07 pmi see what you mean I corrected the problem and removed the PPS as suggested and used PINS 58 , 59.used the pins see attachment. still no luck. bah!

author: jmag999
author_rank: Contributor
timestamp: March 31, 2014, 01:16:39 pm
content: Next problem is that you are calling the I2C(2) functions, but your hardware is attached to the I2C1 peripheral.

author: diyaudio
author_rank: Frequent Contributor
timestamp: March 31, 2014, 01:22:30 pm
content: Quote from: jmag999 on March 31, 2014, 01:16:39 pmI have no hardware connected.. only the scope on pins 58 and 59 as i just want to verify the clock and data. any data nothing important yet.

author: jmag999
author_rank: Contributor
timestamp: March 31, 2014, 01:30:14 pm
content: Take a look at the pin names on the pinout you attached on the first post. It shows SCL1 and SDA1. This means that you are connected to I2C port 1. But your code is writing to I2C port 2, because you are using functions like IdleI2C2();. Change them to xxxxI2C1() and it should work.

author: diyaudio
author_rank: Frequent Contributor
timestamp: March 31, 2014, 01:37:01 pm
content: Quote from: jmag999 on March 31, 2014, 01:30:14 pmI have moved it to pins 58, 59 which should be the correct I2C-2 peripheral the first time it was incorrect. now the code is referencing I2C2. see the previous attachment.

author: diyaudio
author_rank: Frequent Contributor
timestamp: March 31, 2014, 03:59:23 pm
content: still no luck. gosh im starting to doubt the #include "spi.h" library does it even work.

author: jmag999
author_rank: Contributor
timestamp: March 31, 2014, 04:14:53 pm
content: Do you have pull-ups on the bus?

author: granz
author_rank: Regular Contributor
timestamp: March 31, 2014, 04:29:18 pm
content: Quote from: jmag999 on March 31, 2014, 04:14:53 pmWas literally just writing that same thing. The PIC I2C outputs are open-drain type, so you'll get nothing with just the scope connected and no pull-ups.

author: diyaudio
author_rank: Frequent Contributor
timestamp: March 31, 2014, 10:50:02 pm
content: Quote from: jmag999 on March 31, 2014, 04:14:53 pm@jmag999, @granzThanks guys, its working correctly now, I used a 4.7k pull-up. it works. nicely.

author: dannyf
author_rank: Super Contributor
timestamp: April 01, 2014, 10:56:51 am
content: If the sender / receiver pins have pull-up, you may be able to get by with that.

author: granz
author_rank: Regular Contributor
timestamp: April 01, 2014, 02:27:08 pm
content: Quote from: dannyf on April 01, 2014, 10:56:51 amI believe enabling the I2C pins overrides all other peripherals including the regular I/Os, and the internal pull-ups are part of the change-notification circuitry for regular I/Os. Anyhow, the internal pull-ups are of the weak variety, and not suited for I2C...