This example shows typical use of the Inter-Integrated Circuits (I2C) module in polling mode.
- Source code:
#include "drivers.h"
#define BYTES (uint8)5
static uint8 volatile ui8_data[BYTES];
#define I2CWRITE(x) \
{ \
I2C_WrData(I2C0, (x)); \
while(I2C_GetIsrFlag(I2C0) == 0); \
I2C_ClrIsrFlag(I2C0); \
}
#define I2CREAD(x) \
{ \
while(I2C_GetIsrFlag(I2C0) == 0); \
x = I2C_RdData(I2C0); \
I2C_ClrIsrFlag(I2C0); \
}
void main (void)
{
I2CWRITE(0xA0);
I2CWRITE(0x00);
for (i=0; i<BYTES; i++)
I2CWRITE(2*i);
I2CWRITE(0xA0);
I2CWRITE(0x00);
I2CWRITE(0xA1);
for (i=0; i<BYTES; i++)
{
if (i == (BYTES-1))
{
}
else
{
I2CREAD(ui8_data[i]);
}
}
while(1);
}
- Toolchain support:
IAR EWARM 7.40.7 | KEIL uVision 5.15 | CrossWorks 3.6 | ATOLLIC TrueStudio 5.3.0 | Kinetis Design Studio 3.0.0 |
♦ | ♦ | ♦ | ♦ | ♦ |