Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with PIC16F877A I2C communication with RTC module. FULL DESCRIPTION BELOW

Status
Not open for further replies.

Marcus314

Newbie
Joined
Jan 6, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
Good afternoon. I recently started a project that involves a DS3231 RTC module, a LM016 2x16 alphanumetic LCD and a PIC16F877A. My project is a programmable clock. The DS3231 communicates via I2C protocol. Now before starting I want to say that this is part of a school assignment and our teacher said that only ASSEMBLY is permitted.

I developed a .INC file for the I2C protocol:



Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
i2c_inicializa  ;For initializing the MSSP module in I2C mode
        bcf     STATUS,RP1
        bsf     STATUS,RP0
        bsf     TRISC,TRISC3
        bsf     TRISC,TRISC4
        movlw   B'10000000'
        movwf   SSPSTAT
        bcf     STATUS,RP0
        movlw   B'00101000'
        movwf   SSPCON
        bsf     STATUS,RP0
        movlw   B'00000000'
        movwf   SSPCON2
        movlw   D'9'
        movwf   SSPADD
        return
 
        i2c_espera      ;This is an idle subroutine for producing a 1 millisecond delay between I2C commands
        call    retardo_1ms
        return
 
        i2c_inicio      ;Sends a START condition
        bcf     STATUS,RP1
        bsf     STATUS,RP0
        call    i2c_espera
        bsf     SSPCON2,SEN
        return
        
        i2c_reinicio    ;Sends a RESTART condition
        bcf     STATUS,RP1
        bsf     STATUS,RP0      
        call    i2c_espera
        bsf     SSPCON2,RSEN
        return
 
        i2c_parada      ;Sends a STOP condition
        bcf     STATUS,RP1
        bsf     STATUS,RP0
        call    i2c_espera
        bsf     SSPCON2,PEN
        return
 
        i2c_envia_dato  ;This is for WRITING data to the slave
        bcf     STATUS,RP1
        bcf     STATUS,RP0
        movwf   SSPBUF
        call    i2c_espera
        return
 
        i2c_recibe_dato ;This is for READING data sent by the slave
        bcf     STATUS,RP1
        bsf     STATUS,RP0
        call    i2c_espera
        bsf     SSPCON2,RCEN
        call    i2c_espera
        bsf     SSPCON2,ACKDT
        bsf     SSPCON2,ACKEN
        bcf     STATUS,RP1
        bcf     STATUS,RP0
        movf    SSPBUF,0
        return



This is the circuit in PROTEUS

snap.PNG

This is the problem: when I built the code in MPLAB which is this:


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ORG 0x00
    CBLOCK  0x26
    CONT_PAL
    ENDC
    
    call    i2c_inicializa
    call    i2c_inicio
    movlw   B'11010000'           ;DS3231 address
    call    i2c_envia_dato
    movlw   B'00000001'           ;Address to enter
    call    i2c_envia_dato
    movlw   B'00010000'           ;Data to write
    call    i2c_envia_dato 
    call    i2c_parada   
    main
    nop 
    goto main
    #INCLUDE    <retardos.INC>
    #INCLUDE    <i2c.INC>
    #INCLUDE    <lcd.INC>
    END



It shows no errors during build. When running the simulation a window pops up showing the TIME and DATE set at 00:00:00 and 00/00/00 default. I want to modify it so that for example when starting time sets at 00:10:00 so I enter to the MINUTES register (see datasheet) and write a BCD code for for the MINUTES register. However when running up the simulation this does not happen, and not just that, I placed a I2C debugger and it shows me this:

capturee.PNG

Where's the ACK bit? Why the byte of the address is different the one I sent? I really would appreciate your answers. Thanks.
 
Last edited by a moderator:

I guess, sending the first data byte (I2C address) is ignored by the processor, because the start condition generation hasn't yet finished.

You are inserting huge useless delays in your code, but don't wait where it's necessary. After setting SEN in SSPCON2, you should wait until the bit is automatically reset by the processor, indicating finished start.

Suggestion: Start with known working code examples by Microchip.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top