I2C fails when using PLL 80Mhz

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
galeforce9
Posts: 6
Joined: 25 Sep 2011 09:10

I2C fails when using PLL 80Mhz

#1 Post by galeforce9 » 06 Oct 2011 20:19

Hi All,

After many hours trying to get theI2C working I have found an issue.
Using the example for the EEPROM supplied by Mikro as shown below when compiled with the default settings of

Primary Osc (XT+,HS,EC) and Osc Freq = 8.000000 Mhz

everything works fine, however if you compile with

Primary Osc w/pll (XT+,HS,EC+pll) and Osc Freq = 80.000000 Mhz

the I2C bus fails to function correctly with the RA2 clock line staying mostly low instead of high.

The code continues to run but the writing and reading from the EEPROM now fails!
I have a large project which needs to run at 80Mhz but now stuck as I am unable to get the I2C to function. I am using the LV32MXv6 dev board with the pic32mx460.
I have tried changing to the I2C init advanced and other bits but can not get this to function with the PLL.

Any help creatly appreciated as I need to complete the project ASAP.

Ian

Code: Select all


program I2C_Simple

dim i, b as char
    atest as word

sub procedure EEPROM_24C02_Init()
  I2C2_Init(100000)
  'I2C2_Init_Advanced(80000, 100000)

end sub

'--------------- Writes data to 24C02 EEPROM - signle location
sub procedure EEPROM_24C02_WrSingle(dim wAddr as byte, dim wData as byte)
  I2C2_Start()           ' issue I2C start signal
  I2C2_Write(0xA0)       ' send byte via I2C  (command to 24cO2)
  I2C2_Write(wAddr)      ' send byte (address of EEPROM location)
  I2C2_Write(wData)      ' send data (data to be written)
  I2C2_Stop()
end sub

'--------------- Reads data from 24C02 EEPROM - single location (random)
sub function EEPROM_24C02_RdSingle(dim rAddr as byte) as byte
  I2C2_Start()              ' issue I2C start signal
  I2C2_Write(0xA0)          ' send byte via I2C  (device address + W)
  I2C2_Write(rAddr)         ' send byte (data address)
  I2C2_Restart()            ' issue I2C signal repeated start
  I2C2_Write(0xA1)          ' send byte (device address + R)
  result = I2C2_Read(1)     ' Read the data (NO acknowledge)
  I2C2_Stop()
end sub

main:
  AD1PCFG = 0xFFFFFFFF                 ' Configure AN pins as digital I/O

  LATB = 0                   ' Set PORTB value to zero
  TRISB = 0                  ' Configure PORTB as output
  TRISD = 0                  ' Configure PORTB as output
  LATD = 0                   ' Set PORTB value to zero

  EEPROM_24C02_Init()                      ' performs I2C initialization
  b = 0x00
  for i = 0x00 to 0x7F
    EEPROM_24C02_WrSingle(i,b)
    Inc(b)
    Delay_ms(5)
  next i

  for i = 0x00 to 0x7F
    LATD = i
    LATB = EEPROM_24C02_RdSingle(i)
    Delay_ms(100)
  next i
end.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: I2C fails when using PLL 80Mhz

#2 Post by janko.kaljevic » 07 Oct 2011 08:54

Hello,

From this point of view I really can not see what is wrong.
But I have tested I2C_Simple example and it works on 80MHz fine.

Here is the the project.

Best regards.
Attachments
I2C Simple.rar
(3.71 KiB) Downloaded 286 times

galeforce9
Posts: 6
Joined: 25 Sep 2011 09:10

Re: I2C fails when using PLL 80Mhz

#3 Post by galeforce9 » 08 Oct 2011 14:39

Hello,

Thank you for your reply. Unfortunatley the attached .rar file was for MikroC not MikroBasic.

I have done some further testing and have attached 4 projects, all the same demo for EEprom just with different config settings.

project 1
This is the standard sample compiles fine with a PIC32MX460 running at 8Mhz
project 2
As above but with PLL enabled and osc set to 80Mhz. Compiles fine, code runs but EEprom fails read and write
project 3
As project 1 but changed to a PIC32MX795 also running 8Mhz config. All runs fine.
project 4
As above but with PLL enabled and osc set to 80Mhz. Compiles and runs perfectly.

The only issue is with the PIC32MX460 running at 80Mhz. You can see the error immediatley just by looking at the Port LED's. When working both clock and data are mainly lit but when not working RA2 is mainly off!

