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 Scanner problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Toast



Joined: 15 Aug 2019
Posts: 16

View user's profile Send private message

I2C Scanner problem
PostPosted: Tue Aug 27, 2019 3:55 am     Reply with quote

Hi everyone , I am testing my device with i2c scanner. However, it could not find any i2c and I investigate into it and found my problem could not finish execute the i2c_write. Basically, the method i used to test is to turn on a LED every line. Although i found the problem, i couldn't understand how it happens. I would like to ask what will cause the problem i encountered and how to solve it ?
Code:
#include <16F15356.h>
#device ADC=10
#use delay(internal=4MHZ)
#use i2c(Master, sda=PIN_B2, scl=PIN_B1)
#define LED pin_a2

// This function writes the slave address to the i2c bus.
// If a slave chip is at that address, it should respond to
// this with an "ACK".   This function returns TRUE if an
// ACK was found.  Otherwise it returns FALSE.
int8 get_ack_status(int8 address)
{
int8 status;

i2c_start();
//output_high(LED);
status = i2c_write(address);  // Status = 0 if got an ACK
output_high(LED);        //      The LED did not turn on
i2c_stop();

if(status == 0)

   return(TRUE);
else

   return(FALSE);

}


//=================================
void main()
{
unsigned int8 i;
unsigned int8 status;
unsigned int8 count = 0;

output_high(pin_B0);

// Try all slave addresses from 0x10 to 0xEF.
// See if we get a response from any slaves
// that may be on the i2c bus.
for(i=0x10; i < 0xF0; i+=2)
   { 
    status = get_ack_status(i);
    if(status == TRUE)
      { 
       count++;
       delay_ms(2000);
      }
   }

if(count == 0)
 // output_low(LED);
else
 //   output_high(LED);

while(1);
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 4:22 am     Reply with quote

more info needed
1) VDD of PIC...

2) I2C device you're trying to test

3) you have run a '1Hz LED' program to confirm the PIC is operating at correct speed ?
Toast



Joined: 15 Aug 2019
Posts: 16

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 4:46 am     Reply with quote

The VDD is 3.7V and the device I am testing is ICM-20948 and here is the datasheet for ICM-20948: https://www.invensense.com/wp-content/uploads/2016/06/DS-000189-ICM-20948-v1.3.pdf
Toast



Joined: 15 Aug 2019
Posts: 16

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 5:01 am     Reply with quote

temtronic wrote:
more info needed
1) VDD of PIC...

2) I2C device you're trying to test

3) you have run a '1Hz LED' program to confirm the PIC is operating at correct speed ?


Sorry but how can I get the frequency formula?
I got a 31Hz LED flashing with the following code
Code:

#include <16F15356.h>
#device ADC=10
#use delay(internal=4MHZ)

#INT_TIMER1
void timer1_isr(void)
{
set_timer1(63536);
output_toggle(LED);


}
void main()
{
 enable_interrupts(INT_TIMER1);             
  enable_interrupts(GLOBAL);                 
  setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );
  set_timer1(63536);                 
  while(1);         
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 6:56 am     Reply with quote

It's not going to work.

The device only supports up to 1.95v for VddIO. The output 'high' level
is allowed to go only go up to this. Your PIC at 3.7V, requires an I/O signal
that reaches as least 2.96v. You need a signal buffer between this and
the PIC.
What voltage are you taking your I2C pull up resistors to?. Hopefully not
the 3.7v. This is illegally high for the chip if so.
Toast



Joined: 15 Aug 2019
Posts: 16

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 7:30 am     Reply with quote

It does not have any resistor externally connected between the PIC and the ICM-20948 Sad What is the VddIO used for?
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 8:11 am     Reply with quote

Toast wrote:
What is the VddIO used for?


It's in the name: power supply (Vdd) for the external signals (I/O).
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Tue Aug 27, 2019 9:04 am     Reply with quote

You should read the datasheet carefully, as it tells you all of the operating and maximum voltage ratings of everything on the chip.

For example, VddIO should never reach above 2.5V or else it could immediately and permanently damage the chip. VddIO typical operating condition is even lower, at 1.8V. This is what you should be aiming for.

As for not having the resistors externally connected, that is another reason why you cannot detect your device. I2C protocol specifies that lines are either floating or pulled to ground. You need to have pull up resistors on each line of the I2C bus. Section 4.2 of your device datasheet covers this.

If you google "i2c sparkfun", there is a very helpful tutorial that covers the basics of what is i2c, along with the hardware that you should set up, and the protocol.

However, before wiring any of this up, you had better get yourself some level conversion hardware to convert the logic voltages of your PIC into the logic voltages of your devices so you don't burn it out when you try and connect it.
Toast



Joined: 15 Aug 2019
Posts: 16

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 10:23 am     Reply with quote

Is that the SDA, SCL , AD0 all require the pull up resistors? Can i have them pull up by the software using PIC?
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Tue Aug 27, 2019 10:38 am     Reply with quote

There's the NOFLOAT_HIGH option for the #use i2c directive but I have never used that so I don't know if it works. Why not build the hardware properly?

Besides that, you still need to deal with your voltage levels discrepancy between the PIC and your peripheral.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 10:51 am     Reply with quote

You also need to tell us if you are using the ICM-20948 chip by itself,
on a board you built, or did you buy a module board with that chip on it ?

If you bought an ICM-20948 module board, then post a link to the website
for that board.

In other words, I want know if you bought a module board, and it has
level shifters on it.
Toast



Joined: 15 Aug 2019
Posts: 16

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 11:01 am     Reply with quote

PCM programmer wrote:
You also need to tell us if you are using the ICM-20948 chip by itself,
on a board you built, or did you buy a module board with that chip on it ?

If you bought an ICM-20948 module board, then post a link to the website
for that board.

In other words, I want know if you bought a module board, and it has
level shifters on it.


It is the chip by itself
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 11:02 am     Reply with quote

You most definitely _must not_ let the PIC pull the lines up.
Doing this would destroy the ICM-20948 chip.

You need level shifters.

You also need a supply for VddIO. Level shifters, and pull up resistors
to VddIO on the ICM-20948, and pull ups to 3.7v on the PIC side.
Sparkfun do a little board with the level shifter circuit.
Toast



Joined: 15 Aug 2019
Posts: 16

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 11:13 am     Reply with quote

dluu13 wrote:
There's the NOFLOAT_HIGH option for the #use i2c directive but I have never used that so I don't know if it works. Why not build the hardware properly?

Besides that, you still need to deal with your voltage levels discrepancy between the PIC and your peripheral.


Sorry the VDD of my PIC is 3.3V.
For the voltage level conversion, can i use the voltage divider?
Code:

                         +3.3v
                            |
                            <
                            > 10k       
                            <         
ICM20948                    |
vddIO pin                   |    12k
  ----- -------------- ---------v^v------- || GND
                     
Vout / 3.3  = 12k / (10k+12k)
Vout = 1.8V

newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Tue Aug 27, 2019 11:14 am     Reply with quote

Depends. How much current does the VddIO pin draw?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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