1
1
/**
2
2
* @file EEPROM_program.c
3
3
* @author Abdulrahman Aboghanima ([email protected] )
4
- * @brief
5
- * @version 0.1
4
+ * @brief Contains functions declaration for the EEPROM module
5
+ * @version 0.2
6
6
* @date 2022-02-03
7
7
* @todo Fix or remove the delays. Include the in the I2C driver
8
8
* @copyright Copyright (c) 2022
13
13
#include "../../LIB/STD_TYPES.h"
14
14
#include <util/delay.h>
15
15
16
- #define EEPROM_ADDRESS 0b1010000
16
+ #define EEPROM_ADDRESS ( 0b1010000 | (A2_PIN<<2) )
17
+
17
18
/*
18
- Suppos you would like to access memory which address is : X9X8X7X6X5X4X3X2X1X0
19
+ Suppose you would like to access memory which address is : X9X8X7X6X5X4X3X2X1X0
19
20
So in order to access that location you have to through the following address in the I^{2}C Bus
20
21
|---+---+---+---+----+----+----|
21
22
| 1 | 0 | 1 | 0 | A2 | X9 | X8 |
@@ -30,72 +31,51 @@ So in order to access that location you have to through the following address in
30
31
*/
31
32
32
33
33
- void EEPROM_writeByte (const uint8_t data , const uint16_t address )
34
+ extern void EEPROM_writeByte (const uint8_t data , const uint16_t address )
34
35
{
35
36
TWI_sendStartCondition ();
36
- _delay_ms ( 50 );
37
- TWI_sendSlaveAddressWithWrite ( EEPROM_ADDRESS | (A2_PIN << 2 ) |( address >>8 ) );
38
- _delay_ms ( 50 );
37
+ /*Send slave address (which consists also of the number of block)*/
38
+ TWI_sendSlaveAddressWithWrite ( EEPROM_ADDRESS | (address >>8 ) );
39
+ /*Send the address of the byte in the block(block consists of 256 bytes)*/
39
40
TWI_masterWrite ( (uint8_t ) address );
40
- _delay_ms (50 );
41
41
TWI_masterWrite (data );
42
- _delay_ms (50 );
43
42
TWI_sendStopCondition ();
44
- _delay_ms (50 );
45
43
}
46
44
47
- void EEPROM_readByte (uint8_t * const var , const uint16_t address )
45
+ extern void EEPROM_readByte (uint8_t * const var , const uint16_t address )
48
46
{
49
47
TWI_sendStartCondition ();
50
- _delay_ms (50 );
51
- TWI_sendSlaveAddressWithWrite (EEPROM_ADDRESS | (A2_PIN <<2 ) | (address >>8 ));
52
- _delay_ms (50 );
48
+ TWI_sendSlaveAddressWithWrite (EEPROM_ADDRESS | (address >>8 ));
53
49
TWI_masterWrite ((uint8_t ) address );
54
- _delay_ms (50 );
55
50
TWI_sendRepeatedStartCondition ();
56
- _delay_ms (50 );
57
- TWI_sendSlaveAddressWithRead (EEPROM_ADDRESS | (A2_PIN <<2 ) | (address >>8 ));
58
- _delay_ms (50 );
51
+ TWI_sendSlaveAddressWithRead (EEPROM_ADDRESS | (address >>8 ));
59
52
TWI_masterRead (var , 1 );
60
- _delay_ms (50 );
61
53
TWI_sendStopCondition ();
62
- _delay_ms (100 );
63
-
64
54
}
65
55
66
- void EEPROM_writeSequence ( uint8_t * const sequence , const uint16_t firstAddress , const uint16_t sequenceSize )
56
+ extern void EEPROM_writePage ( const uint8_t * const sequence , const uint16_t firstAddress , const uint8_t pageSize )
67
57
{
68
58
TWI_sendStartCondition ();
69
- _delay_ms ( 20 );
70
- TWI_sendSlaveAddressWithWrite (EEPROM_ADDRESS |( A2_PIN << 2 )| (firstAddress >>8 ));
71
- _delay_ms ( 20 );
59
+ /*Send slave address (which consists also of the number of block)*/
60
+ TWI_sendSlaveAddressWithWrite (EEPROM_ADDRESS | (firstAddress >>8 ));
61
+ /*Send the address of the byte in the block (block consists of 256 bytes)*/
72
62
TWI_masterWrite ((uint8_t )firstAddress );
73
- _delay_ms (20 );
74
- for (uint8_t i = 0 ; i < sequenceSize ; i ++ ){
63
+ for (uint8_t i = 0 ; i < pageSize ; i ++ ){
75
64
TWI_masterWrite (sequence [i ]);
76
- _delay_ms (20 );
77
65
}
78
66
TWI_sendStopCondition ();
79
- _delay_ms (100 );
80
67
}
81
68
82
- void EEPROM_readSequence (uint8_t * const sequence , const uint16_t firstAddress , const uint16_t sequenceSize )
69
+ extern void EEPROM_readSequence (uint8_t * const sequence , const uint16_t firstAddress , const uint16_t sequenceSize )
83
70
{
84
71
TWI_sendStartCondition ();
85
- _delay_ms (20 );
86
- TWI_sendSlaveAddressWithWrite (( EEPROM_ADDRESS | (A2_PIN <<2 ) | (firstAddress >>8 ) ));
87
- _delay_ms (20 );
72
+ TWI_sendSlaveAddressWithWrite (( EEPROM_ADDRESS | (firstAddress >>8 ) ));
88
73
TWI_masterWrite ( (uint8_t ) firstAddress );
89
- _delay_ms (20 );
90
74
TWI_sendRepeatedStartCondition ();
91
- _delay_ms (20 );
92
- TWI_sendSlaveAddressWithRead ( EEPROM_ADDRESS | (A2_PIN <<2 ) | (firstAddress >>8 ) );
93
- _delay_ms (20 );
75
+ TWI_sendSlaveAddressWithRead ( EEPROM_ADDRESS | (firstAddress >>8 ) );
94
76
for (uint16_t i = 0 ; i < sequenceSize ; i ++ ){
95
77
TWI_masterRead (sequence + i , sequenceSize - i );
96
- _delay_ms (100 );
97
78
}
98
79
99
80
TWI_sendStopCondition ();
100
- _delay_ms (100 );
101
81
}
0 commit comments