Could this be a silicon error? The main project is over 100K in length and use's dual uarts, pwm and three timers all under interupt control and everything works fine at 80Mhz. It is only the I2C which fails.

Please advice your findings and if you can get project 2 to run as provided.

Thank you

Ian
Attachments
I2C Simple 3-4.zip
(211.61 KiB) Downloaded 235 times
I2C Simple 1-2.zip
(108.35 KiB) Downloaded 243 times

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: I2C fails when using PLL 80Mhz

#4 Post by janko.kaljevic » 10 Oct 2011 15:48

Hello,

Thanks for sending these examples we will test them and reply to you with results as soon as possible.

Best regards.

galeforce9
Posts: 6
Joined: 25 Sep 2011 09:10

Re: I2C fails when using PLL 80Mhz

#5 Post by galeforce9 » 20 Oct 2011 23:50

Hello,

Do you have any news yet.

Ian

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: I2C fails when using PLL 80Mhz

#6 Post by janko.kaljevic » 31 Oct 2011 11:37

Hello,

I believe that we have continued our correspondence on support desk.

Best regards.

digitalis
Posts: 25
Joined: 09 Jul 2011 22:12
Location: Belgium

Re: I2C fails when using PLL 80Mhz

#7 Post by digitalis » 07 Nov 2011 10:50

using the mmb for pic 32
and using I2C2 to run a TDA8444 (5V DIL)
using pull up resisters to 5V on RA2 and RA3 (pins 58 and 59 on uP or 13 and 14 on MMB)
(RA2 and RA3 are 5V tolerant)
RA3 pull's up to 5V but RA2 stays on a 0V level
so system does not work

any idea to solve the problem?
digitalis

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: I2C fails when using PLL 80Mhz

#8 Post by janko.kaljevic » 08 Nov 2011 12:07

digitalis wrote:using the mmb for pic 32
and using I2C2 to run a TDA8444 (5V DIL)
using pull up resisters to 5V on RA2 and RA3 (pins 58 and 59 on uP or 13 and 14 on MMB)
(RA2 and RA3 are 5V tolerant)
RA3 pull's up to 5V but RA2 stays on a 0V level
so system does not work

any idea to solve the problem?
digitalis
I believe that we have the same correspondence here:
http://www.mikroe.com/forum/viewtopic.p ... 03#p173303

Best regards.

digitalis
Posts: 25
Joined: 09 Jul 2011 22:12
Location: Belgium

Re: I2C fails when using PLL 80Mhz

#9 Post by digitalis » 25 Nov 2011 21:23

yes
it is about the same problem
it is about SDA that holds the bus
see that post please
73
digitalis

ashraf.emam
Posts: 27
Joined: 06 Jan 2012 20:08

Re: I2C fails when using PLL 80Mhz

#10 Post by ashraf.emam » 10 Jan 2012 09:11

Hi guys,
I had a similar problem, and I inserted a delay of 8-10usec between each I2C commands.
The problem comes from the processor high speed, check the collision bit.
I did not work you can write your own code.
Here is mine in mikroC.

Code: Select all

