Hot!I2C not working, MCC issue?

Page: 12 > Showing page 1 of 2
Author
Krixen
Junior Member
  • Total Posts : 116
  • Reward points : 0
  • Joined: 2015/03/30 11:18:29
  • Location: 0
  • Status: offline
2017/11/03 10:51:14 (permalink)
0

I2C not working, MCC issue?

Trying to write an I2C driver that I had working in another file and I just ported over the functions. The back-end code for the PIC12LF1840 was created using MCC. I am trying to set-up coms with a MMA8452q accelerometer. I suspect the pins are off but I am not completely sure. This is what MCC generated for pin_manager.c. (note I am using RC1 as SCL and RC2 and SDA)
 
 
LATA = 0x06;
TRISA = 0x3F;
ANSELA = 0x10;
WPUA = 0x00;
OPTION_REGbits.nWPUEN = 0x01;
APFCON = 0x00;
 
Are these correct?
 
edit: If I do an I2C transmission, my EUSART_Write no longer works, and if I don't have any then EUSART_Write will work. Here is my implemented code, only doing one write for now:
 
 
MMA_Address = 0b0011100; //7-bit address with SA0 pin to 0
uint8_t writeBuffer[2];
uint8_t status;

writeBuffer[0] = MMA_Ctrl_Reg_1;
writeBuffer[1] = 0b00000000; //low-noise, fast-read, fastest data rate
I2C_MasterWrite(writeBuffer, 2, MMA_Address, &status);
while(status != I2C_MESSAGE_COMPLETE);
post edited by Krixen - 2017/11/03 11:13:48
#1

