New I2C module - more difficulty - PIC18F47K42
I'm moving from PIC18F47K40 to PIC18F47K42. The I2C module in the newer chip is trying to be smarter I think which means it is less than clear to me how it works and I think it has built in limitations that weren't there before...
To start out I'm going to try to use the module in Master mode and write one single little byte to a memory device. Nice and simple.
Looking at the datasheet on pp.567.
As I understand it, I should load up various registers with bits and pieces and let it rip with a start. My problem is understanding how to test for an ACK.
If I give it the control byte of the external chip in I2C2ADB1 and I put the upper address byte in I2C2TXB as it says to do in the datasheet, how do I know it received an ACK after sending the first byte ??
I also do not understand what they are saying in using the line 'with R/W = 0'. ???
This simple task of writing a byte is a total of 4 bytes. The first is the control byte to address the external chip. The second is a high address byte. The third is a low address byte and the last is the data byte.
My as yet incomplete routine follows:
bool i2c2_write_byte_to_any_address(uint8_t control_byte, uint16_t write_address, uint8_t byte_to_write)
bool device_response = true; // initialise to not-present value
uint8_t upper_write_address_byte = 0;
uint8_t lower_write_address_byte = 0;
lower_write_address_byte = write_address & 0x00FF;
write_address = write_address >> 8;
upper_write_address_byte = write_address & 0x00FF;
while(I2C2STAT0.BFRE = 0) // waiting for the I2C bus to become idle (it should be so already)
I2C2CON2.ABD = 0;
I2C2CNT = 0x04;
I2C2ADB1 = control_byte;
I2C2TXB = upper_write_address_byte;
I2C2CON0bits.S = 1; // send a start
I have managed previously to basically bit-bash my way around I2C then I started using the module in the PIC18F47K40 and now I'm using the module in this new chip.
My other issue here is that because the count register can't be disabled (I believe), does that mean I can never write a sequence of more than 256bytes on the I2C bus ??
Thanks in advance,