I2C not working

I2C not working

Postby Azruine » Wed May 15, 2019 7:06 am

Using PIC16LF1509, Pickit3, MPLAB X IDE 5.05

My code:
Code: Select all
#include <xc.h>

#define _XTAL_FREQ 16000000
#define   XC_HEADER_TEMPLATE_H

// CONFIG1
#pragma config FOSC = INTOSC    // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = ON    // CLKOUT enabled *16MHz clk?
#pragma config IESO = OFF       // Internal/External Switchover Mode (Internal/External Switchover Mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config STVREN = OFF     // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF      // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = OFF        // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

int main()
{
    SSP1CON1 = 0x28;
    SSP1CON2 = 0x00;
    SSP1CON3 = 0x00;
    SSP1ADD = 255;
    TRISBbits.TRISB4 = 1;
    TRISBbits.TRISB6 = 1;    //SDA ans SCL
    TRISC = 0;
    TRISAbits.TRISA2 = 0;
    ANSELB = 0;
    OSCCON = 0b01111010;
    LATAbits.LATA2 = 0;  //LED connected to A2
   
    SSP1CON2bits.SEN = 1;
    while(SSP1CON2bits.SEN);
    SSP1BUF = (0x0D << 1) + 1;
    while(SSP1CON2bits.ACKSTAT);
    LATAbits.LATA2 = 1;
   
    while(1);
    return 1;
}


LED turns on but SDA and SCL signals are exactly same.

Image

1 is SDA, 2 for SCL and red is 1-2.

SDA and SCL are both connected to VDD with pull up register 10k since slave requires 10k in datasheet.
Azruine
 
Posts: 2
Joined: Wed Apr 17, 2019 3:50 am

Re: I2C not working

Postby AussieSusan » Fri May 17, 2019 3:26 am

Have any of the comments in https://www.microchip.com/forums/m1097977.aspx helped?
Susan
AussieSusan
Verified identity
 
Posts: 102
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: I2C not working

Postby Azruine » Thu May 23, 2019 7:16 am

Nothing :(

AussieSusan wrote:Have any of the comments in https://www.microchip.com/forums/m1097977.aspx helped?
Susan
Azruine
 
Posts: 2
Joined: Wed Apr 17, 2019 3:50 am


Return to SSP (IIC, SPI)

Who is online

Users browsing this forum: No registered users and 1 guest