25 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/03 15:31:02 (permalink)
    4 (1)
    The most obvious one:
    If you're working on RC*, we would like to see ANSELC, TRISC etc.
    The *A registers don't help.

    Most times the bug is in front of the keyboard.
    #2
    Krixen
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2015/03/30 11:18:29
    • Location: 0
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 05:55:46 (permalink)
    0
    Doh! I was looking at the previous code I had written for another PIC that was used to talk to this same sensor.
    The pin_manager.c for the CORRECT program is:
     
    LATA = 0x06;
    TRISA = 0x3F;
    ANSELA = 0x10;
    WPUA = 0x00;
    OPTION_REGbits.nWPUEN = 0x01;
    APFCON = 0x00;
    #3
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 06:05:36 (permalink)
    0
    Still *A ! Where is the *C registers setup?

    Most times the bug is in front of the keyboard.
    #4
    Krixen
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2015/03/30 11:18:29
    • Location: 0
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 06:08:32 (permalink)
    3 (1)
    Oh man I am having a great Monday morning. The registers are right, it is the pins that I was wrong about. There is no C registers on the PIC12LF1840.
     
    I am using RA1 for SCLK and RA2 for SDA. 
    #5
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 06:29:02 (permalink)
    4 (1)
    If this is supposed to be an I2C slave, TRISA is ok.
    For a master, TRISA.1 and TRISA.2 should be cleared initially. (TRISA.2 is to be dynamically reconfigured due ti its bidirectional nature.)
    Weak pull-ups may not be enough - depending on I2C speed. Anyway - provided I interpret correctly - none is chosen (WPUA = 0).

    Most times the bug is in front of the keyboard.
    #6
    Krixen
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2015/03/30 11:18:29
    • Location: 0
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 06:39:46 (permalink)
    0
    I have 10kohm pull-up resistors on clock and data. So that should not be a problem. 
     
    It seems like the MMA8452q just never sends info back or something. If I just do a simple EUSART_Write() in my while loop I can read it on a terminal but when I do any sort of I2C write, it gets held up there.
     
    Not sure what is going wrong, these exact drivers have worked for the PIC16LF18325 I had used. 
     
    It gets stuck here in my code:
     
    while(status != I2C_MESSAGE_COMPLETE);
     
    Meaning that the  I2C message is never completing 
     
    edit: Another note I found is that I never see the clock ever go high, even on the first transmission. I am monitoring the clock line with a scope probe and yet nothing seems to happen. I put a 5 second delay right before my first I2C write and monitored the pin and nothing happens. 
     
    Any idea what is going on?
     
     
    post edited by Krixen - 2017/11/06 06:57:03
    #7
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 07:00:03 (permalink)
    0
    We had a similar thread recently - different PIC, but MCC and I2C. Suggest to go through that one - paying special attention to the "address" and "which routines to use" contributions.
    http://www.microchip.com/forums/m1020538.aspx
    Should help to get around your issue.
    Othwise: come back here.

    Most times the bug is in front of the keyboard.
    #8
    Krixen
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2015/03/30 11:18:29
    • Location: 0
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 07:33:18 (permalink)
    0
    Hello, Unfortunately that thread did not have the answer for me. I am using MCC 2.7 which and I have not modified the I2C write code.
     
    What I am seeing is that my SCLK line never goes high or low (even on first transmission) and my SDA line is always about 1/2 VCC. I think it has something to do with Pin assignment but can't figure out what is wrong. 
     
    edit: The reason that nothing was clocking was because I had global interrupts enabled and something was causing an interrupt. However, when I disable interupts, I still am not seeing the SCLK. I have switched to MCC v3.15
     
    SCLK is always high and SDA is somewhere near 1/2 VCC 
    post edited by Krixen - 2017/11/06 07:54:17
    #9
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 08:42:02 (permalink)
    0
    What about using the debugger to step through?  Could it be there is no attempt to TX at all?
    (I hope one of the colleagues starts chiming in. 😎 )

    Most times the bug is in front of the keyboard.
    #10
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 08:46:02 (permalink)
    0
    Addon: try TRISA = 0x39; as the init value (I already mentioned TRISA).

    Most times the bug is in front of the keyboard.
    #11
    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 08:53:37 (permalink)
    0
    0b00111001 Smile then

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #12
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/06 09:09:29 (permalink)
    3 (1)
    Hi Dario,
    "take that" 😏 - I'll be offline for quite some time now.

    Most times the bug is in front of the keyboard.
    #13
    Krixen
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2015/03/30 11:18:29
    • Location: 0
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/09 07:52:31 (permalink)
    0
    Unfortunately that did not work either. I2C is not even making an attempt, which is really puzzling. If I monitor the clock pin and power it, the clock line just stays at 0 the entire time. 
     
    Going to step through and see what happens.
     
    edit: I see that the status that comes back from I2C is always I2C_MESSAGE_FAIL, which only happens when this executes:
     
    i2c_object.trStatus.s.full != true 
    post edited by Krixen - 2017/11/09 08:01:56
    #14
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/09 12:21:50 (permalink)
    0
    If the buffer is full, it cannot get rid of the byte(s).
    DO YOU REALLY HAVE PULLUPS on the right lines ??? and NO SHORT ???
    Or are these pins shot now ?
    One thing worth trying: reset the chip!
    While held in reset, these lines MUST be high if everything is ok. If not: see my line #2.

    Most times the bug is in front of the keyboard.
    #15
    Krixen
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2015/03/30 11:18:29
    • Location: 0
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/09 12:27:32 (permalink)
    0
    I actually just took off the pull-up resistors. Now my SDA is always at GND and my SCLK is idling high. I went back to default values for my registers.
     
    TRISA = 0x3F;
    ANSELA = 0x10;
    LATA = 0x00;
     
    If I enable global and peripheral interrupts my code gets hung up in I2C_MASTER_IDLE. That is where I am now, I never see the clock or data lines move at all. I am at a loss on this one, can't get I2C to do ANYTHING
     
    Other ideas: I am using HF 16 MHz on the internal clock, and use FOSC for the system clock option and INTOSC for oscillator select. I also have PLL enabled. No WDT.
    post edited by Krixen - 2017/11/09 12:29:21
    #16
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/09 12:38:29 (permalink)
    0
    What about re-reading the recommendations top-down? Following them.
    Or should WE repeat that ?
     
    What outcome do you expect without the pull-ups ?
    And why is the darn SCLK high without pull-up? and with TRISA = 0x3F?
     
    You may continue to fiddle aroudn. You may even start reading the documentation.
    Be we are not happy when we have to tell things for the ump-th time ...

    Most times the bug is in front of the keyboard.
    #17
    Krixen
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2015/03/30 11:18:29
    • Location: 0
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/13 08:31:24 (permalink)
    0
    Turns out that if I power it with a power supply and not the pickit3, it works. I kept the pull-up resistors on. If I used the pickit3 without the pull-up resistors, it still doesn't work
    #18
    du00000001
    Just Some Member
    • Total Posts : 1345
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/13 09:14:55 (permalink)
    3 (1)
    The pull-up resistors on I2C?
     
    Did nobody until now tell you that the pull-up resistors on I2C are mandatory - not optional ???



    Most times the bug is in front of the keyboard.
    #19
    Krixen
    Junior Member
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2015/03/30 11:18:29
    • Location: 0
    • Status: offline
    Re: I2C not working, MCC issue? 2017/11/13 09:18:10 (permalink)
    3 (1)
    I have the pull-up resistors on, and always have. I only tried to take them off to get rid of that 1/2 VCC on each data and clock line issue to see if that was it.
     
    The problem lies with the pickit3. The pull-ups on the pickit3 must be interfering with mine or something of that nature. Haven't completely understood it yet. 
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2017 APG vNext Commercial Version 4.5