Pic32mx150F128D I2C not working.

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Pic32mx150F128D I2C not working.

#1 Post by OldSpring » 17 Jan 2015 21:09

Hi, MB team:

I'm working for a small project. It uses Pic32mx150F128d, compiler is MB pic32 3.3.3.

GLCD function works fine, but it will stop to work when I add I2C2 init.

Below is simple test code:

Code: Select all

program Glcd_Test

' Glcd module connections
dim GLCD_D7 as sbit at LATB5_bit
    GLCD_D6 as sbit at LATB6_bit
    GLCD_D5 as sbit at LATB7_bit
    GLCD_D4 as sbit at LATB8_bit
    GLCD_D3 as sbit at LATB9_bit
    GLCD_D2 as sbit at LATB10_bit
    GLCD_D1 as sbit at LATB11_bit
    GLCD_D0 as sbit at LATB12_bit
    GLCD_D7_Direction as sbit at TRISB5_bit
    GLCD_D6_Direction as sbit at TRISB6_bit
    GLCD_D5_Direction as sbit at TRISB7_bit
    GLCD_D4_Direction as sbit at TRISB8_bit
    GLCD_D3_Direction as sbit at TRISB9_bit
    GLCD_D2_Direction as sbit at TRISB10_bit
    GLCD_D1_Direction as sbit at TRISB11_bit
    GLCD_D0_Direction as sbit at TRISB12_bit

dim GLCD_CS1 as sbit at LATC1_bit
    GLCD_CS2 as sbit at LATC2_bit
    GLCD_RS  as sbit at LATA9_bit
    GLCD_RW  as sbit at LATB14_bit
    GLCD_EN  as sbit at LATC3_bit
    GLCD_RST as sbit at LATC5_bit

dim GLCD_CS1_Direction as sbit at TRISC1_bit
    GLCD_CS2_Direction as sbit at TRISC2_bit
    GLCD_RS_Direction  as sbit at TRISA9_bit
    GLCD_RW_Direction  as sbit at TRISB14_bit
    GLCD_EN_Direction  as sbit at TRISC3_bit
    GLCD_RST_Direction as sbit at TRISC5_bit
' End Glcd module connections

main:
  Glcd_Init()        ' Initialize Glcd
  'I2C2_Init(100000)
  while true
      Glcd_Fill(0x00)
      delay_ms(1000)
      Glcd_Fill(0xff)
      delay_ms(1000)
  wend
end.
Is it MCU problem? or your Compiler problem? or my test code problem?

Could you help me to solve this problem? Thank you.

Best regards,

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: Pic32mx150F128D I2C not working.

#2 Post by darko.minic » 19 Jan 2015 10:41

Hello,

As I can see from datasheet for PIC32MX150F128D I2C lines is attached on RB2(SDA) and RB3(SCL).
If you refer help for our compiler you will see that RB2 and RB3 pins are used by GLCD:

Code: Select all

GLCD_D3 as sbit at RB3_bit
GLCD_D2 as sbit at RB2_bit
However you can use I2C1_Init, and there should be no problems.

Regards,
Darko

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Pic32mx150F128D I2C not working.

#3 Post by OldSpring » 20 Jan 2015 00:30

Hi, Darko;

Thank you very much for you fast reply.

We use our own project board. So, we didn't use RB3, RB2 for GLCD. We use these pins for I2C2.

GLCD Library works fine, if we put GLCD and I2C2 toghter. It will refuse to work for us. We read PIC32MX150F128D datasheet and errata.

Now we just want to make sure: Is it MCU problem? or your Compiler problem? or my test code problem?

Also, we tested this code, it isn't work too.

Code: Select all

program Glcd_Test

