Serial Input to EEPROM
Receives Serial Data, Serial Parallel Conversion and Write To EEPROM
start.cpp
Go to the documentation of this file.
1 
20 #include "Arduino.h"
21 //#define DEBUG_LCD //disable for Simulation
22 #include "_debug.h"
23 #define SDA PINC0
24 #define CLK PINC1
25 
27 void setup()
28 {
29  // PINC no Pullups
30  cli(); //no interrupts
31 }
32 void loop()
33 {
34 
35  //wait for falling edge of clk
36  loop_until_bit_is_clear(PINC,CLK);
37  // wait for rising edge of clk
38  loop_until_bit_is_set(PINC,CLK);
39  // read data bit (LSB first)
40  uint8_t databit = PINC&(1<<SDA);
41 
42  // put data bit to receive buffer
43 
44  static uint8_t receivebuffer = 0; // static variables remember their values between subroutine calls (like global vars)
45  static uint8_t bitcounter = 0;
46  static uint8_t eepromaddress1 = 0xF;
47 
48  receivebuffer |= (databit << bitcounter); // bring bit to position
49  bitcounter++;
50  // if bit 8 received transfer to eeprom
51  if (bitcounter == 8) {
52  bitcounter = 0;
53  eeprom_busy_wait();
54  eeprom_write_byte((uint8_t *) eepromaddress1,receivebuffer); // needs a pointer, not a number as address -->
55  // explicite type conversion by (int *) x
56  eepromaddress1++;
57  }
58 
59 
60 }
61 
62 
63 
void setup()
Definition: start.cpp:27