i2cdrv.c
Go to the documentation of this file.00001
00036 #include <stddef.h>
00037 #include "em_cmu.h"
00038 #include "em_gpio.h"
00039 #include "bsp.h"
00040 #include "i2cdrv.h"
00041
00042
00043
00044
00045
00046
00058 void I2CDRV_Init(const I2C_Init_TypeDef *init)
00059 {
00060 int i;
00061
00062 BSP_PeripheralAccess(BSP_I2C, true);
00063 CMU_ClockEnable(cmuClock_HFPER, true);
00064 CMU_ClockEnable(cmuClock_I2C0, true);
00065
00066
00067
00068
00069 GPIO_PinModeSet(gpioPortD, 15, gpioModeWiredAnd, 1);
00070 GPIO_PinModeSet(gpioPortD, 14, gpioModeWiredAnd, 1);
00071
00072
00073
00074 for (i = 0; i < 9; i++)
00075 {
00076
00077
00078
00079
00080
00081
00082 GPIO_PinModeSet(gpioPortD, 15, gpioModeWiredAnd, 0);
00083 GPIO_PinModeSet(gpioPortD, 15, gpioModeWiredAnd, 1);
00084 }
00085
00086
00087 I2C0->ROUTE = I2C_ROUTE_SDAPEN |
00088 I2C_ROUTE_SCLPEN |
00089 (3 << _I2C_ROUTE_LOCATION_SHIFT);
00090
00091 I2C_Init(I2C0, init);
00092 }
00093
00094
00095
00107 I2C_TransferReturn_TypeDef I2CDRV_Transfer(I2C_TransferSeq_TypeDef *seq)
00108 {
00109 I2C_TransferReturn_TypeDef ret;
00110 uint32_t timeout = 300000;
00111
00112 ret = I2C_TransferInit(I2C0, seq);
00113 while (ret == i2cTransferInProgress && timeout--)
00114 {
00115 ret = I2C_Transfer(I2C0);
00116 }
00117
00118 return(ret);
00119 }