' Glcd module connections
dim GLCD_D7 as sbit at RB5_bit
    GLCD_D6 as sbit at RB6_bit
    GLCD_D5 as sbit at RB7_bit
    GLCD_D4 as sbit at RB8_bit
    GLCD_D3 as sbit at RB9_bit
    GLCD_D2 as sbit at RB10_bit
    GLCD_D1 as sbit at RB11_bit
    GLCD_D0 as sbit at RB12_bit
    GLCD_D7_Direction as sbit at TRISB5_bit
    GLCD_D6_Direction as sbit at TRISB6_bit
    GLCD_D5_Direction as sbit at TRISB7_bit
    GLCD_D4_Direction as sbit at TRISB8_bit
    GLCD_D3_Direction as sbit at TRISB9_bit
    GLCD_D2_Direction as sbit at TRISB10_bit
    GLCD_D1_Direction as sbit at TRISB11_bit
    GLCD_D0_Direction as sbit at TRISB12_bit

dim GLCD_CS1 as sbit at LATC1_bit
    GLCD_CS2 as sbit at LATC2_bit
    GLCD_RS  as sbit at LATA9_bit
    GLCD_RW  as sbit at LATB14_bit
    GLCD_EN  as sbit at LATC3_bit
    GLCD_RST as sbit at LATC5_bit

dim GLCD_CS1_Direction as sbit at TRISC1_bit
    GLCD_CS2_Direction as sbit at TRISC2_bit
    GLCD_RS_Direction  as sbit at TRISA9_bit
    GLCD_RW_Direction  as sbit at TRISB14_bit
    GLCD_EN_Direction  as sbit at TRISC3_bit
    GLCD_RST_Direction as sbit at TRISC5_bit
' End Glcd module connections

main:
  Glcd_Init()        ' Initialize Glcd
  'I2C2_Init(100000)
  while true
      Glcd_Fill(0x00)
      delay_ms(1000)
      Glcd_Fill(0xff)
      delay_ms(1000)
  wend
end.
Best regards,

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: Pic32mx150F128D I2C not working.

#4 Post by darko.minic » 20 Jan 2015 10:39

Hello,

Unfortunately I don't have same hardware, so I am unable to test your code by myself.

Did you try to configure I2C2 manually (without library) and see if the problem remains the same?

Best regards,

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Pic32mx150F128D I2C not working.

#5 Post by OldSpring » 20 Jan 2015 14:10

Hi, Darko;

Thanks for fast reply.

I will try to config it manually. I will let you know if it works or not. Thank you.

Best regards.

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Pic32mx150F128D I2C not working.

#6 Post by OldSpring » 22 Jan 2015 01:11

Hi, Darko;

We just use scope to check the Pic32MX150F128D output pins for GLCD.

No I2C2 init, These pins work fine. After adding I2C2_Init(100000), Control pins are ok, but data pins no output.

We think may your compiler has problem? below is our simple test code, it is very easy to check on your board.

If you find the problem, please let us know ASAP. Thanks.

Best regards,

Code: Select all

program Glcd_Test

' Glcd module connections
dim GLCD_D7 as sbit at RB5_bit
    GLCD_D6 as sbit at RB6_bit
    GLCD_D5 as sbit at RB7_bit
    GLCD_D4 as sbit at RB8_bit
    GLCD_D3 as sbit at RB9_bit
    GLCD_D2 as sbit at RB10_bit
    GLCD_D1 as sbit at RB11_bit
    GLCD_D0 as sbit at RB12_bit
    GLCD_D7_Direction as sbit at TRISB5_bit
    GLCD_D6_Direction as sbit at TRISB6_bit
    GLCD_D5_Direction as sbit at TRISB7_bit
    GLCD_D4_Direction as sbit at TRISB8_bit
    GLCD_D3_Direction as sbit at TRISB9_bit
    GLCD_D2_Direction as sbit at TRISB10_bit
    GLCD_D1_Direction as sbit at TRISB11_bit
    GLCD_D0_Direction as sbit at TRISB12_bit

