I'm trying to let one master board read one byte from a slave board and display the read result in master's LCD.The result doesn't correct. Unfortunately, I don't know how to correct it. Could you please give me some suggestions? I really appreciate any help from you. You can read the programs and some explanations below. The project is also attached.
In my project, one PSoC 5 board used as a master is supposed to read one byte from a slave PSoC 5 board. Slave board's address is set to 8 in both topdesign and program. I also use a LCD to display the value which is read by master.
The program of master is here:
uint8 buffer = 0x00;
/* Enable global interrupts - required for I2C */
LCD_Char_PrintString("Clr I2C status");
I2CM_MasterClearStatus(); /* Clear any previous status */
LCD_Char_ClearDisplay(); LCD_Char_PrintString("Sending data");
temp1=I2CM_MasterReadBuf(I2C_SLAVE_ADDRESS, (uint8 *)&buffer, MRD_BUFFER_SIZE, I2CM_MODE_COMPLETE_XFER);
LCD_Char_ClearDisplay(); LCD_Char_PrintString("Waiting for completion"); CyDelay(200u/*ms*/);
while(I2CM_MasterStatus() == I2CM_MSTAT_XFER_INP);
//when I run the project, LCD shows return value of I2CM_MasterStatus() is A1. What does it mean?
/* Delay introduced for ease of reading LCD */
} /* End main */
/*  END OF FILE */
Here is the program of slave:
I2CS_SlaveInitReadBuf((uint8 *)&buffer, RD_BUFFER_SIZE);
/*start I2C Slave operation*/
/* Enable global interrupts - needed for I2C operation */
while( I2CS_SlaveGetReadBufSize()< 1 );
} /* End of main */
From my understanding, if the project works well, master can read slave's buffer where 0x01 stores and the buffer in master will be changed to 0x01 from 0x00. So that I can see 01 in LCD. However, when I run the project, I2CM_MasterStatus() return A1 and the buffer in master is still 0X00.
It is interesting that why the return value of I2CM_MasterStatus() is A1. I guess A1 shows me I2C_MSTAT_RD_CMPLT, I2C_MSTAT_ERR_ADDR_NAK and I2C_MSTAT_ERR_XFER . But why there is something wrong with address.
I'm so confused. I really appreciate any suggestions and help from you. Thank you so much!
Look into I2CM.h, search for "error".
Then you see the bit-codes for your returned error:
#define I2CM_MSTAT_ERR_ADDR_NAK (0x20u) /* Slave did not ACK */
#define I2CM_MSTAT_ERR_XFER (0x80u) /* Error during transfer */
/* Master API returns */
#define I2CM_MSTR_BUS_BUSY (0x01u) /* Bus is busy, process not started */
since in the case of one error you re-try reading (which I would NOT do) there might be some codes mixed.