P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
I2CCFG = 0xe0; //Enable I2C master mode
I2CMSST = 0x00;
Start(); //Send start command
SendData(0x5a); //Send device address (010_1101B) + write command (0b)
RecvACK();
SendData(0x00); //Send storage address
RecvACK();
SendData(0x12); //Write test data 1
RecvACK();
SendData(0x78); //Write test data 2
RecvACK();
Stop(); //Send stop command
Start(); //Send start command
SendData(0x5a); //Send device address (010_1101B) + write command (0b)
RecvACK();
SendData(0x00); //Send storage address high byte
RecvACK();
Start(); //Send start command
SendData(0x5b); //Send device address (010_1101B) + read command (1b)
RecvACK();
P0 = RecvData(); //Read data 1
SendACK();
P2 = RecvData(); //Read data 2
SendNAK();
Stop(); //Send stop command
P_SW2 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
P_SW2 DATA 0BAH
I2CCFG XDATA 0FE80H
I2CMSCR XDATA 0FE81H
I2CMSST XDATA 0FE82H
I2CSLCR XDATA 0FE83H
I2CSLST XDATA 0FE84H
I2CSLADR XDATA 0FE85H
I2CTXD XDATA 0FE86H
I2CRXD XDATA 0FE87H