dim GLCD_CS1 as sbit at LATC1_bit
    GLCD_CS2 as sbit at LATC2_bit
    GLCD_RS  as sbit at LATA9_bit
    GLCD_RW  as sbit at LATB14_bit
    GLCD_EN  as sbit at LATC3_bit
    GLCD_RST as sbit at LATC5_bit

dim GLCD_CS1_Direction as sbit at TRISC1_bit
    GLCD_CS2_Direction as sbit at TRISC2_bit
    GLCD_RS_Direction  as sbit at TRISA9_bit
    GLCD_RW_Direction  as sbit at TRISB14_bit
    GLCD_EN_Direction  as sbit at TRISC3_bit
    GLCD_RST_Direction as sbit at TRISC5_bit
' End Glcd module connections

sub procedure I2C2_Config()
  ON__I2C2CON_bit = 1
  'ON__I2C1CON_bit = 0
  SIDL_I2C2CON_bit = 0
  SCLREL_I2C2CON_bit = 0
  STRICT_I2C2CON_bit = 0
  A10M_I2C2CON_bit = 0
  DISSLW_I2C2CON_bit = 0
  SMEN_I2C2CON_bit = 0
  GCEN_I2C2CON_bit = 0
  STREN_I2C2CON_bit = 0
  ACKDT_I2C2CON_bit = 0
  ACKEN_I2C2CON_bit = 0
  RCEN_I2C2CON_bit = 0
  PEN_I2C2CON_bit = 0
  RSEN_I2C2CON_bit = 0
  SEN_I2C2CON_bit = 0
end sub

main:
    'Glcd_Init()        ' Initialize Glcd
    'I2C2_Config()
    I2C2_Init(100000)
    GLCD_D7_Direction = 0
    GLCD_D6_Direction = 0
    GLCD_D5_Direction = 0
    GLCD_D4_Direction = 0
    GLCD_D3_Direction = 0
    GLCD_D2_Direction = 0
    GLCD_D1_Direction = 0
    GLCD_D0_Direction = 0

    GLCD_CS1_Direction = 0
    GLCD_CS2_Direction = 0
    GLCD_RS_Direction  = 0
    GLCD_RW_Direction  = 0
    GLCD_EN_Direction  = 0
    GLCD_RST_Direction = 0

while true
      GLCD_D7 = not GLCD_D7
      GLCD_D6 = not GLCD_D7
      GLCD_D5 = not GLCD_D7
      GLCD_D4 = not GLCD_D7
      GLCD_D3 = not GLCD_D7
      GLCD_D2 = not GLCD_D7
      GLCD_D1 = not GLCD_D7
      GLCD_D0 = not GLCD_D7
      
      GLCD_CS1 = not GLCD_CS1
      GLCD_CS2 = not GLCD_CS2
      GLCD_RS  = not GLCD_RS
      GLCD_RW  = not GLCD_RW
      GLCD_EN  = not GLCD_EN
      GLCD_RST = not GLCD_RST
      'delay_ms(100)
wend
end.

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: Pic32mx150F128D I2C not working.

#7 Post by darko.minic » 23 Jan 2015 13:50

Hello,

If I understand you correctly, you tried your code with your I2C2 initialization routine, and then everything is working as expected?
Also when you try our I2C2 initialization GLCD not working?

Regards,
Darko

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Pic32mx150F128D I2C not working.

#8 Post by OldSpring » 23 Jan 2015 16:21

Hi, Darko;

When we use our I2C2_Config() or your I2C2_Init(100000). the data pins not working.

Also, If we only set ON__I2C2CON_bit = 1, the data pins will be not working (no output) too.

What's the problem?

Best regards,

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: Pic32mx150F128D I2C not working.

#9 Post by darko.minic » 26 Jan 2015 11:11

Hello,

It seems that there is some problem with I2C2 module and GLCD data pins,
but from your description of problem it's not related to I2C2 library,
because problem remains the same even if you try to use your own I2C2 initialization routine.
Therefore problem could be related with MCU, or your custom hardware.

Can you attach schematic of your hardware, maybe we missing something?

