Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with I2C on PIC24

Status
Not open for further replies.

Nigel Goodwin

Super Moderator
Most Helpful Member
I wonder if anyone can offer any suggestions?.

I'm playing with the I2C hardware on a PIC24FJ64GA002 using the I2C code from http://www.engscope.com/pic24-tutorial/10-2-i2c-basic-functions/ along with a tutorial board I've built containing a FRAM and an I2C expansion socket, I'm using 10K pullups. With just the FRAM connected it all works fine, the test program simply reads four bytes at a time from the FRAM, displays them via RS232, and also lists all devices found on the bus - in this case just 0xA0.

This is a cut and paste of it working:

0xD5, 0x00, 0xD8, 0x01
Addresses on I2C - 0xA0

If I power it down and plug another device in the expansion port (I've got I2C LCD boards, and DS3231/DS1307 clocks) then it doesn't work at all, the four bytes read as zeros, and it lists 128 I2C addresses - there's also no activity on the I2C bus according to my scope.

If instead of powering it down I simply insert the extra device (with it still powered up), it works perfectly - and I can even display data on the LCD display, and here's the RS232 data:

0xD5, 0x00, 0xCF, 0xFD
Addresses on I2C - 0x7E, 0xA0

The FRAM data bytes have been updated to the next four, and the I2C LCD adaptor address has been added at 0x7e.

Likewise, adding a DS3231 gives:

0xDA, 0xFA, 0xD7, 0xF9
Addresses on I2C - 0xA0, 0xAE, 0xD0

The DS addresses of 0xAE and 0xD0 have been added.

I can even add both:

0xDD, 0xF9, 0xDF, 0xF7
Addresses on I2C - 0x7E, 0xA0, 0xAE, 0xD0

So any clues as to why it won't power up and work with other devices attached?.
 
Hi Nigel A first read the 10k pullups look a bit high, I have done a lot projects with pic24 and I2C only ever used 2k2. what speed I2C have you coded...?
Edit That link is a great starting place ...
 
Hi Nigel A first read the 10k pullups look a bit high, I have done a lot projects with pic24 and I2C only ever used 2k2. what speed I2C have you coded...?

I'm using 100K I2C, I used 10K because the DS3231 and I2C/LCD boards already include their own pullups - so I didn't want it to go too low - so when it doesn't work the pullups are considerably lower (the two extra boards each have 4.7K pullups).

With the scope connected the rise time is better with the extra boards plugged in, but only if you plug them in after it's powered up :D
 
I suspect a bus collision at I2C start , when all devices connected . In the past i have TRISed I2C port pins as outputs, made them high , then back to inputs , then enabled I2C.
 
Thanks again grandad, I've currently got my pic24 board reading a DS3231, and displaying a clock on both a 4 bit mode LCD, and an I2C LCD as well :D

I've also been writing and reading to FRAM and EEPROM throughout the day.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top