PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
Learn
Examples
Protocols
Test 24LC512 with I2C.c
1
/*
2
Test 24LC512 with I2C.c
3
4
Test writes data to I2C EEPROM, then reads it back and displays it.
5
6
http://learn.parallax.com/propeller-c-simple-protocols/diy-i2c
7
*/
8
9
#include "simpletools.h"
// Include simpletools header
10
11
i2c
*eeBus;
// I2C bus ID
12
13
int
main
()
// Main function
14
{
15
eeBus = i2c_newbus(28, 29, 0);
// Set up I2C bus, get bus ID
16
17
// Use eeBus to write to device
18
i2c_out(eeBus, 0b1010000,
// with I2C address 0b1010000,
19
32768, 2,
"abcdefg"
, 8);
// send address 32768 (2 bytes)
20
// and "abc..." data (8 bytes)
21
22
while
(i2c_busy(eeBus, 0b1010000));
// Wait for EEPROM to finish
23
24
char
testStr[] = {0, 0, 0, 0, 0, 0, 0, 0};
// Set up test string
25
26
// Use eeBus to read from device
27
i2c_in(eeBus, 0b1010000,
// with I2C address 0b1010000,
28
32768, 2, testStr, 8);
// send address 32768 (2 bytes)
29
// data in to testStr (8 bytes)
30
31
print(
"testStr = %s \n"
, testStr);
// Display result
32
}
i2c_st
Definition:
simplei2c.h:25
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12