I am using a PIC18F46K42 as a master and a PIC18F46K22 as a slave. The master calls for an ADC result from the slave, the slave will load the MSB into the buffer and clock it out but the will not load the LSB in the buffer and just clocks the MSB out again.
C:
case PoolTemp:
data = RawPool >> 8;
i2cSend(data);
data = RawPool;
i2cSend(data);
break;
static inline void i2cSend (char data)
{
uint8_t delayCounter = 255;
while (--delayCounter)
{
if (EMPTY == SSP1STATbits.BF)
{
SSP1BUFbits.SSPBUF = data;
SSP1CON1bits.CKP = 1; // release SCL
break;
}
else
{
__delay_us(10);
}
}
}
Yes, the AHEN, DHEN, & SEN are all enabled. I have it delayed just to hold in loop tell the byte is clocked out and the buffer is ready to transfer the next byte.
I assume we're looking at the slave code. No delay should be needed as the BF bit will be set until it's been transmitted - I don't use the BF bit but rely on the SSPIF to tell me when things have completed. Your routine can also timeout which will cause the second byte not to be sent. BTW, indenting your code would make it much more readable.