- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I configured a master I2C using the SCB block. I am trying to write some data to the slave using the function I2C_1_I2CMasterWriteBuf(). The following is my code snippet -
if(I2C_1_I2C_MSTR_NO_ERROR == I2C_1_I2CMasterWriteBuf(addr, buffer, size, I2C_1_I2C_MODE_COMPLETE_XFER ))
{
while( 0u == (I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_WR_CMPLT ))
{
/*Wait*/
CyDelay(3);
}
if(0u == (I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_ERR_XFER ))
{
if(I2C_1_I2CMasterGetWriteBufSize() == size)
{
result = ERROR;
}
}
}
bytes_sent = I2C_1_I2CMasterGetWriteBufSize();
At this point I2C_1_I2CMasterGetWriteBufSize() is always returning 1. What can be the error? Shouldn't this function return a number that is equal to size if the transfer was successful?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Since I2C_1_I2CMasterWriteBuf() can take long time if the buffer is big,
I think the function returns just after submitting the request.
So it will be the programmer's responsibility to monitor how much of the buffer has been sent.
In your case you monitored I2C_Status(), I imagined that the status of component gets to be complete
in each transaction, so your while loop exit at the first byte sent.
I think that the ..WriteBufSize() must be "the size - 1" at that time.
So I proposed to use while loop to wait until the size get to 0.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Following the datasheet I2C_1_I2CMasterGetWriteBufSize() returns the number of bytes still in the buffer to be sent.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The data sheet says this - Returns the number of bytes that have been transferred with the SCB_I2CMasterWriteBuf() function
[This is a PSOC4 device]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I think that calling I2C_1_I2CMasterWriteBuf() requests "size" byte of transfer
and the I2C_1_I2CMasterStatus() could be I2C_I2C_MSTAT_WR_CMPLT
for each byte sent.
So the first while loop exit at the first byte sent.
If you want to wait for the completion of the buffer sent
you may need to use a loop something like
while(I2C_1_SCB_I2CMasterWriteBuf() != size) {
;
}
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you said this - I2C_1_I2CMasterWriteBuf() requests "size" byte of transfer, do you mean the function I2C_1_I2CMasterGetWriteBufSize() instead?
Because I2C_1_I2CMasterWriteBuf() is the function that actually writes an entire buffer of data to a slave device.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Since I2C_1_I2CMasterWriteBuf() can take long time if the buffer is big,
I think the function returns just after submitting the request.
So it will be the programmer's responsibility to monitor how much of the buffer has been sent.
In your case you monitored I2C_Status(), I imagined that the status of component gets to be complete
in each transaction, so your while loop exit at the first byte sent.
I think that the ..WriteBufSize() must be "the size - 1" at that time.
So I proposed to use while loop to wait until the size get to 0.
moto