c - PIC16F1459 I2C Master Ack Issue with 24LC32 -
i'm facing weird issue. i've used bit bangin i2c functions on pic16f1459, want use mssp (spi,i2c master slave peripheral). i've started writing functions according datasheet, start, stop, etc. problem have pic won't ack data send i2c eeprom. says in datasheet ack status can found @ sspcon2.ackstat. guess poll bit until slave responds data, program hangs in while loop.
void vreadack (void) { while (sspcon2.ackstat != 0); }
and here's write function, i2ccheck function , i2c master initialization function
void vi2cecrireoctet (uc ucdata, uc ucrw) { vi2ccheck(); switch (ucrw) { case read: sspbuf = ucdata + 1; break; case write: sspbuf = ucdata + 0; break; } vreadack(); } void vi2ccheck (void) { while (sspcon2.acken); //acken not cleared, wait while (sspcon2.rcen); //rcen not cleared, wait while (sspcon2.pen); //stop not cleared, wait while (sspcon2.sen); //start not cleared, wait while (sspcon2.rsen); //rep start not cleared, wait while (ssp1stat.r_not_w); //tx not done wait } void viniti2cmaster (void) { trisb4_bit = 1; //sda in trisb6_bit = 1; //scl in ssp1stat.smp = 1; //no slew rate ssp1stat.cke = 0; //disable smbus inputs sspadd = 0x27; //100 khz sspcon1 = 0b00101000; //i2c master mode sspcon3 = 0b00000000; //rien de slave }
just know, 24lc32a writeprotect tied vss, a2-a1-a0 tied gnd, adress 0xa0. 4k7 pull-ups on i2c line. pic16f1459 @ 16mhz intosc.
i'm stuck. i've went through mssp datasheet 5 6 times without finding issue. can guys help?
and here's logic analyzer preview (removing while inside vreadack() )
well looks i've found answer question. doing exact way of doing this. problem seemed bus free time delay required slave respond. @ 16mhz, i2c fast eeprom memory. i've added small delay function right after stop operation, write sequences delayed , bam, worked.
bus free time: time bus must free before new transmission can start.
Comments
Post a Comment