Skip to content

Commit

Permalink
Updated and added new EEPROM interface methods (#FIRM-27)
Browse files Browse the repository at this point in the history
  • Loading branch information
satishgn authored and m-mcgowan committed Sep 9, 2015
1 parent 344ad51 commit c30d4c7
Showing 1 changed file with 69 additions and 4 deletions.
73 changes: 69 additions & 4 deletions src/content/reference/firmware.md
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ To use the TX/RX (Serial1) or D1/D0 (Serial2) pins to communicate with your pers

Sets the data rate in bits per second (baud) for serial data transmission. For communicating with the computer, use one of these rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. You can, however, specify other rates - for example, to communicate over pins TX and RX with a component that requires a particular baud rate.

**NOTE:** The data rate for the USB device `Serial` is ignored, as USB has its own negotiated speed. Setting speed to 9600 is safe for the USB device. Setting the port to 14400 baud will cause the Photon to go into DFU mode while 28800 will allow a YMODEM download of firmware.
**NOTE:** The data rate for the USB device `Serial` is ignored, as USB has its own negotiated speed. Setting speed to 9600 is safe for the USB device. Setting the port to 14400 baud will cause the Photon to go into DFU mode while 28800 will allow a YMODEM download of firmware.

```C++
// SYNTAX
Expand Down Expand Up @@ -1797,7 +1797,7 @@ Serial1.flush();
### halfduplex()

Puts Serial1 into half-duplex mode. In this mode both the transmit and receive
are on the TX pin. This mode can be used for a single wire bus communications
are on the TX pin. This mode can be used for a single wire bus communications
scheme between microcontrollers.

```C++
Expand Down Expand Up @@ -3597,7 +3597,7 @@ The parameter for millis is an unsigned long, errors may be generated if a progr

### micros()

Returns the number of microseconds since the device began running the current program.
Returns the number of microseconds since the device began running the current program.

Firmware v0.4.3 and earlier:
- This number will overflow (go back to zero), after exactly 59,652,323 microseconds (0 .. 59,652,322) on the Core and after exactly 35,791,394 microseconds (0 .. 35,791,394) on the Photon.
Expand Down Expand Up @@ -4157,6 +4157,71 @@ uint8_t val = 0x45;
EEPROM.write(addr, val);
```

### update()
This method is similar to `EEPROM.write()` however this method will only write data if the cell contents pointed to by `address` is different to `value`. This method can help prevent unnecessary wear on the EEPROM cells.

`update(address, value)`

`address` is the address (int) of the EERPOM location that needs to be updated
`value` is the byte data (uint8_t) to write

```C++
// EXAMPLE USAGE
// Update a byte value to the second byte of EEPROM
int addr = 1;
uint8_t val = 0x45;
EEPROM.update(addr, val);
```

### get()
This function will retrieve any object from the EEPROM. Two parameters are needed to call this function. The first is an int containing the address from where the object needs to be read, and the second is the object you would like to read.

`get(address, object)`

`address` is the address (int) of the EERPOM location
`object` is the object data that would be read

```C++
// EXAMPLE USAGE
// Read a custom object from EEPROM addres
int addr = 10;
float fValue = 0.00f;
EEPROM.get(addr, fValue);

struct MyObject{
float field1;
byte field2;
char name[10];
};
MyObject myObj;
EEPROM.get(addr, myObj);
```

### put()
This function will write any object to the EEPROM. Two parameters are needed to call this function. The first is an int containing the address that is to be written, and the second is the object you would like to write.

`put(address, object)`

`address` is the address (int) of the EERPOM location to write to
`object` is the object data to write

```C++
// EXAMPLE USAGE
// Write a object value to the EEPROM address
int addr = 10;
float fValue = 123.456f;
EEPROM.put(addr, fValue);

struct MyObject{
float field1;
byte field2;
char name[10];
};
MyObject myObj = {12.34f, 25, "Test!"}
EEPROM.put(addr, myObj);
```
## STARTUP()
_Since 0.4.5_
Expand Down Expand Up @@ -4289,7 +4354,7 @@ When using manual mode:
*Since v0.4.4.*
Retrieves the amount of memory guaranteed to be available. The actual amount of free memory will be at least as large as the value returned.
Retrieves the amount of memory guaranteed to be available. The actual amount of free memory will be at least as large as the value returned.
```cpp
uint32_t freemem = System.freeMemory();
Expand Down

0 comments on commit c30d4c7

Please sign in to comment.