- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I'm stuck in trying to get a simple example working that include an I2C Master and I2C Slave. I trying to use the high-level API's to do a MasterReadBuff function call.
void InitializeSystem(void) | // Start all components, initialize variables, perform self-test |
{
uint8 ii; |
CyGlobalIntEnable;
for(ii = 0; ii < BUFFSIZE; ii++)
{
SlaveSendBuffer[ii] = ii; |
}
PWM_Start();
Slave_I2C_SlaveInitReadBuf(SlaveSendBuffer, BUFFSIZE);
Slave_I2C_SlaveInitWriteBuf(SlaveReceiveBuffer,BUFFSIZE);
Slave_I2C_Start(); | // Initialize I2C slave |
Master_I2C_Start();
PWM_WriteCompare(1); |
}
int main()
{
int i,k; | |
uint32 MStatus; | |
uint8 temp =0; | |
uint8 mydata = 1; | |
uint8 write_data_buffer[SUB_ADDR_LENGTH] = {SUB_ADDR_LOCATION}; |
InitializeSystem();
MStatus = Master_I2C_MasterSendStart(SlaveAddr,Master_I2C_WRITE_XFER_MODE); | // Initialize a transaction for writing | ||
Master_I2C_MasterClearStatus(); | |||
Master_I2C_MasterReadBuf(SlaveAddr, Master_Rd_Buffer, READ_DATA_LENGTH, | Master_I2C_MODE_REPEAT_START); | ||
while(0u == (Master_I2C_MSTAT_ERR_XFER & Master_I2C_MSTAT_RD_CMPLT)) | |||
temp++; |
}
I'm having trouble reading from the SlaveReceive Buffer. Can anyone give me some help?
Thanks,
Joe
Solved! Go to Solution.
- Labels:
-
PSoC 5 Architecture
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Joe,
1. I2C_MasterReadBuf() will generate a start condition, slave address and the read/ write bit and will byte after byte in the further transactions. All these are managed by the ISR. Hence the I2C_MasterSendStart() is not required.
2. The right condition to wait for the transaction to get completed is:
while(0u == (Master_I2C_MasterStatus() & (Master_I2C_MSTAT_ERR_XFER | Master_I2C_MSTAT_RD_CMPLT)))
{
}
I have attached the modified project with this response. Hope it helps!
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Joe,
1. I2C_MasterReadBuf() will generate a start condition, slave address and the read/ write bit and will byte after byte in the further transactions. All these are managed by the ISR. Hence the I2C_MasterSendStart() is not required.
2. The right condition to wait for the transaction to get completed is:
while(0u == (Master_I2C_MasterStatus() & (Master_I2C_MSTAT_ERR_XFER | Master_I2C_MSTAT_RD_CMPLT)))
{
}
I have attached the modified project with this response. Hope it helps!
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content