Not applicable
Jun 19, 2015
04:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jun 19, 2015
04:05 AM
Hello,
I try to access a nfc (near field communication) reader via I2C using a xmc4200 and the xmc peripheral library. As there is very little documentation (or I was not able to find it) for the xmc i2c library part, I've picked the example, that was shipped with the xmc peripheral library. In a small example, I want to see that I'm able to write 10 bytes to a fifo (first in first out) within the nfc reader and after this, reading back the fifo content.
I've learned that I have to use XMC_I2C_CH_MasterReceiveAck() to indicate that I'm going to read data from the bus and acknowledge that data for all, but the first byte. For the last byte I have to send a Nack using XMC_I2C_CH_MasterReceiveNack(). For every byte to be received, I should be able to poll the protocol status register for XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION or XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION and seeing one of the flags would indicate that a new byte is ready in RBUF to be read:
The code above works well, when stepping through it, using a debugger. But if I'm setting a breakpoint behind the loop, I see that some (3) values at the beginning are repeated. If I write for example [ 0xff, 0x00, 0xaa, 1, 2 , 3 , 4 , 5, 6, 7 ] to the fifo, I read back [ 0xff, 0xff, 0xff, 0x00, 0xaa, 1, 2, 3 ...]. By using an oscilloscope, I can tell that the data on the bus was right in such cases. So to me, it looks like, I'm reading to much data from one event and there must be some other flags that must be checked too.
Does someone of you have used this API and knows how to use it? Neither the search function of this forum, nor google reveals any results to a search for "XMC_I2C_CH_GetReceivedData()".
Kind regards,
Torsten
I try to access a nfc (near field communication) reader via I2C using a xmc4200 and the xmc peripheral library. As there is very little documentation (or I was not able to find it) for the xmc i2c library part, I've picked the example, that was shipped with the xmc peripheral library. In a small example, I want to see that I'm able to write 10 bytes to a fifo (first in first out) within the nfc reader and after this, reading back the fifo content.
I've learned that I have to use XMC_I2C_CH_MasterReceiveAck() to indicate that I'm going to read data from the bus and acknowledge that data for all, but the first byte. For the last byte I have to send a Nack using XMC_I2C_CH_MasterReceiveNack(). For every byte to be received, I should be able to poll the protocol status register for XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION or XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION and seeing one of the flags would indicate that a new byte is ready in RBUF to be read:
static void receive( std::uint8_t* buffer, std::size_t buffer_size )
{
for ( ; buffer_size; --buffer_size, ++buffer )
{
if ( buffer_size == 1 )
{
XMC_I2C_CH_MasterReceiveNack(channel);
}
else
{
XMC_I2C_CH_MasterReceiveAck(channel);
}
while( ( XMC_I2C_CH_GetStatusFlag( channel )
& ( XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION | XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION ) ) == 0U )
{
/* wait for ACK */
}
XMC_I2C_CH_ClearStatusFlag(XMC_I2C1_CH0, XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
*buffer = XMC_I2C_CH_GetReceivedData(channel);
}
}
The code above works well, when stepping through it, using a debugger. But if I'm setting a breakpoint behind the loop, I see that some (3) values at the beginning are repeated. If I write for example [ 0xff, 0x00, 0xaa, 1, 2 , 3 , 4 , 5, 6, 7 ] to the fifo, I read back [ 0xff, 0xff, 0xff, 0x00, 0xaa, 1, 2, 3 ...]. By using an oscilloscope, I can tell that the data on the bus was right in such cases. So to me, it looks like, I'm reading to much data from one event and there must be some other flags that must be checked too.
Does someone of you have used this API and knows how to use it? Neither the search function of this forum, nor google reveals any results to a search for "XMC_I2C_CH_GetReceivedData()".
Kind regards,
Torsten
Labels
2 Replies
Jul 03, 2015
05:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 03, 2015
05:52 AM
Hi,
Could it be you make the following line is wrong?
should not be channel used as first parameter?
Best regards,
Jesus
Could it be you make the following line is wrong?
XMC_I2C_CH_ClearStatusFlag(XMC_I2C1_CH0, XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
should not be channel used as first parameter?
Best regards,
Jesus
Not applicable
Jul 08, 2015
10:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 08, 2015
10:34 AM
Hello Jesus,
yes, that was the bug. Thank you very much for!
Cheers,
Torsten
yes, that was the bug. Thank you very much for!
Cheers,
Torsten