E' vero...scusa...utilizzo il c e l'assembler.
Ho un timer che scade ogni secondo e richiama questo metodo:
void Read_I2cRTC(void)
{
unsigned char i = 0x000;
I2c_Init();
I2c_Start();
TxByte_I2c(_i2cRTCWRITE);
TxByte_I2c(_i2cRTCWRIN);
I2c_Restart();
TxByte_I2c(_i2cRTCREAD);
for (i = 0x000; i < 0x010; i ++)
{
BUF_RTC[i] = RxByte_I2c();
I2c_Ack();
}
I2c_Stop();
}
Questo è il codice relativo hai medoti che chiamo:
I2c_Init:
bsf TRISD,5,0 ;SDA serial data
bsf TRISD,6,0 ;SCL serial clock
bsf PORTD,5,0
bsf PORTD,6,0
bcf SSP2STAT,CKE ;status register CKE bit6 Disnable SMBus specific inputs
return
I2c_Start:
bsf SSP2CON2,SEN ;control register
btfsc SSP2CON2,SEN ;SEN: Start Condition Enable bit(
bra $ - 002H
return
I2c_Restart:
bsf SSP2CON2,RSEN ;Repeated Start Condition Enable bit(
btfsc SSP2CON2,RSEN
bra $ - 002H
return
I2c_Stop:
bsf SSP2CON2,PEN ;Stop Condition Enable bit
btfsc SSP2CON2,PEN
bra $ - 002H
return
I2c_Ack:
bcf SSP2CON2,ACKDT ;Acknowledge Data bit
bsf SSP2CON2,ACKEN ;Acknowledge Sequence Enable bit
btfsc SSP2CON2,ACKEN
bra $ - 002H
return
TxByte_I2c:
movf POSTDEC1,W,A
movff POSTDEC1,SSP2BUF
btfsc SSP2STAT,BF,A
bra $ - 002H
btfsc SSP2STAT,R_W,A
bra $ - 002H
btfsc SSP2CON2,ACKSTAT
nop
movf POSTINC1,W,A
movf POSTINC1,W,A
return
RxByte_I2c:
bsf SSP2CON2,RCEN
btfsc SSP2CON2,RCEN
bra $ - 002H
movf SSP2BUF,W,A ;Buffer register
btfsc SSP2STAT,BF,A
bra $ - 002H
return
Se serve altro chiedi pure
![]()