cI2C/examples/ci2c_master_read/ci2c_master_read.ino

41 lines
882 B
Arduino
Raw Normal View History

2017-01-16 19:22:03 +01:00
/*
Master i2c read
Read some bytes in FRAM
This example code is in the public domain.
created Jan 12 2017
2017-02-02 00:03:07 +01:00
latest mod Jan 31 2017
2017-01-16 19:22:03 +01:00
by SMFSW
*/
#include <ci2c.h>
2017-01-22 18:32:00 +01:00
const uint8_t blank = 0xEE; // blank tab filling value for test
I2C_SLAVE FRAM; // slave declaration
2017-01-16 19:22:03 +01:00
void setup() {
Serial.begin(115200); // start serial for output
2017-02-02 00:03:07 +01:00
I2C_init(I2C_FM); // init with Fast Mode (400KHz)
2017-01-16 19:22:03 +01:00
I2C_slave_init(&FRAM, 0x50, I2C_16B_REG);
}
void loop() {
const uint16_t reg_addr = 0;
2017-01-22 18:32:00 +01:00
uint8_t str[8];
const uint8_t half_sz = sizeof(str) / 2;
memset(&str, blank, sizeof(str));
2017-01-16 19:22:03 +01:00
2017-01-22 18:32:00 +01:00
I2C_read(&FRAM, reg_addr, &str[0], half_sz); // FRAM, Addr 0, str, read chars for size of half str
I2C_read_next(&FRAM, &str[half_sz], half_sz);
2017-01-16 19:22:03 +01:00
Serial.println();
for (uint8_t i = 0; i < sizeof(str); i++)
{
2017-01-22 18:32:00 +01:00
Serial.print(str[i], HEX); // print hex values
2017-01-16 19:22:03 +01:00
Serial.print(" ");
}
delay(5000);
}