1 | int main(void)
|
2 | {
|
3 | /* Chip errata */
|
4 | CHIP_Init();
|
5 |
|
6 | /* Enable clocks required */
|
7 | CMU_ClockEnable(cmuClock_HFPER, true);
|
8 |
|
9 |
|
10 | /* Enabling clock to the I2C */
|
11 | CMU_ClockEnable(cmuClock_I2C0, true);
|
12 | CMU_ClockEnable(cmuClock_GPIO, true);
|
13 | CMU_ClockEnable(cmuClock_CORELE, true); //??
|
14 |
|
15 |
|
16 | /* Starting LFXO and waiting until it is stable */
|
17 | CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
|
18 |
|
19 | /* Routing the LFXO clock to the RTC */
|
20 | CMU_ClockSelectSet(cmuClock_LFA,cmuSelect_LFXO);
|
21 | CMU_ClockEnable(cmuClock_RTC, true);
|
22 |
|
23 |
|
24 | /* Setup SysTick Timer for 1 msec interrupts */
|
25 | if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;
|
26 |
|
27 | /* Enable LCD without voltage boost */
|
28 | SegmentLCD_Init(false);
|
29 |
|
30 | setupI2C();
|
31 |
|
32 | Read_I2C_Data();
|
33 |
|
34 | ...
|
35 | }
|
36 |
|
37 | /**************************************************************************//**
|
38 | * @brief Setup I2C
|
39 | *****************************************************************************/
|
40 | void setupI2C(void)
|
41 | {
|
42 | // Using default settings
|
43 | I2C_Init_TypeDef i2cInit = I2C_INIT_DEFAULT;
|
44 |
|
45 | /* Using PD6 (SDA) and PD7 (SCL) */
|
46 | GPIO_PinModeSet(gpioPortD, 7, gpioModeWiredAndPullUpFilter, 1);
|
47 | GPIO_PinModeSet(gpioPortD, 6, gpioModeWiredAndPullUpFilter, 1);
|
48 |
|
49 |
|
50 | /* Enable pins at location 1 */
|
51 | I2C0->ROUTE = I2C_ROUTE_SDAPEN |
|
52 | I2C_ROUTE_SCLPEN |
|
53 | (1 << _I2C_ROUTE_LOCATION_SHIFT);
|
54 |
|
55 | /* Initializing the I2C */
|
56 | I2C_Init(I2C0, &i2cInit);
|
57 |
|
58 | I2C_Enable(I2C0, 1);
|
59 | }
|
60 |
|
61 | void Read_I2C_Data(){
|
62 | I2C_TransferReturn_TypeDef I2C_Status;
|
63 | uint8_t write_value[1];
|
64 | write_value[1]=128;
|
65 | I2C_TransferSeq_TypeDef seq;
|
66 | seq.addr = 0x58;
|
67 | seq.flags = I2C_FLAG_WRITE_WRITE;
|
68 | seq.buf[0].len = 1;
|
69 | seq.buf[0].data = 0;
|
70 | seq.buf[1].len = 1;
|
71 | seq.buf[1].data = write_value;
|
72 |
|
73 | I2C_Status = I2C_TransferInit(I2C0, &seq);
|
74 |
|
75 | while(I2C_Status == i2cTransferInProgress){
|
76 | I2C_Status=I2C_Transfer(I2C0);
|
77 | }
|
78 |
|
79 | int i=0;
|
80 | i++;
|
81 |
|
82 | }
|