//==============================================================================
// void I2C_WriteByte(unsigned char, unsigned char, unsigned char)
// unsigned char I2C_ReadByte(unsigned char, unsigned char)
// unsigned int I2C_ReadWord(unsigned char, unsigned char)
// void I2C_WriteCmd(unsigned char, unsigned char)
//void I2C_WriteWord(unsigned char, unsigned char, unsigned char, unsigned char)
//==============================================================================
bit  Ack;
sbit MySCL   at RD7_bit;
sbit MySDA   at RD6_bit;
sbit Dir_SCL at TRISD7_bit;
sbit Dir_SDA at TRISD6_bit;
//------------------------------------------------------------------------------
void MyStart(){
  Dir_SCL = 0; //Clock  output
  Dir_SDA = 0; //SDA as output
  MySCL = 1;
  MYSDA = 1;
  Delay_us(25);
  MySDA = 0;
  Delay_us(15);
  MySCL = 0;
  Delay_us(10);
  return;
}
//------------------------------------------------------------------------------
void MyStop()
{
 Dir_SCL = 0;
 MySCL = 0;
 Delay_us(15);
 MySDA = 0;
 Dir_SDA = 0;
 MySCL = 1;
 Delay_us(5);
 MySDA = 0;
 Delay_us(15);
 MySDA = 1;
 MySCL=1;
 return;
}
//------------------------------------------------------------------------------
void MyRepeat(){
  Dir_SDA = 0;
  Dir_SCL = 0;
  MySDA = 0;
  MYSCL = 0;
  Delay_us(15);
  MySDA = 1;
  Delay_us(15);
  MySCL = 1;
  Delay_us(15);
  MySDA = 0;
  Delay_us(15);
  MySCL = 0;
  Delay_us(20);
  return;
}
//------------------------------------------------------------------------------
unsigned MyRite(unsigned char i){
 int j;

 for (j=0; j<8;j++)
 {
   if((i & 0x80)) MySDA = 1;
   else MySDA = 0;
   i = i << 1;
   Delay_us(3);
   MySCL = 1;
   Delay_us(5);
   MySCL = 0;
  }               //Acknowledge Cycle
  Dir_SDA = 1;    //SDA input
  Delay_us(4);
  MySCL = 1;
  Delay_us(5);
  Ack = MySDA;
  MySCL = 0;
  Delay_us(13);
  Dir_SDA = 0;    //SDA output
  MySDA = 0;         //SDA =0
  Delay_us(10);
  if (Ack) return (1);
  else return (0);
}
//------------------------------------------------------------------------------
unsigned char MyRead(unsigned char ack){
unsigned char i =0,j;

  Delay_us(20);
  Dir_SDA = 1;
  Dir_SCL = 0;
  for (j = 0; j < 8; j++){
    MySCL = 1;
    Delay_us(5);
    i= i << 1;
    i += MySDA;
    MySCL = 0;
    Delay_us(5);
  }
//Acknowledge Cycle
  Dir_SDA = 0;         // output
  Dir_SCL = 0;
  MySCL = 0;
  if (ack == 1) MySDA = 1;
  else  MySDA = 0;
  Delay_us(2);
  MySCL = 1;
  Delay_us(5);
  MySCL = 0;
  Delay_us(5);
  MySDA = 0;
  Delay_us(10);
  return i;
}
//------------------------------------------------------------------------------
void I2C_WriteCmd(unsigned char Adrs, unsigned char Cmd){
   MyStart();                        // issue I2C start signal
   MyRite(Adrs);                      // send byte via I2C  (device address + W)
   MyRite(Cmd);                     // Command
   MyStop();
  return;
}
//------------------------------------------------------------------------------
void I2C_WriteByte(unsigned char Adrs, unsigned char Cmd, unsigned char value){
   MyStart();                        // issue I2C start signal
   MyRite(Adrs);                      // send byte via I2C  (device address + W)
   MyRite(Cmd);                     // Command
   MyRite(value);
   MyStop();
  return;
}
//------------------------------------------------------------------------------
void I2C_WriteWord(unsigned char Adrs, unsigned char Cmd, unsigned char value1, unsigned char value2){
   MyStart();                       // issue I2C start signal
   MyRite(Adrs);                    // send byte via I2C  (device address + W)
   MyRite(Cmd);                     // Send Subaddress or Register
   MyRite(value1);                  // Send Value1 (h)
   //Delay_us(8);
   MyRite(value2);                  // Send Value2 (l)
   MyStop();
  return;
}
//------------------------------------------------------------------------------
unsigned int I2C_ReadWord(unsigned char Adrs, unsigned char Cmd){
  unsigned char h,l;
   MyStart();                      // issue I2C start signal
   MyRite(Adrs);                     // send byte via I2C  (device address + W)
   MyRite(Cmd);                     // send byte (address of EEPROM location)
   MyRepeat();             // issue I2C signal repeated start
   MyRite(Adrs+1);
   h = MyRead(0u);
   l = MyRead(1u);
   MyStop();
   return(h*256+l);
}
//------------------------------------------------------------------------------
unsigned char I2C_ReadByte(unsigned char Adrs, unsigned char Cmd){
  unsigned char b;
   MyStart();                      // issue I2C start signal
   MyRite(Adrs);                     // send byte via I2C  (device address + W)
   MyRite(Cmd);                     // send byte (address of EEPROM location)
   MyRepeat();             // issue I2C signal repeated start
   MyRite(Adrs+1);
   b = MyRead(1u);
   MyStop();
   return(b);
}
Good Luck

especialista
Posts: 10
Joined: 24 Aug 2010 14:41
Location: Brazil
Contact:

Re: I2C fails when using PLL 80Mhz

#11 Post by especialista » 22 Feb 2015 16:27

Try grounding each I2C line via 100pF ceramic capacitor.

Trust me: It will save you a lot of hair!
Especialista
Proud User of MIkroC Pro, PLCPIC16 v6, Proteus & PicKit 2

Post Reply

Return to “mikroBasic PRO for PIC32 General”