Sensorian  1.0
C API Reference Guide Library
main.c
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
29 #include <stdio.h>
30 #include <stdbool.h>
31 #include <stdlib.h>
32 #include <time.h>
33 #include "EEPROM.h"
34 #include "Utilities.h"
35 #include "i2c.h"
36 
37 #define DEL 100
38 
39 int main(int argc, char **argv)
40 {
41  char wr_buff1[8] = {0x01,0x02,0x03,0x04,0x05,0x06,0x7,0x08};
42  char wr_buff2[8] = {0xa1,0xb2,0xc3,0xd4,0xe5,0xf6,0xa7,0x0a8};
43  char rd_buffer[8] = {0};
44  unsigned char i = 0;
45 
47 
48  printf("Status reg: 0x%2x. \r\n", EEPROM_Read(EEPROM_SREG));
49 
51  delay_ms(DEL);
52  EEPROM_Write(0x01,0x99);
53  delay_ms(DEL);
54  EEPROM_Write(0x02,0xa9);
55  delay_ms(DEL);
56  EEPROM_Write(0x03,0xc9);
57  delay_ms(DEL);
58  EEPROM_Write(0x04,0xd9);
59  delay_ms(DEL);
60 
61  printf("Reading individual bytes. \r\n");
62  printf("EE0 0x%2x. \r\n", EEPROM_Read(EEPROM_START));
63  printf("EE1 0x%2x. \r\n", EEPROM_Read(EEPROM_START+1));
64  printf("EE2 0x%2x. \r\n", EEPROM_Read(EEPROM_START+2));
65  printf("EE3 0x%2x. \r\n", EEPROM_Read(EEPROM_START+3));
66  printf("EE4 0x%2x. \r\n", EEPROM_Read(EEPROM_START+4));
67 
68  printf("Writing individual pages. \r\n");
70  delay_ms(DEL);
71  printf("Reading individual pages. \r\n");
72 
73  EEPROM_ReadPage(EEPROM_START,rd_buffer);
74  for(i =0;i<8;i++)
75  {
76  printf("EE%d 0x%2x. \r\n", i,rd_buffer[i]);
77  }
78 
79  printf("Writing individual pages. \r\n");
80  EEPROM_WritePage(EEPROM_START+8,wr_buff2);
81  delay_ms(DEL);
82  printf("Reading individual pages. \r\n");
83  EEPROM_ReadPage(EEPROM_START+8,rd_buffer);
84  for(i =0;i<8;i++)
85  {
86  printf("EE%d 0x%2x. \r\n", i,rd_buffer[i]);
87  }
88 
89  I2C_Close(); //Return I2C pins to default status
90 
91  return 0;
92 }
93 
94 
Utilities driver header.
#define DEL
Definition: main.c:37
unsigned char EEPROM_Read(unsigned char mem_address)
The function reads a data byte from the EEPROM.
Definition: EEPROM.c:70
void I2C_Close(void)
Closes the I2C peripheral.
Definition: i2c.c:174
void EEPROM_Write(unsigned char mem_address, unsigned char ee_data)
This function writes a single byte in the I2C EEPROM.
Definition: EEPROM.c:45
void EEPROM_WritePage(char mem_address, char *buffer)
This function writes a single page to the RTCC EEPROM.
Definition: EEPROM.c:92
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition: i2c.c:36
#define EEPROM_ADDRESS
Definition: EEPROM.h:38
void EEPROM_ReadPage(char mem_address, char *buffer)
This function reads a single page from the RTCC EEPROM.
Definition: EEPROM.c:102
int main(int argc, char **argv)
Definition: main.c:34
#define EEPROM_SREG
Definition: EEPROM.h:59
void delay_ms(unsigned int ms)
Delay in ms.
Definition: Utilities.c:39
EEPROM driver header.
#define EEPROM_START
Definition: EEPROM.h:44
I2C driver header.