Regards,
Darko

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Pic32mx150F128D I2C not working.

#10 Post by OldSpring » 01 Feb 2015 15:08

Hi, Darko;

The schematic of my hardware attached, please check it. Thanks.

Best regards,
Attachments
GLCD.jpg
GLCD.jpg (76.51 KiB) Viewed 6493 times

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: Pic32mx150F128D I2C not working.

#11 Post by darko.minic » 02 Feb 2015 14:56

Hello,

As I mentioned before, unfortunately I don't have same hardware, so I am unable to test your code by myself.

I can recommend you to try to make some simple connections on breadboard with PIC32MX150F128D attached to your GLCD, and then try to
run your GLCD with I2C2 initialization routine in your code.
This can help you to isolate the problem, and see whether the problem is in your hardware.

Regards,
Darko

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Pic32mx150F128D I2C not working.

#12 Post by OldSpring » 03 Feb 2015 01:54

Hi, Darko:

I already told you, You don't need same hardware to test my software. you only use LED to test those pins.

1) First, you can use your board to test Leds use those pins (they should work)
2) After init I2C2, those pins will not work.

It's simple test, you will know MCU or you software problem!

Best regards,

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: Pic32mx150F128D I2C not working.

#13 Post by darko.minic » 03 Feb 2015 12:00

Hello,

I tried your code with the exact same conditions.
Everything is working as expected with and without I2C2 routine.
GLCD clear and fill in interval of 1 second.

So there is no problem with software or MCU.

I can recommend you to double check your hardware (schematic and layout) and see
why I2C2 lines affects on GLCD lines and try to isolate the problem.
Also as I mentioned in post before you can try to make some simple connections on breadboard with PIC32MX150F128D attached to your GLCD,
and then try to run your GLCD with I2C2 initialization routine in your code.

Your code is OK, and if everything is OK with the Hardware, it should work.

Regards,
Darko

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Pic32mx150F128D I2C not working.

#14 Post by OldSpring » 07 Feb 2015 18:26

Hello, Darko:

We tested Pic32mx150F128D again.

RB5 and RB6 output will be very low after I2C2 init.

We checked Microchip pic32mx150F128D errate, didn't find any information about I2C2.

Today, we use your newest version 3.5.0 to test it, we got same result. below show our test code and test "hardware"
(we use internal Oscillator. Setting: Fast RC Osc with PLL, 40MHz)

Code: Select all

program Pic32mx150F128D

dim LED_B5 as sbit at LATB5_bit
    LED_B6 as sbit at LATB6_bit
    LED_B5_Direction as sbit at TRISB5_bit
    LED_B6_Direction as sbit at TRISB6_bit

main:
    LED_B5 = 0
    LED_B6 = 0
    LED_B5_Direction = 0
    LED_B6_Direction = 0
'I2C2_Init(100000)
'I2C2CON = 0x8000
 ON__I2C2CON_bit = 1
    while true
          LED_B5 = not LED_B5
          LED_B6 = not LED_B6
          Delay_ms(100)
    wend
end.
We just want you to make sure, this problem is normal, or MCU problem, or our test "hardware" problem.
If you can give us a clear answer? MCU problem or Compiler problem?

If we can't solve this problem, we will think to use soft I2C.

Thanks.
Attachments
Pic32mx150f128D_test.jpg
Pic32mx150f128D_test.jpg (20.35 KiB) Viewed 6380 times

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: Pic32mx150F128D I2C not working.

#15 Post by darko.minic » 09 Feb 2015 15:17

Hello,

As I mentioned in post before your code is tested with the exact same conditions.
Everything worked as expected, therefore compiler is OK.
However you tried the simplest connection with MCU, and problem remains the same,
so there could be problem with MCU.

This problem is very unusual and unfortunately I am unable to reproduce it with the same condition you have.

Regards,
Darko

Post Reply

Return to “mikroBasic PRO for PIC32 General”