edit: add development environment. edit2: added I2C command(s) code and a L.A. screen shot.
Development Environment: MPLABX 5.35, XC8 2.00, PIC18LF2580
If I read this post correctly, I think I am experiencing the same issue.
I overcame it by adding an additional read between the slave read command
and performing the read_device_byte() command. But is this the way things
are supposed to work? The slave datasheet (NT3H2211) seems to indicate
-> perform the slave read command
-> read_device_byte
when I do this then I get the slave read command address in the buffer.
(returned from the slave as Data0 (or is it the 2580 ??) )
the command function(s) code:
// I2C
void wait_for_idle(void) {
// ACKen/RXen/Pen/RSen/Sen
while ( ( SSPCON2 & 0x1F ) || (SSPSTAT & 0x04));
PIR1bits.SSPIF = 0x0;
SSPCON1bits.WCOL = 0x0;
};
void start(void) {// Start I2C comm's
wait_for_idle();
SSPCON2bits.SEN = 0x1;
};
// Stop I2C comm's
void stop(void){
wait_for_idle();
SSPCON2bits.PEN = 0x1;
};
// write address constants: write(slave_R); write(SRAM_BLK) *OR* data bytes
void write(unsigned char in_byte) {
wait_for_idle();
SSPBUF = in_byte;
};
// returns one byte. Call it in a loop, 2211 returns 16 bytes per block.
unsigned char read_device_byte(void) {
volatile unsigned char in_data;
wait_for_idle();
SSPCON2bits.RCEN = 0x1;
in_data = SSPBUF;
wait_for_idle();
SSPCON2bits.ACKDT = 0x0; // have to set the ack bit
SSPCON2bits.ACKEN = 0x1; // then initiate the acknowledge
return(in_data);
};
here is my code example:
for (dev_addr=0xf8; dev_addr<=0xfb; dev_addr++) {
start();
write(0xaa); // slave address write mode
write(dev_addr); // point to SRAM block.
stop();
i = dly_cntr_R;
while (i > 0x0) {i--;}; // need >= ~50usec delay here
start(); // slave imposed >50usec delay before start
write(0xab);
// 0xAB IN SSPBUF ??
read_device_byte(); // EXTRA READ TO CLEAR BUFFER
// NOW CANNED_DATA GETS POPULATED CORRECTLY
for (i = 0x00; i < 0x10; i++) {
canned_data[offset][i] = read_device_byte(); };
stop();
offset++;
};
Logic analyzer screen shot:
post edited by cabletie - 2020/09/28 05:47:53
Attached Image(s)
