Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: eeprom_test eeprom_test MCP3204_test
24LC1025.cpp@0:8047024a08c2, 2019-11-20 (annotated)
- Committer:
 - sashida_h
 - Date:
 - Wed Nov 20 03:55:16 2019 +0000
 - Revision:
 - 0:8047024a08c2
 - Child:
 - 1:41cf2e3bb7f3
 
initial commit; ;
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| sashida_h | 0:8047024a08c2 | 1 | #include "24LC1025.h" | 
| sashida_h | 0:8047024a08c2 | 2 | // 24LC64 の書き込み、読み込みテスト | 
| sashida_h | 0:8047024a08c2 | 3 | |
| sashida_h | 0:8047024a08c2 | 4 | //I2C i2c(p9, p10); //p9: data, p10: clock | 
| sashida_h | 0:8047024a08c2 | 5 | |
| sashida_h | 0:8047024a08c2 | 6 | I2CEEprom::I2CEEprom():I2C(PB_7,PB_6) | 
| sashida_h | 0:8047024a08c2 | 7 | { | 
| sashida_h | 0:8047024a08c2 | 8 | addr = 0xA0; | 
| sashida_h | 0:8047024a08c2 | 9 | } | 
| sashida_h | 0:8047024a08c2 | 10 | I2CEEprom::I2CEEprom(PinName data, PinName clock, int address):I2C(data, clock) | 
| sashida_h | 0:8047024a08c2 | 11 | { | 
| sashida_h | 0:8047024a08c2 | 12 | addr = address; | 
| sashida_h | 0:8047024a08c2 | 13 | } | 
| sashida_h | 0:8047024a08c2 | 14 | |
| sashida_h | 0:8047024a08c2 | 15 | void I2CEEprom::write(unsigned int address, unsigned char data) | 
| sashida_h | 0:8047024a08c2 | 16 | { | 
| sashida_h | 0:8047024a08c2 | 17 | start(); | 
| sashida_h | 0:8047024a08c2 | 18 | ((I2C*)this)->write(addr); | 
| sashida_h | 0:8047024a08c2 | 19 | ((I2C*)this)->write((address>>8)); | 
| sashida_h | 0:8047024a08c2 | 20 | ((I2C*)this)->write(address); | 
| sashida_h | 0:8047024a08c2 | 21 | ((I2C*)this)->write(data); | 
| sashida_h | 0:8047024a08c2 | 22 | stop(); | 
| sashida_h | 0:8047024a08c2 | 23 | } | 
| sashida_h | 0:8047024a08c2 | 24 | |
| sashida_h | 0:8047024a08c2 | 25 | unsigned char I2CEEprom::read(unsigned int address) | 
| sashida_h | 0:8047024a08c2 | 26 | { | 
| sashida_h | 0:8047024a08c2 | 27 | unsigned char x; | 
| sashida_h | 0:8047024a08c2 | 28 | start(); | 
| sashida_h | 0:8047024a08c2 | 29 | ((I2C*)this)->write(addr); | 
| sashida_h | 0:8047024a08c2 | 30 | ((I2C*)this)->write((address>>8)); | 
| sashida_h | 0:8047024a08c2 | 31 | ((I2C*)this)->write(address); | 
| sashida_h | 0:8047024a08c2 | 32 | start(); | 
| sashida_h | 0:8047024a08c2 | 33 | ((I2C*)this)->write(addr+1); | 
| sashida_h | 0:8047024a08c2 | 34 | x = ((I2C*)this)->read(0); | 
| sashida_h | 0:8047024a08c2 | 35 | stop(); | 
| sashida_h | 0:8047024a08c2 | 36 | return x; | 
| sashida_h | 0:8047024a08c2 | 37 | } |