• AVR Freaks

Hot!I2C master not generating start condition, or any condition...

Author
erikblue
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2019/04/30 13:00:16
  • Location: 0
  • Status: offline
2020/07/13 21:31:02 (permalink)
0

I2C master not generating start condition, or any condition...

Hi,
 
I have several I2C master designs using the 16F18326. I created my own I2C write/read functions using registers (no interrupts). Now I'm using 16F18446 with the same write/read functions but can't seem to generate a start function.
 
I do this:
SSP2CON2bits.SEN = 1; /* Begin I2C start */

 
And then poll for the flag to get set:
while(SSP2IF == 0);

 
But nothing happens and my watchdog expires.
 
My pin_manager function initializes things like this:
SSP2DATPPS = 0x0D; //RB5->MSSP2:SDA2; 
RB7PPS = 0x15; //RB7->MSSP2:SCL2;
RB5PPS = 0x16; //RB5->MSSP2:SDA2;
RC4PPS = 0x18; //RC4->NCO1:NCO1OUT;
SSP2CLKPPS = 0x0F; //RB7->MSSP2:SCL2;

 
There is one thing that seems weird, and that is that the datasheet in Table 16-3 does not actually list 0x15 and 0x16 as valid settings for the PPS output signal registers!? This code was generated from MCC, so who should I trust more?
 
And my I2C initialization function does this:
void I2CInit(void)
{
/* I2C baud rate target is 100kHz - use equation per pg 364 of datasheet */
/* i2c_clk_period = (SSPxADD<7:0> + 1)*4 / Fosc */
SSP2ADD = 0x3; /*TODO: understand how exactly this changes I2C frequency */
PIE3bits.SSP2IE = 1; /* set as I2C master */
PIR3bits.SSP2IF = 0;
SSP2STAT = 0x00;
SSP2CON1 = 0x28;
SSP2CON2 = 0x00;
PIE3bits.SSP2IE = 1;
}

 
And finally in main.c, I enable interrupts (even though I'm not using them) because it seemed that I needed to do that to get the interrupt flag register to actually post flags so I could poll it:
GIE = 1;
PEIE = 1;

 
Thanks in advance for any tips, its been a few hours now and am stumped.
 
Erik
#1

2 Replies Related Threads

    ric
    Super Member
    • Total Posts : 27975
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: I2C master not generating start condition, or any condition... 2020/07/13 22:00:12 (permalink)
    +1 (1)
    erikblue
    My pin_manager function initializes things like this:

    I don't see any code wirting to ANSELB to switch RB5 and RB7 from analog to digital mode.

    There is one thing that seems weird, and that is that the datasheet in Table 16-3 does not actually list 0x15 and 0x16 as valid settings for the PPS output signal registers!? This code was generated from MCC, so who should I trust more?

    That looks like a clear omission in the datasheet. If MCC uses those values, they're probably correct.
     

    And finally in main.c, I enable interrupts (even though I'm not using them) because it seemed that I needed to do that to get the interrupt flag register to actually post flags so I could poll it:

    DON'T do that!
    GIE and PEIE do not gate the xxIF interrupt request flags, and WILL generate a jump to the interrupt service if the matching xxIE flag is set.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    erikblue
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2019/04/30 13:00:16
    • Location: 0
    • Status: offline
    Re: I2C master not generating start condition, or any condition... 2020/07/15 18:37:26 (permalink)
    +1 (1)
    Thanks for the reply, turns out it was TRIS.  Somehow in MCC I had SCL set as an output, so TRISB[7] was being set to 0 instead of a 1.  Painful mistake, since it was a new board I was thinking something else was wrong...
    #3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5