Hi,
I've once again bashed my head to what is called HW I2C on the PIC K42 architecture. This time, yet again ran into a wall. And since granddad seems to have gotten it to work in the old thread, which is locked, https://www.electro-tech-online.com/threads/pic18f25k42-a-work-in-progress.152004/page-3 , I wish to query how he did it.
Also, just for good measure, I'm happy my slave routine came to the rescue and I hope you rooted out the issues. I know I did .
In any case, this is my current code for I2C transfer, but I get stuck in the TXBE check all the time. Hardware sets PCIF for some odd reason. Most commonly after writing the second data byte to the transmit buffer.
Any suggestions?
All I2C1 registers at time of "hang":
I2C1ADB1 SFR 0x3D6E 0x78
I2C1BTO SFR 0x3D7C 0x00
I2C1CLK SFR 0x3D7B 0x03
I2C1CNT SFR 0x3D6C 0x18
I2C1CON0 SFR 0x3D73 0x84
I2C1CON1 SFR 0x3D74 0xA0
I2C1CON2 SFR 0x3D75 0x20
I2C1ERR SFR 0x3D76 0x10
I2C1PIE SFR 0x3D7A 0x00
I2C1PIR SFR 0x3D79 0x05
I2C1RXB SFR 0x3D6A 0x00
I2C1SCLPPS SFR 0x3AE1 0x13
I2C1SDAPPS SFR 0x3AE2 0x14
I2C1STAT0 SFR 0x3D77 0x88
I2C1STAT1 SFR 0x3D78 0x00
I've once again bashed my head to what is called HW I2C on the PIC K42 architecture. This time, yet again ran into a wall. And since granddad seems to have gotten it to work in the old thread, which is locked, https://www.electro-tech-online.com/threads/pic18f25k42-a-work-in-progress.152004/page-3 , I wish to query how he did it.
Also, just for good measure, I'm happy my slave routine came to the rescue and I hope you rooted out the issues. I know I did .
In any case, this is my current code for I2C transfer, but I get stuck in the TXBE check all the time. Hardware sets PCIF for some odd reason. Most commonly after writing the second data byte to the transmit buffer.
Any suggestions?
C:
void I2C_Transmit(char slave_write_address, int length, uint8_t *data) {
I2C1ADB1 = slave_write_address;
I2C1CNT = length;
I2C1CON0bits.S = 1; //Start
while (length-- > 0) {
unsigned char d = *data++;
I2C1TXB = d;
while (!I2C1STAT1bits.TXBE) {
}
}
// Detect Stop condition
while (!I2C1PIRbits.PCIF) {}
I2C1PIRbits.PCIF = 0;
I2C1PIRbits.SCIF = 0;
I2C1STAT1bits.CLRBF = 1;
}
All I2C1 registers at time of "hang":
I2C1ADB1 SFR 0x3D6E 0x78
I2C1BTO SFR 0x3D7C 0x00
I2C1CLK SFR 0x3D7B 0x03
I2C1CNT SFR 0x3D6C 0x18
I2C1CON0 SFR 0x3D73 0x84
I2C1CON1 SFR 0x3D74 0xA0
I2C1CON2 SFR 0x3D75 0x20
I2C1ERR SFR 0x3D76 0x10
I2C1PIE SFR 0x3D7A 0x00
I2C1PIR SFR 0x3D79 0x05
I2C1RXB SFR 0x3D6A 0x00
I2C1SCLPPS SFR 0x3AE1 0x13
I2C1SDAPPS SFR 0x3AE2 0x14
I2C1STAT0 SFR 0x3D77 0x88
I2C1STAT1 SFR 0x3D78 0x00