Facebook
From ja, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 220
  1. #include <Wire.h>
  2. #include "Adafruit_FRAM_I2C.h"
  3.  
  4. /* Connect SCL    to analog 5
  5.    Connect SDA    to analog 4
  6.    Connect VDD    to 5.0V DC
  7.    Connect GROUND to common ground */
  8.    
  9. Adafruit_FRAM_I2C fram     = Adafruit_FRAM_I2C();
  10. uint16_t          framAddr = 0;
  11.  
  12. void writeByte(uint16_t pos,uint8_t value) {
  13.   fram.write8(pos,value);
  14.   Serial.print("Write Byte: ");
  15.   Serial.println(value, HEX);
  16. }
  17.  
  18. uint8_t readByte(uint16_t pos){
  19.   uint8_t value;
  20.   value = fram.read8(pos);
  21.   Serial.print("Read Byte: ");
  22.   Serial.println(value, HEX);
  23.   return value;
  24. }
  25.  
  26. void dump(){
  27.   uint8_t value;
  28.   for (uint16_t a = 0; a < 32768; a++) {
  29.     value = fram.read8(a);
  30.     if ((a % 32) == 0) {
  31.       Serial.print("\n 0x");
  32.       Serial.print(a, HEX);
  33.       Serial.print(": ");
  34.     }
  35.     Serial.print("0x");
  36.     if (value < 0x1)
  37.       Serial.print('0');
  38.     Serial.print(value, HEX);
  39.     Serial.print(" ");
  40.   }
  41. }
  42.  
  43. void setup() {
  44.   // Check code
  45.   Serial.begin(9600);
  46.  
  47.   if (fram.begin()) {  // you can stick the new i2c addr in here, e.g. begin(0x51);
  48.     Serial.println("Found I2C FRAM");
  49.   } else {
  50.     Serial.println("No I2C FRAM found ... check your connections\r\n");
  51.     while (1);
  52.   }
  53.  
  54.   uint8_t letter = 82;
  55.   writeByte(0x0,letter);
  56.   dump();
  57. }
  58.  
  59. void loop() {
  60.   // put your main code here, to run repeatedly:
  61.  
  62. }