As soon as i send i2c1_driver_TXData(0XD1); function I2c Stop responding and creating waveform.
This is an address for read, after it you must call "i2c_driver_startRX()" so the master generates the clock pulses that allow the slave to send the data beeing read. Don't forget that the slave never generates the clock signal, its allways the master.
OTOH the data line is shared bettwen the master and the slave. After sending the read address the master releases the data line for use by the slave but keeps controling the clock line in order to generate the clocks that the slave needs to output its data. (*)
It will generate waveform if input is i2c1_driver_TXData(0XD0);
This is a address for writing, so the master remains in control of data line and sends whatever data it has to send.
If you look at the code generated by MCC, in the file "i2c_driver.c" you will see that the "mssp1_waitForEvent()" function simply waits for the SSP1IF flag to become active, meaning that the last operations has been completed, so you can proceed with the next one.
But it don't clears the SSP1IF flag, so it must be cleared (mssp1_clearIRQ()) in order not to gave a false "operation complete signals" on the next operation.
In the PIC datasheet, figure 26-29 at page 464 shows the timeline of a master reading 2 bytes from the slave. All actions from master and slave are commented as all the actions on the MSSP control flags and buffer.
You can cross check this picture with the sequence of operations in the code and the actions behind each function generated by the MCC ().
Also compare this picture with the signals you see in your scope/logic analyzer, this way you can spot exactly in what point things went wrong.
(*) Don't forget that if the slave is not ready to send the requested data it can do a "clock stretch" until its ready to send its data. in this case the slave will keep the clock line low until its ready and things will seems to have stopped. If everything seems good until the moment the slave should start its data out, then set the logic analyzer/scope for a larger sample and see if something happens after a while (several miliseconds). I once had to cope with a temperature sensor that needed more than 700ms to finish a reading and be ready to send the data.
post edited by JorgeF - 2018/04/18 03:25:46