+ Post New Thread
Results 1 to 5 of 5
  1. #1
    Junior Member level 1
    Points: 376, Level: 4

    Join Date
    Jul 2017
    Posts
    18
    Helped
    0 / 0
    Points
    376
    Level
    4

    PIC16F1508 and MCP9801 simulation in Proteus

    1) I am trying to read the ambient temperature register in MCP9801 with the following code. My simulation is getting stuck on one line (highlighted in code below). I have attached the Simulation log.JPG.



    2) I have referred to the the relevant discussions previously done, but still

    wasn't able to figure the problem in my code.

    https://www.microchip.com/forums/m956027.aspx

    https://www.microchip.com/forums/m852246.aspx



    3) It's been two weeks I have started with MPLAB and PIC controllers. I have written Blinky LED for PIC16F1508, 688 and 1887. Also I have done UART communication using PIC16F1887.



    Code:
    #include 
    #include 
    #include 
    #include"pic16f1508.h"
    
    #define _XTAL_FREQ 16000000
    
    void initialise()
    {
    INTCONbits.GIE = 0; // GLOBAL INTERRUPTS DISABLED
    INTCONbits.PEIE = 0; // PERIPHERAL INTERRUPTS DISABLED
    PIE3 = 0; // INTERRUPTs DISABLED 
    
    SSP1STATbits.SMP = 1; // Slew rate control disabled for Standard Speed mode (100 kHz and 1 MHz)
    SSP1STATbits.CKE = 0; // Disable SMBus specific inputs
    SSP1ADD = 0x03; // CLOCK OF 31.25 KHZ SET
    SSP1MSK = 0; // NO MASK 
    TRISBbits.TRISB4 = 1; // 
    TRISBbits.TRISB6 = 1;
    ANSELB = 0;
    
    PIE1bits.SSP1IE = 0;
    SSP1CON1bits.WCOL = 0; // 1 - I2C CAN'T BE STARTED, 0 - GOOD TO GO
    SSP1CON1bits.SSPOV = 0;// 1 - BYTE RECEIVED WHEN SSP1BUF STILL HOLDING LAST BYTE
                                           // 0 - GOOD TO GO
    SSP1CON1bits.SSPEN = 1; // ENABLE I2C
    SSP1CON1bits.CKP = 0;
    SSP1CON1bits.SSPM0 = 0;
    SSP1CON1bits.SSPM1 = 0;
    SSP1CON1bits.SSPM2 = 0;
    SSP1CON1bits.SSPM3 = 1; // SSPM - 1000, MASTER MODE SELECTED
    
    SSP1CON2 = 0x00;
    SSP1BUF = 0;
    TRISC = 1;
    }
    
    void first_write()
    {
    SSP1CON2bits.SEN = 1; // START I2C
    
    while(SSP1CON2bits.SEN | SSP1STATbits.R_nW); // WAIT -(I GET STUCK OVER HERE!!!)
    
    SSP1BUF = 0x90; // 1001 - DEFAULT ADDRESS(MCP9801), 000 - I HAVE SET THE 
                               // LAST THREE BITS OF ADDRESS (MCP9801), 0 - WRITE
    
    while(SSP1CON2bits.ACKSTAT); // SEE IF ACKNOWLEDGEMENT HAS BEEN RECEIVED//
    SSP1BUF = 0; // TO SET THE REGISTER POINTER TO 00 FOR TEMPERATURE
    
    SSP1CON2bits.PEN = 1; // STOP I2C
    }
    void one_read()
    {
    SSP1CON2bits.SEN = 1;
    SSP1BUF = 0x91; // 1001 - DEFAULT ADDRESS, 000 - I HAVE SET THE LAST THREE
    
                               //  BITS OF ADDRESS (MCP9801), 1 - READ
                             
    while(0 == SSP1STATbits.BF); // WAIT WHILE RECEPTION NOT COMPLETE
    SSP1CON2bits.ACKDT = 0; // SEND ACKNOWLEDGEMENT
    SSP1CON2bits.PEN = 1; // STOP I2C
    PORTC = SSP1BUF; // 
    
    }
    void main(void)
    {
            {
                 initialise();
                 first_write();
                 one_read(); 
            }
    }
    Click image for larger version. 

Name:	Circuit.JPG 
Views:	5 
Size:	79.2 KB 
ID:	150680Click image for larger version. 

Name:	Simulation log.JPG 
Views:	5 
Size:	99.9 KB 
ID:	150679

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 1
    Points: 2,290, Level: 11
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    444
    Helped
    43 / 43
    Points
    2,290
    Level
    11

    Re: PIC16F1508 and MCP9801 simulation in Proteus

    In Proteus the I2C Pull-up resistors for 100 KHz I2C Clock should be 4.7k and DIGITAL type.


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  3. #3
    Junior Member level 1
    Points: 376, Level: 4

    Join Date
    Jul 2017
    Posts
    18
    Helped
    0 / 0
    Points
    376
    Level
    4

    Re: PIC16F1508 and MCP9801 simulation in Proteus

    Thanks for that! Does the code look okay ?



    •   AltAdvertisment

        
       

  4. #4
    Junior Member level 1
    Points: 376, Level: 4

    Join Date
    Jul 2017
    Posts
    18
    Helped
    0 / 0
    Points
    376
    Level
    4

    Re: PIC16F1508 and MCP9801 simulation in Proteus

    Also I have set 31.25 kHz clock frequency in SSP1BUF register(0x03).



  5. #5
    Advanced Member level 1
    Points: 2,290, Level: 11
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    444
    Helped
    43 / 43
    Points
    2,290
    Level
    11

    Re: PIC16F1508 and MCP9801 simulation in Proteus

    If code is correct then after making the pullup resistors 4.7k DIGITAL type then you should get the readings.



--[[ ]]--