• AVR Freaks

Hot!PIC32MX120-032B cannot get I2C1 or I2C2 to work

Author
mdj
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2009/11/23 08:30:27
  • Location: 0
  • Status: offline
2012/10/05 07:15:44 (permalink)
0

PIC32MX120-032B cannot get I2C1 or I2C2 to work

The I2C pins of the the PIC32MX1 device stay high no matter what I try. Software that works for a PIC32MX340 will not work on this device. Does anyone have working I2C code for the PIC32MX1 series. My non-working code is below. As soon as the SEN bit is set the I2C1Stat reg shows BCL - Master bus collision
 
I2C1BRG = 38;//Initialise
I2C1CON = 0x8000;//Switch on the I2C
I2C1CONbits.SEN = 1;//Set start bit ***this never happens
while(I2C1CONbits.SEN);//Wait for it to be established
MasterWriteI2C1(I2CAddress); ***etc***
 
Any suggestions?
#1

11 Replies Related Threads

    Electron2K4
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2012/10/05 09:13:40
    • Location: 0
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/06 06:39:36 (permalink)
    0
     
    Make sure they are not analogue (by default they are).
     
    They stay high because of pull-up resistors.
     
    #2
    vl
    Super Member
    • Total Posts : 222
    • Reward points : 0
    • Joined: 2012/05/15 22:29:27
    • Location: 0
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/06 07:31:02 (permalink)
    0
    Also, disable JTAG:
    DDPCONbits.JTAGEN = 0;

    You can/should leave the corresponding TRIS bits as 1 (input).
    #3
    Howard Long
    Super Member
    • Total Posts : 727
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/06 11:01:47 (permalink)
    0
    Attached is my I2C code.
     
    Howard
    #4
    Howard Long
    Super Member
    • Total Posts : 727
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/07 02:19:17 (permalink)
    0
    The forum didn't like .h files as attachments, so here it is, note the peripheral library bug mentioned in the header file, and also the warning in the .c file about disabling the slew rate control (which also affects I2C2, although that isn't currently mentioned in the silicon errata).
     
    Cheers, Howard
     
    #ifdef _MYI2C
     #define ASSIGN(x) =x
     #define EXTERN
    #else
     #define ASSIGN(x)
     #define EXTERN extern
    #endif
    // **** Bug in libraries for I2C1 only, IEC1CLR = _IEC0_I2C1BIE_MASK should be _IEC1_I2C1BIE_MASK
    #undef mI2C1BIntEnable
    #define mI2C1BIntEnable(enable)             (IEC1CLR = _IEC1_I2C1BIE_MASK, IEC1SET = ((enable) << _IEC1_I2C1BIE_POSITION))
    EXTERN void MyI2C1Init(void);
    EXTERN UINT8 MyI2C1ReceiveByte(UINT8 u8I2CAddr,UINT8 u8RegAddr);
    EXTERN void MyI2C1SendByte(UINT8 u8I2CAddr,UINT8 u8RegAddr,UINT8 u8Data);
    #undef ASSIGN
    #undef EXTERN 
    
    #5
    mdj
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2009/11/23 08:30:27
    • Location: 0
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/08 03:57:02 (permalink)
    0
    Thanks Howard
    Used your code and still not a twitch. Have you used it on an MX1?
    As soon as it processes StartI2C I get an 0x408 on I2C1STAT which means a Master Bus Collision has been detected and yet I have no devices on the pins, just pullups!
    Marc
    #6
    fallen
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2010/07/21 04:59:45
    • Location: South Africa
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/08 07:30:18 (permalink)
    0
    Hi
     
    Have u setup the PPS (Peripheral Pin select)
     
    Cheers Garth
     

    #7
    rpg7
    Super Member
    • Total Posts : 1386
    • Reward points : 0
    • Joined: 2003/11/07 12:47:35
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/08 07:38:30 (permalink)
    0
    fallen Have u setup the PPS (Peripheral Pin select)

    AFAICS PPS not used on I2C for this chip.
     
    However, OP is using library functions (mixed with some direct register access) so I can't help with that as I only do I2C with direct register access.
     
    Looking at it again, the JTAG is on I2C1 and I2C2 is on port B witch defaults IIRC to analog. So JTAG needs to be turned off in code and so does analog function of port B

    #8
    mdj
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2009/11/23 08:30:27
    • Location: 0
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/08 07:44:55 (permalink)
    0
    This is what I start off with so hopefully both those bases are covered:
    SYSTEMConfigPerformance(72000000L);
    DDPCONbits.JTAGEN = 0;
    ANSELA = 0;//All digital output
    ANSELB = 0;//All digital output
    #9
    rpg7
    Super Member
    • Total Posts : 1386
    • Reward points : 0
    • Joined: 2003/11/07 12:47:35
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/08 08:27:08 (permalink)
    0
    mdj SYSTEMConfigPerformance(72000000L);

    What actual clock are you running? Officially it is a 40Mhz part.
    #10
    Electron2K4
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2012/10/05 09:13:40
    • Location: 0
    • Status: offline
    Re:PIC32MX120-032B cannot get I2C1 or I2C2 to work 2012/10/08 09:15:29 (permalink)
    0
     
    yes max speed for this part is 40 MHz, although I overclocked one to 64 MHz and another one to 80 MHz. :D (not for production! only for test/fun)

     
    post edited by Electron2K4 - 2012/10/08 09:19:00
    #11
    Hemjal
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2019/09/12 23:37:27
    • Location: 0
    • Status: offline
    Re: PIC32MX120-032B cannot get I2C1 or I2C2 to work 2019/11/22 01:44:08 (permalink)
    0
    fin all of the solutions here
     
    https://www.youtube.com/watch?v=yM9OpRPMEAE

    Regards,
    Hemjal Md Abu
    FI
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5